Quantcast
Channel: VMware Communities : Popular Discussions - vCloud Director PowerCLI
Viewing all articles
Browse latest Browse all 13334

Example for configuring VM's "guest properties" (i.e. OVF settings)

$
0
0

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:

  1. Instantiate a vApp from template
  2. Add network to the vApp and connect it to an org network
  3. 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.


Viewing all articles
Browse latest Browse all 13334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>