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
+3
View File
@@ -38,6 +38,9 @@ function Edit-ZertoVra {
$baseUri = "vras/{0}" -f $vraIdentifier $baseUri = "vras/{0}" -f $vraIdentifier
# Get the current VRA information for use if an updated parameter is not supplied # Get the current VRA information for use if an updated parameter is not supplied
$vra = Get-ZertoVra -vraIdentifier $vraIdentifier $vra = Get-ZertoVra -vraIdentifier $vraIdentifier
if ( -not $vra ) {
Write-Error "VRA with Identifier: $vraIdentifier could not be found. Please check the ID and try again."
}
} }
process { process {
@@ -2,6 +2,7 @@
function Invoke-ZertoFailover { function Invoke-ZertoFailover {
[cmdletbinding( SupportsShouldProcess = $true )] [cmdletbinding( SupportsShouldProcess = $true )]
param( param(
#TODO - Refactor?
[Parameter( [Parameter(
Mandatory = $true, Mandatory = $true,
HelpMessage = "Name of the VPG to Failover" HelpMessage = "Name of the VPG to Failover"
@@ -25,8 +25,12 @@ function Invoke-ZertoFailoverCommit {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/FailoverCommit" -f $baseUri, $vpgId if ( -not $vpgId ) {
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" Write-Error "VPG: $name could not be found. Please check the name and try again. Skipping."
} else {
$uri = "{0}/{1}/FailoverCommit" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST"
}
} }
} }
@@ -16,8 +16,12 @@ function Invoke-ZertoFailoverRollback {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/FailoverRollback" -f $baseUri, $vpgId if ( -not $vpgId ) {
Invoke-ZertoRestRequest -uri $uri -method "POST" Write-Error "VPG: $name not found. Please check the name and try again. Skipping"
} else {
$uri = "{0}/{1}/FailoverRollback" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -method "POST"
}
} }
} }
@@ -16,8 +16,12 @@ function Invoke-ZertoForceSync {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier $id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/forcesync" -f $baseUri, $id if ( -not $id ) {
Invoke-ZertoRestRequest -uri $uri -method "POST" Write-Error "VPG: $name not found. Please check the name and try again. Skipping"
} else {
$uri = "{0}/{1}/forcesync" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
}
} }
} }
+7 -2
View File
@@ -49,6 +49,7 @@ function Invoke-ZertoMove {
begin { begin {
$baseUri = "vpgs" $baseUri = "vpgs"
$body = [ordered]@{} $body = [ordered]@{}
#TODO - use a foreach loop to populate the body without all the if statments
if ($PSBoundParameters.ContainsKey('commitPolicy')) { if ($PSBoundParameters.ContainsKey('commitPolicy')) {
$body['commitPolicy'] = $commitPolicy $body['commitPolicy'] = $commitPolicy
} }
@@ -72,8 +73,12 @@ function Invoke-ZertoMove {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/move" -f $baseUri, $vpgId if ( -not $vpgId ) {
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) Write-Error "VPG: $name not found. Please check the name and try again. Skipping"
} else {
$uri = "{0}/{1}/move" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
}
} }
} }
@@ -29,8 +29,12 @@ function Invoke-ZertoMoveCommit {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/MoveCommit" -f $baseUri, $vpgId if ( -not $vpgId ) {
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST" Write-Error "VPG: $name not found. Please check the name and try again. Skipping."
} else {
$uri = "{0}/{1}/MoveCommit" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST"
}
} }
} }
@@ -16,8 +16,12 @@ function Invoke-ZertoMoveRollback {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier $id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/moveRollBack" -f $baseUri, $id if ( -not $id ) {
Invoke-ZertoRestRequest -uri $uri -method "POST" Write-Error "VPG: $name not found. Please check the name and try again."
} else {
$uri = "{0}/{1}/moveRollBack" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
}
} }
} }
+1 -2
View File
@@ -241,8 +241,7 @@ function New-ZertoVpg {
} }
if ( -not $validSettings ) { if ( -not $validSettings ) {
Write-Error "One or more parameters passed do not have valid identifiers or 0 valid VMs were found. Please check your settings and try again." Write-Error "One or more parameters passed do not have valid identifiers or 0 valid VMs were found. Please check your settings and try again." -ErrorAction Stop
Break
} }
} }
@@ -36,10 +36,9 @@ function New-ZertoVpgSettingsIdentifier {
if ($PSCmdlet.ShouldProcess("Creating VPG Settings Object")) { if ($PSCmdlet.ShouldProcess("Creating VPG Settings Object")) {
Invoke-ZertoRestRequest -uri $baseUri -body $body -Method "POST" Invoke-ZertoRestRequest -uri $baseUri -body $body -Method "POST"
} }
} }
end { end {
#Nothing to do
} }
} }
+1 -1
View File
@@ -55,7 +55,7 @@ function Remove-ZertoVpg {
Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -Method "DELETE" Invoke-ZertoRestRequest -uri $uri -body $($body | ConvertTo-Json) -Method "DELETE"
} }
} else { } else {
Write-Output "VPG with name $vpgName not found. Please check the name and try again" Write-Error "VPG with name $vpgName not found. Please check the name and try again"
} }
} }
} }
+6 -2
View File
@@ -16,8 +16,12 @@ function Resume-ZertoVpg {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier $id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/resume" -f $baseUri, $id if ( -not $id ) {
Invoke-ZertoRestRequest -uri $uri -method "POST" Write-Error "VPG: $name not found. Please check the name and try again. Skipping."
} else {
$uri = "{0}/{1}/resume" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
}
} }
} }
+21 -4
View File
@@ -24,18 +24,35 @@ function Start-ZertoCloneVpg {
begin { begin {
$baseUri = "vpgs" $baseUri = "vpgs"
$vpgInfo = Get-ZertoVpg -name $vpgName $vpgInfo = Get-ZertoVpg -name $vpgName
if ( -not $vpgInfo ) {
Write-Error "VPG: $vpgName could not be found. Please check the name and try again."
}
$vpgIdentifier = $vpgInfo.vpgIdentifier $vpgIdentifier = $vpgInfo.vpgIdentifier
if ( $PSBoundParameters.ContainsKey('datastoreName') ) { if ( $PSBoundParameters.ContainsKey('datastoreName') ) {
$recoverysiteIdentifier = $vpgInfo.recoverysite.identifier $recoverysiteIdentifier = $vpgInfo.recoverysite.identifier
$recoverySiteDatastores = Get-ZertoVirtualizationSite -siteIdentifier $recoverysiteIdentifier -datastores $recoverySiteDatastores = Get-ZertoVirtualizationSite -siteIdentifier $recoverysiteIdentifier -datastores
$datastoreIdentifier = $($recoverySiteDatastores | Where-Object {$_.datastoreName -like $datastoreName}).DatastoreIdentifier $datastoreIdentifier = $($recoverySiteDatastores | Where-Object {$_.datastoreName -like $datastoreName}).DatastoreIdentifier
if ( -not $datastoreIdentifier ) {
Write-Error "Datastore: $datastoreName is not a valid datastore. Please check the name and try again." -ErrorAction Stop
}
} }
if ( $PSBoundParameters.ContainsKey('vmName') ) { if ( $PSBoundParameters.ContainsKey('vmName') ) {
$vmIdentifiers = @() $vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName
$vmIdentifiers = foreach ( $name in $vmName ) { [System.Collections.ArrayList]$vmIdentifiers = @()
$(Get-ZertoProtectedVm -vmName $name).vmIdentifier 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
} }
} }
} }
@@ -21,32 +21,34 @@ function Start-ZertoFailoverTest {
begin { begin {
$baseUri = "vpgs" $baseUri = "vpgs"
$vpgIdentifier = $(Get-ZertoVpg -name $vpgName).vpgIdentifier $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') ) { if ( $PSBoundParameters.ContainsKey('vmName') ) {
$vmIdentifiers = @() $vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName
$vmIdentifiers = foreach ( $name in $vmName ) { [System.Collections.ArrayList]$vmIdentifiers = @()
$(Get-ZertoProtectedVm -vmName $name).vmIdentifier 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 { process {
$uri = "{0}/{1}/FailoverTest" -f $baseUri, $vpgIdentifier $uri = "{0}/{1}/FailoverTest" -f $baseUri, $vpgIdentifier
$body = [ordered]@{} if ($PSCmdlet.ShouldProcess($vpgName)) {
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")) {
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
} }
} }
end { end {
@@ -12,6 +12,9 @@ function Stop-ZertoCloneVpg {
begin { begin {
$baseUri = "vpgs" $baseUri = "vpgs"
$vpgIdentifier = $(Get-ZertoVpg -name $vpgName).vpgIdentifier $vpgIdentifier = $(Get-ZertoVpg -name $vpgName).vpgIdentifier
if ( -not $vpgIdentifier ) {
Write-Error "VPG: $vpgName could not be found. Please check the name and try again." -ErrorAction Stop
}
} }
process { process {
@@ -6,6 +6,7 @@ function Stop-ZertoFailoverTest {
HelpMessage = "Name(s) of VPG(s) to stop testing.", HelpMessage = "Name(s) of VPG(s) to stop testing.",
Mandatory = $true Mandatory = $true
)] )]
[ValidateNotNullOrEmpty()]
[string[]]$vpgName, [string[]]$vpgName,
[Parameter( [Parameter(
HelpMessage = "Was the test successful? True or False. True is Default." HelpMessage = "Was the test successful? True or False. True is Default."
@@ -25,11 +26,13 @@ function Stop-ZertoFailoverTest {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier $vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
if ( -not $vpgId) {
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop
}
$uri = "{0}/{1}/FailoverTestStop" -f $baseUri, $vpgId $uri = "{0}/{1}/FailoverTestStop" -f $baseUri, $vpgId
if ($PSCmdlet.ShouldProcess("Stopping Failover Test")) { if ($PSCmdlet.ShouldProcess("Stopping Failover Test")) {
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json) Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
} }
} }
} }
+6 -2
View File
@@ -16,8 +16,12 @@ function Suspend-ZertoVpg {
process { process {
foreach ($name in $vpgName) { foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier $id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/pause" -f $baseUri, $id if ( -not $id ) {
Invoke-ZertoRestRequest -uri $uri -method "POST" Write-Error "VPG: $name not found. Skipping."
} else {
$uri = "{0}/{1}/pause" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
}
} }
} }
@@ -17,8 +17,12 @@ function Uninstall-ZertoVra {
foreach ($name in $hostName) { foreach ($name in $hostName) {
$vraName = "Z-VRA-{0}" -f $name $vraName = "Z-VRA-{0}" -f $name
$vraIdentifier = get-zertovra -vraName $vraName | Select-Object vraIdentifier -ExpandProperty vraIdentifier $vraIdentifier = get-zertovra -vraName $vraName | Select-Object vraIdentifier -ExpandProperty vraIdentifier
$uri = "{0}/{1}" -f $baseUri, $vraIdentifier.toString() if ( -not $vraIdentifier ) {
Invoke-ZertoRestRequest -uri $uri -method "DELETE" Write-Error "Host: $hostName either does not have a VRA or was not found. Please check the name and try again. Skipping."
} else {
$uri = "{0}/{1}" -f $baseUri, $vraIdentifier.toString()
Invoke-ZertoRestRequest -uri $uri -method "DELETE"
}
if ($hostName.Count -gt 1) { if ($hostName.Count -gt 1) {
Start-Sleep 1 Start-Sleep 1
} }