Update Body Build Logic

This commit is contained in:
Wes Carroll
2019-04-15 17:20:17 -04:00
parent 5a579d6fe8
commit 2e4cd68b5e
+31 -21
View File
@@ -24,9 +24,9 @@ function Invoke-ZertoFailover {
[ValidateSet("Rollback", "Commit", "None")]
[string]$commitPolicy = "Rollback",
[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
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.
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."
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. 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. This assumes that you do not have access to the protected virtual machines"
)]
[ValidateSet(0, 1, 2)]
[int]$shutdownPolicy = 0,
@@ -52,29 +52,39 @@ function Invoke-ZertoFailover {
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop
}
$baseUri = "vpgs/{0}/failover" -f $vpgId
$body = [ordered]@{}
# Setup Defaults
$body = @{}
# Setup Required Defaults
$body['commitpolicy'] = $commitPolicy
$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') {
$body[$param.key] = $param.value
Switch ($PSBoundParameters.Keys) {
"checkpointIdentifier" {
$body['checkpointIdentifier'] = $checkpointIdentifier
}
}
if ($PSBoundParameters.ContainsKey('vmName')) {
$vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName
[System.Collections.ArrayList]$vmIdentifiers = @()
foreach ( $name in $vmName ) {
$selectedVm = $vpgVmInformation | Where-Object {$_.VmName.toLower() -eq $name.toLower()}
if ($null -eq $selectedVm) {
Write-Error "VM: $name NOT found in VPG $vpgName. Check the name and try again." -ErrorAction Stop
} elseif ($vmIdentifiers.Contains($selectedVm.vmIdentifier.toString())) {
Write-Error "VM: $($selectedVm.VmName) specified more than once. Please check parameters and try again." -ErrorAction Stop
} else {
$vmIdentifiers.Add($selectedVm.vmIdentifier.toString()) | Out-Null
"shutdownPolicy" {
$body['shutdownPolicy'] = $shutdownPolicy
}
"reverseProtection" {
$body['reverseProtection'] = $reverseProtection
}
"vmName" {
$vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName
[System.Collections.ArrayList]$vmIdentifiers = @()
foreach ( $name in $vmName ) {
$selectedVm = $vpgVmInformation | Where-Object {$_.VmName.toLower() -eq $name.toLower()}
if ($null -eq $selectedVm) {
Write-Error "VM: $name NOT found in VPG $vpgName. Check the name and try again." -ErrorAction Stop
} elseif ($vmIdentifiers.Contains($selectedVm.vmIdentifier.toString())) {
Write-Error "VM: $($selectedVm.VmName) specified more than once. Please check parameters and try again." -ErrorAction Stop
} else {
$vmIdentifiers.Add($selectedVm.vmIdentifier.toString()) | Out-Null
}
}
$body['VmIdentifiers'] = $vmIdentifiers
}
$body['VmIdentifiers'] = $vmIdentifiers
}
}