Update Invoke-ZertoMove.ps1

WhatIf Processing
Reverse Protection Logic
Ensure Params are set and do not rely on defaults
This commit is contained in:
Wes Carroll
2019-04-06 22:51:03 -04:00
parent b3d649e495
commit 31db21c325
+37 -27
View File
@@ -1,11 +1,12 @@
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
function Invoke-ZertoMove { function Invoke-ZertoMove {
[CmdletBinding()] [CmdletBinding( DefaultParameterSetName = "main", SupportsShouldProcess = $true )]
param( param(
[Parameter( [Parameter(
HelpMessage = "Name(s) of the VPG(s) you want to move.", HelpMessage = "Name(s) of the VPG(s) you want to move.",
Mandatory = $true Mandatory = $true
)] )]
[ValidateNotNullOrEmpty()]
[string[]]$vpgName, [string[]]$vpgName,
[Parameter( [Parameter(
HelpMessage = "'Rollback': After the seconds specified in the commitValue setting have elapsed, the failover is rolled back. HelpMessage = "'Rollback': After the seconds specified in the commitValue setting have elapsed, the failover is rolled back.
@@ -20,30 +21,23 @@ function Invoke-ZertoMove {
)] )]
[Int32]$commitPolicyTimeout, [Int32]$commitPolicyTimeout,
[Parameter( [Parameter(
HelpMessage = "False: If a utility (VMware Tools) is installed on the protected virtual machines, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. HelpMessage = "If this switch is specified, Zerto will attempt to gracefully shut down the Virtual Machines. If the machines do not poweroff within 5 minutes, they will be forcibly powering them off."
True: To force a shutdown of the virtual machines.
Default: True"
)] )]
[bool]$forceShutdown, [switch]$forceShutdown,
[Parameter( [Parameter(
HelpMessage = "False: Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set. ParameterSetName = "disableReverseProtection",
True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. HelpMessage = "Do not enable reverse protection. The VPG definition is kept with the status Needs Configuration and the reverse settings in the VPG definition are not set."
Default Value: True
Note: If ReverseProtection is set to True, the KeepSourceVMs should be ignored because the virtual disks of the VMs are used for replication and cannot have VMs attached."
)] )]
[bool]$reverseProtection = $false, [switch]$disableReverseProtection,
[Parameter( [Parameter(
HelpMessage = "False: Remove the protected virtual machines from the protected site. ParameterSetName = "keepSourceVms",
True: Prevent the protected virtual machines from being deleted in the protected site. HelpMessage = "Prevent the protected virtual machines from being deleted in the protected site. Using this setting disables reverse protection."
Default: False"
)] )]
[bool]$keepSourceVms = $false, [switch]$keepSourceVms,
[Parameter( [Parameter(
HelpMessage = "False: Do not continue the Move operation in case of failure of script executing prior the operation. HelpMessage = "Continue the Move operation in case of failure of script executing prior the operation. If this switch is not set a failure of the script executing prior to the operation will cause the operation to fail."
True: Continue the Move operation in case of failure of script executing prior the operation.
Default: False"
)] )]
[bool]$continueOnPreScriptFailure [switch]$ContinueOnPreScriptFailure
) )
begin { begin {
@@ -57,16 +51,30 @@ function Invoke-ZertoMove {
$body['commitPolicyTimeout'] = $commitPolicyTimeout $body['commitPolicyTimeout'] = $commitPolicyTimeout
} }
if ($PSBoundParameters.ContainsKey('forceShutdown')) { if ($PSBoundParameters.ContainsKey('forceShutdown')) {
$body['forceShutdown'] = $forceShutdown $body['forceShutdown'] = $true
} else {
$body['forceShutdown'] = $false
} }
if ($PSBoundParameters.ContainsKey('reverseProtection')) { if ($PSBoundParameters.ContainsKey('ContinueOnPreScriptFailure')) {
$body['reverseProtection'] = $reverseProtection $body['ContinueOnPreScriptFailure'] = $true
} else {
$body['ContinueOnPreScriptFailure'] = $false
} }
if ($PSBoundParameters.ContainsKey('keepSourceVms')) { switch ($PSCmdlet.ParameterSetName) {
$body['keepSourceVms'] = $keepSourceVms "disableReverseProtection" {
} $body['reverseProtection'] = $false
if ($PSBoundParameters.ContainsKey('continueOnPreScriptFail')) { $body['keepSourceVms'] = $false
$body['continueOnPreScriptFail'] = $continueOnPreScriptFailure }
"keepSourceVms" {
$body['reverseProtection'] = $false
$body['keepSourceVms'] = $true
}
"main" {
$body['reverseProtection'] = $true
$body['keepSourceVms'] = $false
}
} }
} }
@@ -77,7 +85,9 @@ function Invoke-ZertoMove {
Write-Error "VPG: $name not found. Please check the name and try again. Skipping" Write-Error "VPG: $name not found. Please check the name and try again. Skipping"
} else { } else {
$uri = "{0}/{1}/move" -f $baseUri, $vpgId $uri = "{0}/{1}/move" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) if ($PSCmdlet.ShouldProcess("Moving VPG: $name wiht settings: $($body | convertto-json)")) {
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
}
} }
} }
} }