Hi Everyone - I need a little help. I'm very green with VCO. I have a question about how I set an IP address for a specified OS Customization Spec. Essentially what I want to do is:
Clone a VM -> Modify Num CPU -> Modify RAM GB -> Modify IP Address, DNS Servers, Default Gateway in a specified OS Customization Spec, apply to VM -> Power On VM. The section in red is where I'm having a hard time. I'm very good with PowerCLI but not so much with JavaScript. I seem to be getting lost in what methods to call. I know I can simply do with with PowerCLI by executing the following command-lets.
Get-OSCustomizationSpec -Name $_.OSCSpec | Get-OSCustomizationNicMapping | Set-OSCustomizationNicMapping -IpAddress $_.Ip -SubnetMask $_.Subnet -DefaultGateway $_.GW -Dns $_.DnsP,$_.DnsS -IPMode UseStaticIP;
I have been doing lots of Google Searching and I know the section that I have highlighted above in red will need to use Java Script. I found something in the VMware Communities that looks like it should work, but the IP address is never set to the specified IP after the code runs. Here is the code that I'm using.
var custspec = new VcCustomizationSpec(); //System.debug("OSC Template: " + custspec); var con = SDKConnection; //System.debug("vCenter Connection: " + con); var cms = con.customizationSpecManager; //System.debug("Cust Spec Manager: " + cms); var customSpecExists = cms.doesCustomizationSpecExist(specName); //System.debug("Does OSC Exist? " + customSpecExists); if (customSpecExists) { var customSpecItem = cms.getCustomizationSpec(specName); System.debug("got custSpecItem: " + customSpecItem); custspec = customSpecItem.spec; System.debug("contents custSpec: " + custspec); VMtocustomize.customizeVM_Task(custspec); } else throw "customspec not found"; var oldip = custspec.nicSettingMap[0].adapter.ip; System.log("Old IP Address: " + oldip); //Set IP Settings for custspec var fixedIp = new VcCustomizationFixedIp(); fixedIp.ipAddress = ip; System.log("fixedIP: " + fixedIp); System.log("fixedIP.ipAddress: " + fixedIp.ipAddress); //Null old IP before setting new IP custspec.nicSettingMap[0].adapter.ip = null; custspec.nicSettingMap[0].adapter.ip = fixedIp.ipAddress; System.log("New IP in custspec: " + custspec.nicSettingMap[0].adapter.ip); System.log("New IP Address in custspec: " + custspec.nicSettingMap[0].adapter.ip.ipAddress); //let it sleep so it is ready System.sleep(10*1000); //Start the VM VMtocustomize.powerOnVM_Task(null);
specName is String
SDKConnection is VC:SdkConnection
VMtoCustomize is VC:VirtualMachine
ip is String
When I run my code here is what I get in my logs:
[2014-11-19 19:01:49.747] [D] got custSpecItem: DynamicWrapper (Instance) : [VcCustomizationSpecItem]-[class com.vmware.vim.vi4.CustomizationSpecItem] -- VALUE : com.vmware.vim.vi4.CustomizationSpecItem@5975d454
[2014-11-19 19:01:49.747] [D] contents custSpec: DynamicWrapper (Instance) : [VcCustomizationSpec]-[class com.vmware.vim.vi4.CustomizationSpec] -- VALUE : com.vmware.vim.vi4.CustomizationSpec@19247372
[2014-11-19 19:01:49.816] [I] Old IP Address: DynamicWrapper (Instance) : [VcCustomizationFixedIp]-[class com.vmware.vim.vi4.CustomizationFixedIp] -- VALUE : com.vmware.vim.vi4.CustomizationFixedIp@484a5709
[2014-11-19 19:01:49.817] [I] fixedIP: DynamicWrapper (Instance) : [VcCustomizationFixedIp]-[class com.vmware.vim.vi4.CustomizationFixedIp] -- VALUE : com.vmware.vim.vi4.CustomizationFixedIp@c100862a
[2014-11-19 19:01:49.817] [I] fixedIP.ipAddress: 172.22.1.200
[2014-11-19 19:01:49.820] [I] Cannot convert 172.22.1.200 to com.vmware.vim.vi4.CustomizationIpGenerator (Workflow:Template / Scriptable task (item1)#28)
If someone could please help that would be so ultra cool! Thanks guys!