Various fixes

Removed Commit Value as it is not a vaild param
Enabled ShouldProcess
Ensured mandatory default values make it into the body
Added Validate a valid VPG is selected.
This commit is contained in:
Wes Carroll
2019-04-05 17:18:56 -04:00
parent 2a8837aff7
commit 5533bae319
+21 -12
View File
@@ -1,16 +1,18 @@
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #> <# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
function Invoke-ZertoFailover { function Invoke-ZertoFailover {
[cmdletbinding()] [cmdletbinding( SupportsShouldProcess = $true )]
param( param(
[Parameter( [Parameter(
Mandatory = $true, Mandatory = $true,
HelpMessage = "Name of the VPG to Failover" HelpMessage = "Name of the VPG to Failover"
)] )]
[ValidateNotNullOrEmpty()]
[string]$vpgName, [string]$vpgName,
[Parameter( [Parameter(
HelpMessage = "Checkpoint Identifier to use as the Point-In-Time to rollback to." HelpMessage = "Checkpoint Identifier to use as the Point-In-Time to rollback to."
)] )]
[Alias("checkpointId")] [Alias("checkpointId")]
[ValidateNotNullOrEmpty()]
[string]$checkpointIdentifier, [string]$checkpointIdentifier,
[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.
@@ -19,11 +21,7 @@ function Invoke-ZertoFailover {
Default is the Site Settings setting." Default is the Site Settings setting."
)] )]
[ValidateSet("Rollback", "Commit", "None")] [ValidateSet("Rollback", "Commit", "None")]
[string]$commitPolicy, [string]$commitPolicy = "Rollback",
[Parameter(
HelpMessage = "The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is the Site Setting"
)]
[string]$commitValue,
[Parameter( [Parameter(
HelpMessage = "0: The protected virtual machines are not touched before starting the failover. This assumes that you do not have access to the protected virtual machines. -- DEFAULT HelpMessage = "0: The protected virtual machines are not touched before starting the failover. This assumes that you do not have access to the protected virtual machines. -- DEFAULT
1: If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the virtual machines are gracefully shut down, otherwise the failover operation fails. This is similar to performing a Move operation to a specified checkpoint. 1: If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the virtual machines are gracefully shut down, otherwise the failover operation fails. This is similar to performing a Move operation to a specified checkpoint.
@@ -32,9 +30,9 @@ function Invoke-ZertoFailover {
[ValidateSet(0, 1, 2)] [ValidateSet(0, 1, 2)]
[int]$shutdownPolicy = 0, [int]$shutdownPolicy = 0,
[Parameter( [Parameter(
HelpMessage = "Time, in seconds, before VMs are forcibly turned off if the Force Shutdown option is seclected after attempting to gracefully shut down the VMs" HelpMessage = "The amount of time in seconds the failover waits in a Before Commit state to enable checking that the failover is as required before performing the commitPolicy setting. Default is 60 Minutes (3600 Seconds)"
)] )]
[long]$timeToWaitBeforeShutdownInSec = 300, [int]$timeToWaitBeforeShutdownInSec = 3600,
[Parameter( [Parameter(
HelpMessage = "True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings. HelpMessage = "True: Enable reverse protection. The virtual machines are recovered on the recovery site and then protected using the default reverse protection settings.
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." 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."
@@ -43,15 +41,23 @@ function Invoke-ZertoFailover {
[Parameter( [Parameter(
HelpMessage = "Name(s) of VMs in the VPG to failover" HelpMessage = "Name(s) of VMs in the VPG to failover"
)] )]
[ValidateNotNullOrEmpty()]
[string[]]$vmName [string[]]$vmName
) )
begin { begin {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier $vpgId = $(Get-ZertoVpg -name $vpgName).vpgIdentifier
$baseUri = "vpgSettings/{0}/failover" -f $vpgId if ( -not $vpgId) {
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!"
break
}
$baseUri = "vpgs/{0}/failover" -f $vpgId
$body = [ordered]@{} $body = [ordered]@{}
# Setup Defaults
$body['commitpolicy'] = $commitPolicy
$body['TimeToWaitBeforeShutdownInSec'] = $timeToWaitBeforeShutdownInSec
foreach ($key in $PSBoundParameters.Keys) { foreach ($key in $PSBoundParameters.Keys) {
if ($key -notlike 'vpgGroup' -or $key -notlike 'vmName') { if ($key -notlike 'vpgName' -and $key -notlike 'vmName' -and $key -notlike 'WhatIf' -and $key -notlike 'TimeToWaitBeforeShutdownInSec' -and $key -notlike 'commitpolicy') {
$body[$key] = $PSBoundParameters['key'] $body[$key] = $PSBoundParameters['key']
} }
} }
@@ -65,7 +71,10 @@ function Invoke-ZertoFailover {
} }
process { process {
Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST" if ($PSCmdlet.ShouldProcess("$vpgName with identifier $vpgId and these options $($body | convertto-json)")) {
Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST"
}
} }
end { end {