PowerCLI Script to Recover Pivotal Operations Manager VApp Settings

Posted On // Leave a Comment

If you've read my previous blog posts, you know that I'm running a home vSphere lab on a shoestring budget with hardware that is "mostly" working "most" of the time.


One of my NUC hosts locked up recently and I was noticing that my Pivotal Operations Manager VM for Cloud Foundry just wouldn't use the static IP address I had assigned to it at install. The networking settings are stored as VApp Options that you can set when you deploy the Operations Manager OVA. I figured that maybe the failure caused those settings to get out of sync, so I tried to update them again and save the updates, but I kept getting an error from vCenter Web Client say that it "Cannot complete operation due to concurrent modification by another operation."


I thought something must be out of whack, so I removed the VM from inventory, and re-added it back. Of course when you do that you lose all the VApp options you had set, but you also lose the definition that they existed in the first place! So, I wrote a little PowerCLI script to recover those settings in case I lose them again so that I don't have to re-deploy the Operations Manager VM. Just copy and paste this text into your favorite text editor, update the "Set Values" section and VM Name in the second to last line, and then paste the script into PowerCLI to run it:


function BuildProp([int]$key, [string]$id, [string]$label, [string]$type, [string]$description)
{
    $prop = New-Object VMware.Vim.VAppPropertySpec
    $prop.operation = "add"
    $prop.info = New-Object VMware.Vim.VAppPropertyInfo
    $prop.info.key = $key
    $prop.info.id = $id
    $prop.info.label = $label
    $prop.info.type = $type
    $prop.info.userConfigurable = $true
    $prop.info.description = $description
    return $prop
}

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.VAppConfig = New-Object VMware.Vim.VmConfigSpec
$spec.VAppConfig.OvfEnvironmentTransport = [string[]]"com.vmware.guestInfo"
$spec.VAppConfig.Property = New-Object VMware.Vim.VAppPropertySpec[] (7)
$spec.VAppConfig.Property[0] = BuildProp 0 "admin_password" "Admin Password" "password" "This password is used to SSH into the Ops Manager. The username is 'ubuntu'."
$spec.VAppConfig.Property[1] = BuildProp 1 "ip0" "IP Address" "string" "The IP address for the Ops Manager. Leave blank if DHCP is desired."
$spec.VAppConfig.Property[2] = BuildProp 2 "DNS" "DNS" "string" "The domain name servers for the Ops Manager (comma separated). Leave blank if DHCP is desired."
$spec.VAppConfig.Property[3] = BuildProp 3 "netmask0" "Netmask" "string" "The netmask for the Ops Manager's network. Leave blank if DHCP is desired."
$spec.VAppConfig.Property[4] = BuildProp 4 "ntp_servers" "NTP Servers" "string" "Comma-delimited list of NTP servers"
$spec.VAppConfig.Property[5] = BuildProp 5 "gateway" "Default Gateway" "string" "The default gateway address for the Ops Manager's network. Leave blank if DHCP is desired."
$spec.VAppConfig.Property[6] = BuildProp 6 "custom_hostname" "Custom Hostname" "string" "This will be set as the hostname on the VM. Default: 'pivotal-ops-manager'."

#Set Values to whatever is appropriate for your environment
$spec.VAppConfig.Property[0].Info.Value = ""
$spec.VAppConfig.Property[1].Info.Value = ""
$spec.VAppConfig.Property[2].Info.Value = ""
$spec.VAppConfig.Property[3].Info.Value = ""
$spec.VAppConfig.Property[4].Info.Value = ""
$spec.VAppConfig.Property[5].Info.Value = ""
$spec.VAppConfig.Property[6].Info.Value = ""

# Change the VM name below to the name of your Operations Manager VM that you want to repair
$vm = Get-VM -Name CHANGEME_I_AM_A_PLACEHOLDER
$vm.ExtensionData.ReconfigVM_Task($spec)

0 comments: