Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address issues 535, 536, and 537 #538

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)

## [Unreleased] - 2019-12-31

### Added
Expand Down
48 changes: 29 additions & 19 deletions Rubrik/Public/Export-RubrikVApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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')]
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
}
}
}
}
Expand All @@ -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"
}
}
}

Expand All @@ -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)"
Expand All @@ -290,6 +299,7 @@ function Export-RubrikVApp
}

if($RemoveNetworkDevices) {
$resources.Body.networksToRestore = @()
foreach($vm in $resources.Body.vmsToExport) {
$vm.networkConnections = @()
}
Expand Down
2 changes: 1 addition & 1 deletion Rubrik/Public/Get-RubrikSnapshot.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 12 additions & 9 deletions Rubrik/Public/Restore-RubrikVApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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')]
Expand Down Expand Up @@ -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) {
Expand Down