For John’s question in the VMware Communities about customizing a VM here:
http://communities.vmware.com/thread/311899
I took the challenge and created a small example how to customize a Virtual Machine using the CustomizeVM_Task().
The network settings, licensing, domain stuff and so on should come from a sysprep.inf text file.
Creating the proper CustomizationSpecification is really a hard job, especially since a couple of settings are mandatory even if the used information is already given via the SysprepText.
I got help using the API Reference, and the UML charts in Steve Jin’s indispensable book (http://www.amazon.com/VMware-VI-vSphere-SDK-Infrastructure/dp/0137153635 , I cannot mention it often enough… and no, that’s not an affiliate-link…yet… 😀 ), page 242.
When testing it, I got a lot of not helpful errors like “Cannot complete customization”. If you increase the loglevel in vCenter, in the vCenter logs there are a bit more information. Just don’t forget to reset it afterwards to avoid “logflooding”.
At the end I ended up with this code:
var sysprepMime = sysprepFile.getContentAsMimeAttachment(); var sysprepText = sysprepMime.content System.debug("sysprep: " + sysprepText); //create the custSpec objects var custSpec = new VcCustomizationSpec(); System.debug("custSpec: " + custSpec); var myVcCustomizationSysprepText = new VcCustomizationSysprepText() ; System.debug("myVcCustomizationSysprepText: " + myVcCustomizationSysprepText); myVcCustomizationSysprepText.value = sysprepText //from Resource element above custSpec.identity = myVcCustomizationSysprepText; System.debug("custSpec.identity: " + custSpec.identity); //fill the mandatory GlobalIPSettings var myVcCustomizationGlobalIPSettings = new VcCustomizationGlobalIPSettings() ; custSpec.globalIPSettings = myVcCustomizationGlobalIPSettings; System.debug("custSpec.globalIPSettings: " + custSpec.globalIPSettings); //fill in the NIC-settings-map for one nic with unknownIPGenerator (IP-spec is in sysprep-text): var mappingMap = new Array(); var myVcCustomizationAdapterMapping = new VcCustomizationAdapterMapping() ; var myVcCustomizationIPSettings = new VcCustomizationIPSettings() ; var myIpGenerator; //myIpGenerator = new VcCustomizationUnknownIpGenerator() ; //myIpGenerator = new VcCustomizationFixedIp(); //myIpGenerator.ipAddress = "1.2.3.4"; myIpGenerator = new VcCustomizationDhcpIpGenerator() ; myVcCustomizationIPSettings.ip = myIpGenerator; myVcCustomizationAdapterMapping.adapter = myVcCustomizationIPSettings; System.debug("myVcCustomizationIPSettings.ip:" + myVcCustomizationIPSettings.ip); System.debug("myVcCustomizationAdapterMapping.adapter: " + myVcCustomizationAdapterMapping.adapter); mappingMap.push(myVcCustomizationAdapterMapping); System.debug("mappingMap: " + mappingMap); //adding map to custSpec custSpec.nicSettingMap = mappingMap; vmToCustomize.customizeVM_Task(custSpec);
Download the full workflow example here: http://www.vcoportal.de/download/workflow/customizeVM.workflow
Hi Joerg, did you ever find the solution for using the customization with an static IP?. I am struggling since I used to rely for this on vCloud director, now that I am moving to the vCAC+vSphere combo I need to find a workflow that takes care of that, but without any of the sysprep piece (like joining domain, time zone, license, etc). I basically need DNS and network settings, but the getCustomizationSpec method must have an identity variable that I don’t know how to obtain.
Thanks,
Juan.
Hi Juan,
if you want to have vCenter to customize the IP address of the VM, sysprep is always used.
So you have to specify domain, licensing, time zone and so on, otherwise you will get an error from vCenter when trying to apply the customization.
Also, check the links in this thread: https://communities.vmware.com/thread/311899
Cheers,
Joerg
When using a fixed IP address, you also need to set the gateway and subnet mask in the CustomizationIpSettings.