Last active
October 14, 2019 20:30
-
-
Save shamsway/bc1b40599efaa7ceb106dc8029854b2e to your computer and use it in GitHub Desktop.
VMworld 2019 HBI3518BUS Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Trigger CDM to refresh metadata from vCD | |
# Updated 10.14.19 to utilize new vCD-specific cmdlets in the PowerShell SDK for Rubrik | |
Import-Module Rubrik | |
$Key = "[API key]" # Key must be assigned to a user with Admin credentials to trigger metadata refresh | |
$vcdid = "[ID of vCD Server] # Ex: Vcd:::f96a2b1b-a06d-4f17-b6be-52141795532e | |
# Connect to Envoy, or CDM | |
Connect-Rubrik -Server [Server:Port] -Token $Key | Out-Null | |
# Refresh vCD | |
$refresh = Update-RubrikVCD -id $vcdid | |
$url = $refresh.links.href | |
$endpoint = $url -replace "^.*?(vcd\/cluster\/request\/.*?)$", '$1' | |
$refreshtask = Invoke-RubrikRESTCall -Endpoint $endpoint -Method GET -api internal | |
Write-Output "vCD Refresh Status: $($refreshtask.status)" | |
sleep 5 | |
$counter = 0 | |
while($refreshtask.status -ne "SUCCEEDED") | |
{ | |
Write-Output "vCD Refresh Status: $($refreshtask.status)" | |
sleep 5 | |
$refreshtask = Invoke-RubrikRESTCall -Endpoint $endpoint -Method GET -api internal | |
$counter += 1 | |
if($counter -eq 12) { throw "Refresh task took too long" } | |
} | |
Write-Output "vCD Refresh Status: $($refreshtask.status)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clone a vApp template into our vDC | |
Import-Module VMware.VimAutomation.Cloud | |
# Connect to vCD | |
Connect-CIServer -Server [vcd server] -User [username] -Password "[password]" -Org [org] | |
# Clone new template into Tenant1 VDC | |
$template = Get-CIVappTemplate -Name '[template]' | |
$orgvdc = Get-OrgVdc -Name "[org vDC]" | |
Write-Output "`n*** Cloning Template ****" | |
New-CIVapp -Name '[vApp name]' -OrgVdc $orgvdc -VAppTemplate $template | |
# If necessary, trigger Rubrik CDM to refresh vCD metadata via Refresh-vCD.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assign an SLA to our newly deployed vApp | |
# Updated 10.14.19 to utilize new vCD-specific cmdlets in the PowerShell SDK for Rubrik | |
Import-Module Rubrik | |
$Key = "[API Key]" | |
$Name = "[vApp Name]" | |
# Connect to Envoy | |
Connect-Rubrik -Server 192.168.1.200:4443 -Token $Key | Out-Null | |
# Get SLA ID to assign to vApp | |
$slaid = (Get-RubrikSLA -Name "Bronze" -PrimaryClusterID "local").id | |
# Search for new vApp | |
$response = Get-RubrikVApp -Name $Name -Relic:$false | |
Write-Output "`nFound $($response.Count) matching vApp(s)" | |
# If vApp was found, assign SLA | |
if($response.Count -eq 1) | |
{ | |
$vappid = $response.id | |
Write-Output "Assigning $($slaid) to $($vappid)" | |
$slaresponse = Protect-RubrikVApp -ID $vappid -SLAID $slaid | |
Write-Output "SLA $($slaresponse.configuredSlaDomainName) assigned to $($slaresponse.name)" | |
} | |
elseif($response.total -gt 1) { | |
throw "Multiple vApps named $($Name)" | |
} | |
else { | |
throw "Could not find vApp $($Name)" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment