public/Remove-VolumeSnapshot.ps1
|
function Remove-ZStackVolumeSnapshot { # .SYNOPSIS # Deletes a leaf volume snapshot. # .DESCRIPTION # ZStack PowerCLI (ZStack.PowerCLI 1.1.5) uses CLI 1.1.5, commit 6fcf509ff540d0098f54c1c33609dbe9f572c837. # Connection configuration namespace: zstack-powershell. # .LINK # https://github.com/terraform-zstack-modules/zstack-cli-go/blob/main/docs/powershell.md [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] param( [Parameter(Mandatory, Position = 0, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [object[]] $Snapshot, [object] $Volume, [ValidateRange(1, 3600)] [int] $TimeoutSeconds = 300, [object] $Server ) process { foreach ($item in $Snapshot) { try { $target = Get-CloudResourceSelection $item VolumeSnapshot $Server RemoveVolumeSnapshot $volumeId = Get-CloudDeviceParentId $target VolumeId $Volume @('Volume', 'HardDisk') RemoveVolumeSnapshot $arguments = @('delete', 'snapshot', $target.Id, '--volume', $volumeId) Invoke-CloudDeviceWrite $PSCmdlet $target $arguments delete-snapshot RemoveVolumeSnapshot "Delete leaf volume snapshot for $volumeId" $TimeoutSeconds } catch { $PSCmdlet.WriteError($_) } } } } |