From dfb377e847927ab74193cc513444243a49c78d97 Mon Sep 17 00:00:00 2001 From: Matt Elliott Date: Thu, 19 Dec 2019 17:30:36 -0500 Subject: [PATCH 1/2] Address issues 535, 536, and 537 --- CHANGELOG.md | 7 ++++ Rubrik/Public/Export-RubrikVApp.ps1 | 48 +++++++++++++++++----------- Rubrik/Public/Get-RubrikSnapshot.ps1 | 2 +- Rubrik/Public/Restore-RubrikVApp.ps1 | 21 ++++++------ 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92fdbf315..b360047e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). * **Fixed** for any bug fixes. * **Security** in case of vulnerabilities. +## [Unreleased] - 2019-12-19 + +### Changed +* Get-RubrikSnapshot has been changed to convert the current date/time to UTC. This addresses Issue [535](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/535) +* Restore-RubrikVApp and Export-RubrikVApp has been updated to properly deal with -PowerOn being changed to a switch-type parameter. This addresses issue [536](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/536) +* Export-RubrikVApp has been changed so that it does not request vCD to restore vApp networks if the NICs are removed or unmapped. This addresses issue [537](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/537) + ## [Unreleased] - 2019-12-31 ### Added diff --git a/Rubrik/Public/Export-RubrikVApp.ps1 b/Rubrik/Public/Export-RubrikVApp.ps1 index 6a87bd4b7..faac72fa6 100644 --- a/Rubrik/Public/Export-RubrikVApp.ps1 +++ b/Rubrik/Public/Export-RubrikVApp.ps1 @@ -17,15 +17,15 @@ function Export-RubrikVApp https://rubrik.gitbook.io/rubrik-sdk-for-powershell/command-documentation/reference/export-rubrikvapp .EXAMPLE - Export-RubrikVApp -id 'VcdVapp:::01234567-8910-1abc-d435-0abc1234d567' -snapshotid '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -ExportMode 'ExportToNewVapp' -PowerOn:$true + Export-RubrikVApp -id 'VcdVapp:::01234567-8910-1abc-d435-0abc1234d567' -snapshotid '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -ExportMode 'ExportToNewVapp' -PowerOn This exports the vApp snapshot with an id of 7acdf6cd-2c9f-4661-bd29-b67d86ace70b to a new vApp in the same Org VDC .EXAMPLE - Export-RubrikVApp -id 'VcdVapp:::01234567-8910-1abc-d435-0abc1234d567' -snapshotid '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -ExportMode 'ExportToNewVapp' -NoMapping -PowerOn:$true + Export-RubrikVApp -id 'VcdVapp:::01234567-8910-1abc-d435-0abc1234d567' -snapshotid '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -ExportMode 'ExportToNewVapp' -NoMapping -PowerOn This exports the vApp snapshot with an id of 7acdf6cd-2c9f-4661-bd29-b67d86ace70b to a new vApp in the same Org VDC and remove existing network mappings from VM NICs .EXAMPLE - Export-RubrikVApp -id 'VcdVapp:::01234567-8910-1abc-d435-0abc1234d567' -snapshotid '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -ExportMode 'ExportToNewVapp' -TargetOrgVDCID 'VcdOrgVdc:::01234567-8910-1abc-d435-0abc1234d567' -PowerOn:$true + Export-RubrikVApp -id 'VcdVapp:::01234567-8910-1abc-d435-0abc1234d567' -snapshotid '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -ExportMode 'ExportToNewVapp' -TargetOrgVDCID 'VcdOrgVdc:::01234567-8910-1abc-d435-0abc1234d567' -PowerOn This exports the vApp snapshot with an id of 7acdf6cd-2c9f-4661-bd29-b67d86ace70b to a new vApp in an alternate Org VDC .EXAMPLE @@ -35,7 +35,7 @@ function Export-RubrikVApp $restorableVms[0].PSObject.Properties.Remove('vcenterVm') $vm = @() $vm += $restorableVms[0] - Export-RubrikVApp -id $vapp.id -snapshotid $snapshot.id -Partial $vm -ExportMode ExportToTargetVapp -PowerOn:$false + Export-RubrikVApp -id $vapp.id -snapshotid $snapshot.id -Partial $vm -ExportMode ExportToTargetVapp This retreives the latest snapshot from the given vApp 'vApp01' and perform a partial export on the first VM in the vApp. The VM is exported into the existing parent vApp. Set the ExportMode parameter to 'ExportToNewVapp' parameter to create a new vApp for the partial export. @@ -97,8 +97,8 @@ function Export-RubrikVApp [ValidateNotNullOrEmpty()] [String]$NetworkMapping, # Power on vApp after restoration. - [Parameter(ParameterSetName='Full',Mandatory = $true)] - [Parameter(ParameterSetName='Partial',Mandatory = $true)] + [Parameter(ParameterSetName='Full')] + [Parameter(ParameterSetName='Partial')] [switch]$PowerOn, # Rubrik server IP or FQDN [Parameter(ParameterSetName='Full')] @@ -133,7 +133,11 @@ function Export-RubrikVApp Process { #region oneoff $resources.Body.exportMode = $ExportMode - $resources.Body.shouldPowerOnVmsAfterRecovery = $PowerOn + if($PowerOn.IsPresent) { + $resources.Body.shouldPowerOnVmsAfterRecovery = $true + } else { + $resources.Body.shouldPowerOnVmsAfterRecovery = $false + } if($Partial) { Write-Verbose -Message "Performing Partial vApp Recovery" @@ -221,12 +225,14 @@ function Export-RubrikVApp $vapp = Get-RubrikVapp -id $id # Collect networks to restore - $networks = [System.Collections.ArrayList]@() - foreach($vm in $vapp.vms) { - foreach($network in $vm.networkConnections) { - if($false -eq $networks.Contains($network.vappNetworkName)) { - $networks.Add($network.vappNetworkName) | Out-Null - Write-Verbose -Message "Flagged network $($network.vappNetworkName) for restore" + if(-Not $NoMapping -and -Not $RemoveNetworkDevices) { + $networks = [System.Collections.ArrayList]@() + foreach($vm in $vapp.vms) { + foreach($network in $vm.networkConnections) { + if($false -eq $networks.Contains($network.vappNetworkName)) { + $networks.Add($network.vappNetworkName) | Out-Null + Write-Verbose -Message "Flagged network $($network.vappNetworkName) for restore" + } } } } @@ -250,16 +256,18 @@ function Export-RubrikVApp $resources.Body.newVappParams.orgVdcId = $orgvdc $resources.Body.vmsToExport = [System.Collections.ArrayList]@() foreach($vm in $vapp.vms) { - $resources.Body.vmsToExport.Add($vm) + $resources.Body.vmsToExport.Add($vm) | Out-Null Write-Verbose -Message "Added $($vm.name) to request" } # Build networksToRestore based on networks collected from vApp - $resources.Body.networksToRestore = [System.Collections.ArrayList]@() - foreach($availablenet in $recoveropts.availableVappNetworks) { - if($networks.Contains($availablenet.name)) { - $resources.Body.networksToRestore.Add($availablenet) | Out-Null - Write-Verbose -Message "Found network $($availablenet.name) information for restore" + if(-Not $NoMapping -and -Not $RemoveNetworkDevices) { + $resources.Body.networksToRestore = [System.Collections.ArrayList]@() + foreach($availablenet in $recoveropts.availableVappNetworks) { + if($networks.Contains($availablenet.name)) { + $resources.Body.networksToRestore.Add($availablenet) | Out-Null + Write-Verbose -Message "Found network $($availablenet.name) information for restore" + } } } @@ -281,6 +289,7 @@ function Export-RubrikVApp } if($NoMapping) { + $resources.Body.networksToRestore = @() foreach($vm in $resources.Body.vmsToExport) { foreach($network in $vm.networkConnections) { Write-Verbose -Message "Unmapping $($network.vappNetworkName) from $($vm.Name)" @@ -290,6 +299,7 @@ function Export-RubrikVApp } if($RemoveNetworkDevices) { + $resources.Body.networksToRestore = @() foreach($vm in $resources.Body.vmsToExport) { $vm.networkConnections = @() } diff --git a/Rubrik/Public/Get-RubrikSnapshot.ps1 b/Rubrik/Public/Get-RubrikSnapshot.ps1 index afc8e6908..d7f5d20da 100644 --- a/Rubrik/Public/Get-RubrikSnapshot.ps1 +++ b/Rubrik/Public/Get-RubrikSnapshot.ps1 @@ -128,7 +128,7 @@ function Get-RubrikSnapshot $result = Test-ReturnFilter -Object $datesearch -Location 'date' -result $result } } elseif ($Latest) { - $datesearch = Test-DateDifference -Date $($result.date) -Compare (Get-Date) -Range 999999999 + $datesearch = Test-DateDifference -Date $($result.date) -Compare (Get-Date).ToUniversalTime() -Range 999999999 # If $datesearch is $null, a matching date was not found, so return $null if($null -eq $datesearch) { $result = $null diff --git a/Rubrik/Public/Restore-RubrikVApp.ps1 b/Rubrik/Public/Restore-RubrikVApp.ps1 index 186433e35..f7c383188 100644 --- a/Rubrik/Public/Restore-RubrikVApp.ps1 +++ b/Rubrik/Public/Restore-RubrikVApp.ps1 @@ -17,11 +17,11 @@ function Restore-RubrikVApp https://rubrik.gitbook.io/rubrik-sdk-for-powershell/command-documentation/reference/restore-rubrikvapp .EXAMPLE - Restore-RubrikVApp -id '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -PowerOn:$true + Restore-RubrikVApp -id '7acdf6cd-2c9f-4661-bd29-b67d86ace70b' -PowerOn This restores the vApp snapshot with an id of 7acdf6cd-2c9f-4661-bd29-b67d86ace70b .EXAMPLE - (Get-RubrikVApp 'vApp01' -PrimaryClusterID local | Get-RubrikSnapshot -Latest).id | Restore-RubrikVApp -PowerOn:$true + (Get-RubrikVApp 'vApp01' -PrimaryClusterID local | Get-RubrikSnapshot -Latest).id | Restore-RubrikVApp -PowerOn This retreives the latest snapshot from the given vApp 'vApp01' and restores it .EXAMPLE @@ -30,7 +30,7 @@ function Restore-RubrikVApp $restorableVms = $recoveropts.restorableVms $vm = @() $vm += $restorableVms[0] - Restore-RubrikVApp -id $id -Partial $vm -PowerOn:$false + Restore-RubrikVApp -id $id -Partial $vm This retreives the latest snapshot from the given vApp 'vApp01' and performs a partial restore on the first VM in the vApp. This is an advanced use case and the user is responsible for parsing the output from Get-RubrikVAppRecoverOption. Syntax of the object passed with the -Partial Parameter must match the format of the object returned from (Get-RubrikVAppRecoverOption).restorableVms @@ -74,8 +74,8 @@ function Restore-RubrikVApp [ValidateNotNullOrEmpty()] [String]$NetworkMapping, # Power on vApp after restoration. - [Parameter(ParameterSetName='Full',Mandatory = $true)] - [Parameter(ParameterSetName='Partial',Mandatory = $true)] + [Parameter(ParameterSetName='Full')] + [Parameter(ParameterSetName='Partial')] [switch]$PowerOn, # Rubrik server IP or FQDN [Parameter(ParameterSetName='Full')] @@ -109,20 +109,23 @@ function Restore-RubrikVApp Process { #region oneoff + if($PowerOn.IsPresent) { + $resources.Body.shouldPowerOnVmsAfterRecovery = $true + } else { + $resources.Body.shouldPowerOnVmsAfterRecovery = $false + } + if($Partial) { Write-Verbose -Message "Performing Partial vApp Recovery" $resources.Body.vmsToRestore = @() $resources.Body.vmsToRestore += $Partial - $resources.Body.shouldPowerOnVmsAfterRecovery = $PowerOn $body = ConvertTo-Json -InputObject $resources.Body -Depth 4 Write-Verbose -Message "REST Body $($body)" - } - else { + } else { Write-Verbose -Message "Performing Full vApp Recovery" $recoveropts = Get-RubrikVAppRecoverOption -id $id $resources.Body.vmsToRestore = $recoveropts.restorableVms - $resources.Body.shouldPowerOnVmsAfterRecovery = $PowerOn if($DisableNetwork) { foreach($vm in $resources.Body.vmsToRestore) { From 3cd408084b6d790c7a8b246170dec7ba8138b5a1 Mon Sep 17 00:00:00 2001 From: Matt Elliott Date: Thu, 19 Dec 2019 17:35:17 -0500 Subject: [PATCH 2/2] Add detail to changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b360047e2..94cb41e97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - 2019-12-19 ### Changed -* Get-RubrikSnapshot has been changed to convert the current date/time to UTC. This addresses Issue [535](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/535) +* Get-RubrikSnapshot has been changed to convert the current date/time to UTC when using the -Latest parameter. This addresses Issue [535](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/535) * Restore-RubrikVApp and Export-RubrikVApp has been updated to properly deal with -PowerOn being changed to a switch-type parameter. This addresses issue [536](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/536) * Export-RubrikVApp has been changed so that it does not request vCD to restore vApp networks if the NICs are removed or unmapped. This addresses issue [537](https://github.com/rubrikinc/rubrik-sdk-for-powershell/issues/537)