Automating VCF Upgrade - SDDC Manager

This is part three of a four part blog series in which I talk about automating the VMware Cloud Foundation upgrade process. If you have been following the series so far then you will have your bundles downloaded, and performed various health checks to confirm that all is well and will now be ready to start the upgrade process.

Upgrading VMware Cloud Foundation is a multi-stage process, this post will focus on upgrading SDDC Manager which in itself involves two step:

  • Step 1 - Upgrade SDDC Manager
  • Step 2 - Apply Configuration Drift to SDDC Manager

VMware Cloud Foundation APIs Used

  • GET /v1/upgradables/domains/
  • GET /v1/domains/
  • GET /v1/bundles
  • GET /v1/upgrades/

PowerVCF Cmdlets

  • Get-VCFWorkloadDomain
  • Get-VCFBundle
  • Get-VCFUpgrade

PowerShell Scripts

Upgrade SDDC Manager

  1. Start Windows PowerShell.

  2. Replace the values in the sample code with values for the instance of VMware Cloud Foundation and run the commands in the PowerShell console.

1$sddcManagerFqdn = "lax-vcf01.lax.rainpole.io"
2$sddcManagerUser = "[email protected]"
3$sddcManagerPass = "VMw@re1!"
4$vcfRelease = "4.5.2.0"
  1. Authenticate to the SDDC Manager appliance by running the following command:
1Request-VCFToken -fqdn $sddcManagerFqdn -username $sddcManagerUser -password $sddcManagerPass
  1. Perform SDDC Manager upgrade by running the following command:
 1$workloadDomain = (Get-VCFWorkloadDomain | Where-Object {$_.type -eq "MANAGEMENT"}).id
 2$uri = "https://$sddcManager/v1/upgradables/domains/$workloadDomain/?targetVersion=$vcfRelease"
 3$bundle = ((Invoke-RestMethod -Method GET -URI $uri -ContentType application/json -headers $headers).elements)
 4if ((Get-VCFBundle -id $bundle.bundleId).downloadStatus -eq "SUCCESSFUL" -and (Get-VCFBundle -id $bundle.bundleId).type -eq "SDDC_MANAGER") {
 5    $jsonSpec = '{
 6        "bundleId": "'+ $bundle.bundleId +'",
 7        "resourceType": "DOMAIN",
 8        "resourceUpgradeSpecs": [ {
 9            "resourceId": "'+ $workloadDomain +'",
10            "upgradeNow": true
11        } ]}'
12    $task = Start-VCFUpgrade -json $jsonSpec
13    Write-Output " Waiting for Upgrade Task ($($task.name)) with Id ($($task.id)) to Complete"    
14    Do { Start-Sleep 60; Request-VCFToken -fqdn $sddcManagerFqdn -username $sddcManagerUser -password $sddcManagerPass | Out-Null; $status = Get-VCFUpgrade -id $task.id } While ($status.status -in "PENDING","SCHEDULED","INPROGRESS")
15    Write-Output " Upgrade Task with Id ($($task.id)) completed with status ($($status.status))"
16} else {
17    Write-Warning " Upgrade Not Possible as Required Bundle ($bundleId) Not Downloaded to SDDC Manager"
18}

In this step we use the Get-VCFWorkloadDomain cmdlet to get the Management Domain Id which we use in the JSON spec for performing the upgrade process, we also use the /v1/upgradables/domains/ API to get the details of next available bundle for performing the SDDC Manager upgrade (This API is not currently in PowerVCF). We perform a few checks before starting the upgrade which include:

  • Check that the next upgradable bundle has been physically downloaded to SDDC Manager
  • Check that the next upgradable bundle has a type of SDDC_MANAGER

If both of these conditions are true we proceed using the Start-VCFUpgrade cmdlet to trigger the upgrade, capturing the API response in $task which we then use with the Get-VCFUpgrade cmdlet to perform a Do { } While { } loop on the upgrade task Id until the status is no longer in a Scheduled, Pending or In Progress state.

  1. Perform SDDC Manager drift configuration by running the following command:
 1$workloadDomain = (Get-VCFWorkloadDomain | Where-Object {$_.type -eq "MANAGEMENT"}).id
 2$uri = "https://$sddcManager/v1/upgradables/domains/$workloadDomain/?targetVersion=$vcfRelease"
 3$bundle = ((Invoke-RestMethod -Method GET -URI $uri -ContentType application/json -headers $headers).elements)
 4if ((Get-VCFBundle -id $bundle.bundleId).downloadStatus -eq "SUCCESSFUL" -and (Get-VCFBundle -id $bundle.bundleId).type -eq "SDDC_MANAGER") {
 5    $jsonSpec = '{
 6        "bundleId": "'+ $bundle.bundleId +'",
 7        "resourceType": "DOMAIN",
 8        "resourceUpgradeSpecs": [ {
 9            "resourceId": "'+ $workloadDomain +'",
10            "upgradeNow": true
11        } ]}'
12    $task = Start-VCFUpgrade -json $jsonSpec
13    Write-Output " Waiting for Upgrade Task ($($task.name)) with Id ($($task.id)) to Complete"    
14    Do { Start-Sleep 60; Request-VCFToken -fqdn $sddcManagerFqdn -username $sddcManagerUser -password $sddcManagerPass | Out-Null; $status = Get-VCFUpgrade -id $task.id } While ($status.status -in "PENDING","SCHEDULED","INPROGRESS")
15    Write-Output " Upgrade Task with Id ($($task.id)) completed with status ($($status.status))"
16} else {
17    Write-Warning " Upgrade Not Possible as Required Bundle ($bundleId) Not Downloaded to SDDC Manager"
18}

For the configuration drift part we can execute the same process again.

Once complete that's it we have successfully upgraded SDDC Manager programmatically.


Posts in this Series