vCloud Director – retain IP/Mac

I found myself in need of changing a network setting on a bunch of vCD vApps.  The setting in question (“Retain IP/MAC Resources” in the GUI, “RetainNetInfoAcrossDeployments” from the API) causes the vApp to retain it’s assigned IP (apparently by retaining the VCNS components), even after stopping and expiring the vApp. (it releases the IP when it is removed from “Expired Items”)

I first checked Set-CIVAppNetwork but the option was not listed.  I found it using (get-civapp <name>|get-civappnetwork).extensiondata.configuration

BackwardCompatibilityMode :
IpScope :
IpScopes : VMware.VimAutomation.Cloud.Views.IpScopes
ParentNetwork : VMware.VimAutomation.Cloud.Views.Reference
FenceMode : natRouted
RetainNetInfoAcrossDeployments : True
Features : {, VMware.VimAutomation.Cloud.Views.FirewallService, VMware.VimAutomation.Cloud.Views.NatService, VMware.VimAutomation.Cloud.Views.StaticRoutingService}
SyslogServerSettings : VMware.VimAutomation.Cloud.Views.SyslogServerSettings

But could not see a way to change it until my GoogleFu turned up a VMware Communities post where pwmiller demonstrates using .UpdateServerData() along with GetNetworkConfigSection(), both of which are Methods for extensiondata.

However, when I tried the script it would not work without a tweak, either a typo from 11/2013 or a change in PowerCLI:

$vapp = get-civapp 
$networkconfigsection = $vapp.ExtensionData.GetNetworkConfigSection()
$vappnetwork = $networkconfigsection.networkconfig | Where-Object {$_.networkName -match }
$vappnetwork.configuration.RetainNetInfoAcrossDeployments = $false
$networkconfigsection.UpdateServerData()

The bold is my fix to get the code working. Now I’ll have to investigate those additional methods a little more…

This entry was posted in Cloud, Computing, PowerShell, Scripting, Virtualization, VMware and tagged , , , . Bookmark the permalink.

Leave a Reply