Following is an example for configuring a VM's "guest properties" (in vSphere this is called "OVF settings/environment") using PowerCLI (or API).
Note that this script was designed to run as an "org admin" (i.e. tenant) and was tested on vCD 5.1.
The script performs the following operations:
- Instantiate a vApp from template
- Add network to the vApp and connect it to an org network
- Configure a bunch of vApp specific "guest properties" (OVF settings)
$ciServerName = '...'
$vAppInstanceName = '...'
$orgNetworkName = '...'
$templateName = '...'
$ipAddress = '...'
$connection = Connect-CIServer $ciServerName -Org netapp -User ... -Password ...
# Create a new vApp from a vApp template
$vappTemplate = Get-CIVAppTemplate -Name $templateName
$vApp = $vappTemplate | New-CIVApp $vAppInstanceName
$vm = $vApp|Get-CIVM
# Create a vApp network and connect it to the desired org network
$vAppNet = New-CIVAppNetwork -Direct -VApp $vApp -ParentOrgNetwork $orgNetworkName
$nic = ($vm |Get-CINetworkAdapter)|Where-Object {$_.Primary}
Set-CINetworkAdapter -NetworkAdapter $nic -VAppNetwork $vAppNet -IPAddressAllocationMode Manual -IPAddress $ipAddress -Connected $true
# Search for the guest properties section (OVF settings) - this is called "product section" in the API/CLI
$vmProductSection = $vm.ExtensionData.GetProductSections()
$vsa = $vmProductSection.ProductSection[0]
# Set the value of individual properties
($vsa.Items|Where-Object {$_.key -eq 'ipaddr'}).value = '...'
($vsa.Items|Where-Object {$_.key -eq 'netmask'}).value = '...'
($vsa.Items|Where-Object {$_.key -eq 'hostname'}).value = '...'
($vsa.Items|Where-Object {$_.key -eq 'gateway'}).value = '...'
($vsa.Items|Where-Object {$_.key -eq 'password'}).value = '...'
# Commit the changes
$vmProductSection.UpdateServerData()
# Finally start the vApp
Start-CIVApp $vapp
M.