Update Body Build Logic

This commit is contained in:
Wes Carroll
2019-04-15 17:20:17 -04:00
parent 5a579d6fe8
commit 2e4cd68b5e
@@ -24,9 +24,9 @@ function Invoke-ZertoFailover {
[ValidateSet("Rollback", "Commit", "None")] [ValidateSet("Rollback", "Commit", "None")]
[string]$commitPolicy = "Rollback", [string]$commitPolicy = "Rollback",
[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. -- 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. This assumes that you do not have access to the protected virtual machines.
2: The protected virtual machines are forcibly shut down before starting the failover. If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. This is similar to performing a Move operation to a specified checkpoint." 2: The protected virtual machines are forcibly shut down before starting the failover. If the protected virtual machines have VMware Tools or Microsoft Integration Services available, the procedure waits five minutes for the virtual machines to be gracefully shut down before forcibly powering them off. This is similar to performing a Move operation to a specified checkpoint. This assumes that you do not have access to the protected virtual machines"
)] )]
[ValidateSet(0, 1, 2)] [ValidateSet(0, 1, 2)]
[int]$shutdownPolicy = 0, [int]$shutdownPolicy = 0,
@@ -52,16 +52,25 @@ function Invoke-ZertoFailover {
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop
} }
$baseUri = "vpgs/{0}/failover" -f $vpgId $baseUri = "vpgs/{0}/failover" -f $vpgId
$body = [ordered]@{} $body = @{}
# Setup Defaults # Setup Required Defaults
$body['commitpolicy'] = $commitPolicy $body['commitpolicy'] = $commitPolicy
$body['TimeToWaitBeforeShutdownInSec'] = $timeToWaitBeforeShutdownInSec $body['TimeToWaitBeforeShutdownInSec'] = $timeToWaitBeforeShutdownInSec
foreach ($param in $PSBoundParameters.GetEnumerator()) {
if ($param.key -notlike 'vpgName' -and $param.key -notlike 'vmName' -and $param.key -notlike 'WhatIf' -and $param.key -notlike 'TimeToWaitBeforeShutdownInSec' -and $param.key -notlike 'commitpolicy') { Switch ($PSBoundParameters.Keys) {
$body[$param.key] = $param.value "checkpointIdentifier" {
$body['checkpointIdentifier'] = $checkpointIdentifier
} }
"shutdownPolicy" {
$body['shutdownPolicy'] = $shutdownPolicy
} }
if ($PSBoundParameters.ContainsKey('vmName')) {
"reverseProtection" {
$body['reverseProtection'] = $reverseProtection
}
"vmName" {
$vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName $vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName
[System.Collections.ArrayList]$vmIdentifiers = @() [System.Collections.ArrayList]$vmIdentifiers = @()
foreach ( $name in $vmName ) { foreach ( $name in $vmName ) {
@@ -77,6 +86,7 @@ function Invoke-ZertoFailover {
$body['VmIdentifiers'] = $vmIdentifiers $body['VmIdentifiers'] = $vmIdentifiers
} }
} }
}
process { process {
if ($PSCmdlet.ShouldProcess("$vpgName with identifier $vpgId and these options $($body | convertto-json)")) { if ($PSCmdlet.ShouldProcess("$vpgName with identifier $vpgId and these options $($body | convertto-json)")) {