Validate identifiers are present

This commit is contained in:
Wes Carroll
2019-04-05 22:49:36 -04:00
parent e279ba0cda
commit 5bf7d0d6df
18 changed files with 109 additions and 45 deletions
@@ -21,32 +21,34 @@ function Start-ZertoFailoverTest {
begin {
$baseUri = "vpgs"
$vpgIdentifier = $(Get-ZertoVpg -name $vpgName).vpgIdentifier
if ( -not $vpgIdentifier) {
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop
}
if ( $PSBoundParameters.ContainsKey('vmName') ) {
$vmIdentifiers = @()
$vmIdentifiers = foreach ( $name in $vmName ) {
$(Get-ZertoProtectedVm -vmName $name).vmIdentifier
$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
if ($checkpointIdentifier) {
$body['CheckpointIdentifier'] = $checkpointIdentifier
}
}
}
process {
$uri = "{0}/{1}/FailoverTest" -f $baseUri, $vpgIdentifier
$body = [ordered]@{}
if ($checkpointIdentifier) {
$body['CheckpointIdentifier'] = $checkpointIdentifier
}
if ( $PSBoundParameters.ContainsKey('vmName') ) {
$vmIdentifiers = @()
$vmIdentifiers = foreach ( $name in $vmName ) {
$(Get-ZertoProtectedVm -vmName $name).vmIdentifier
}
$body['VmIdentifiers'] = $vmIdentifiers
}
if ($PSCmdlet.ShouldProcess("Starting Failover Test")) {
if ($PSCmdlet.ShouldProcess($vpgName)) {
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
}
}
end {