From 20d947a931b0a19e9c3155e0335ada0e3a77b183 Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Mon, 25 Feb 2019 22:37:47 -0500 Subject: [PATCH] Added Checkpoint Creation and VPG Removal Functions --- .../Public/Checkpoint-ZertoVpg.ps1 | 34 ++++++++++++++++ ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 | 40 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 create mode 100644 ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 diff --git a/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 new file mode 100644 index 0000000..da7e52e --- /dev/null +++ b/ZertoApiWrapper/Public/Checkpoint-ZertoVpg.ps1 @@ -0,0 +1,34 @@ +function Checkpoint-ZertoVpg { + [cmdletbinding()] + param( + [Parameter( + Mandatory = $true, + HelpMessage = "Name of the VPG to tag." + )] + [string]$vpgName, + [Parameter( + Mandatory = $true, + HelpMessage = "Text to tag the checkpoint with." + )] + [string]$checkpointName + ) + + begin { + $baseUri = "vpgs" + $vpgIdentifier = $(get-zertovpg -name $vpgName).vpgIdentifier + $body = @{"checkpointName" = $checkpointName} + } + + process { + if ($vpgIdentifier) { + $uri = "{0}/{1}/Checkpoints" -f $baseUri, $vpgIdentifier + Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -method "POST" + } else { + Write-Output "Cannot find VPG named $vpgName. Please check the name and try again." + } + } + + end { + + } +} diff --git a/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 b/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 new file mode 100644 index 0000000..3184f4a --- /dev/null +++ b/ZertoApiWrapper/Public/Remove-ZertoVpg.ps1 @@ -0,0 +1,40 @@ +function Remove-ZertoVpg { + [cmdletbinding( SupportsShouldProcess = $true )] + param( + [Parameter( + Mandatory = $true, + HelpMessage = "Name of the VPG to delete." + )] + [string]$vpgName, + [Parameter( + HelpMessage = "Use this switch to keep the recovery volumes at the target site. If the virtual machines in the deleted VPG are reprotected, these volumes can be used as preseeded volumes to speed up the initial synchronization of the new VPG." + )] + [switch]$keepRecoveryVolumes, + [Parameter( + HelpMessage = "Use this switch to force delete the VPG." + )] + [switch]$force + ) + + begin { + $baseUri = "vpgs" + $vpgIdentifier = $(get-zertovpg -name $vpgName).vpgIdentifier + } + + process { + $vpgIdentifier = $(get-zertovpg -name $vpgName).vpgIdentifier + if ( $vpgIdentifier ) { + $uri = "{0}/{1}" -f $baseUri, $vpgIdentifier + $body = @{"Force" = $force; "KeepRecoveryVolumes" = $keepRecoveryVolumes} + if ($PSCmdlet.ShouldProcess( $vpgName + " and these settings: " + $($body | ConvertTo-Json) ) ) { + Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -Method "DELETE" + } + } else { + Write-Output "VPG with name $vpgName not found. Please check the name and try again" + } + } + + end { + # Nothing to do + } +}