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
# Get the current VRA information for use if an updated parameter is not supplied
$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 {
@@ -2,6 +2,7 @@
function Invoke-ZertoFailover {
[cmdletbinding( SupportsShouldProcess = $true )]
param(
#TODO - Refactor?
[Parameter(
Mandatory = $true,
HelpMessage = "Name of the VPG to Failover"
@@ -25,8 +25,12 @@ function Invoke-ZertoFailoverCommit {
process {
foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/FailoverCommit" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST"
if ( -not $vpgId ) {
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 {
foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/FailoverRollback" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -method "POST"
if ( -not $vpgId ) {
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 {
foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/forcesync" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
if ( -not $id ) {
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 {
$baseUri = "vpgs"
$body = [ordered]@{}
#TODO - use a foreach loop to populate the body without all the if statments
if ($PSBoundParameters.ContainsKey('commitPolicy')) {
$body['commitPolicy'] = $commitPolicy
}
@@ -72,8 +73,12 @@ function Invoke-ZertoMove {
process {
foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/move" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
if ( -not $vpgId ) {
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 {
foreach ($name in $vpgName) {
$vpgId = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/MoveCommit" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri -body $($body | convertto-json) -method "POST"
if ( -not $vpgId ) {
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 {
foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/moveRollBack" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
if ( -not $id ) {
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 ) {
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."
Break
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
}
}
@@ -36,10 +36,9 @@ function New-ZertoVpgSettingsIdentifier {
if ($PSCmdlet.ShouldProcess("Creating VPG Settings Object")) {
Invoke-ZertoRestRequest -uri $baseUri -body $body -Method "POST"
}
}
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"
}
} 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 {
foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/resume" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
if ( -not $id ) {
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 {
$baseUri = "vpgs"
$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
if ( $PSBoundParameters.ContainsKey('datastoreName') ) {
$recoverysiteIdentifier = $vpgInfo.recoverysite.identifier
$recoverySiteDatastores = Get-ZertoVirtualizationSite -siteIdentifier $recoverysiteIdentifier -datastores
$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') ) {
$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
}
}
}
@@ -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 {
@@ -12,6 +12,9 @@ function Stop-ZertoCloneVpg {
begin {
$baseUri = "vpgs"
$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 {
@@ -6,6 +6,7 @@ function Stop-ZertoFailoverTest {
HelpMessage = "Name(s) of VPG(s) to stop testing.",
Mandatory = $true
)]
[ValidateNotNullOrEmpty()]
[string[]]$vpgName,
[Parameter(
HelpMessage = "Was the test successful? True or False. True is Default."
@@ -25,11 +26,13 @@ function Stop-ZertoFailoverTest {
process {
foreach ($name in $vpgName) {
$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
if ($PSCmdlet.ShouldProcess("Stopping Failover Test")) {
Invoke-ZertoRestRequest -uri $uri -method "POST" -body $($body | ConvertTo-Json)
}
}
}
+6 -2
View File
@@ -16,8 +16,12 @@ function Suspend-ZertoVpg {
process {
foreach ($name in $vpgName) {
$id = $(Get-ZertoVpg -name $name).vpgIdentifier
$uri = "{0}/{1}/pause" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri -method "POST"
if ( -not $id ) {
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) {
$vraName = "Z-VRA-{0}" -f $name
$vraIdentifier = get-zertovra -vraName $vraName | Select-Object vraIdentifier -ExpandProperty vraIdentifier
$uri = "{0}/{1}" -f $baseUri, $vraIdentifier.toString()
Invoke-ZertoRestRequest -uri $uri -method "DELETE"
if ( -not $vraIdentifier ) {
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) {
Start-Sleep 1
}