Initiate Raw Data cloud-init Customization with the vSphere Web Services API

Use the following steps to initiate customization with raw cloud-init data by using the vSphere Web Services API.

  1. Build a customization specification of type CustomizationSpec. Set the following properties in the spec:
    1. The globalIPSettings property must be present but need not contain its optional child properties. If the child properties are present, they will be ignored during the method call.
    2. The identity property must be present and must have type CloudinitPrep.
      • The child property identity.metadata is required. It contains the entire text of the metadata file, less any final new line character.
      • The child property identity.userdata is optional. If present, it contains the entire text of the userdata file, less any final new line character.
    Example:
    CloudinitPrep cloudinit = new CloudinitPrep();
    cloudinit.setMetadata(metadataText);
    cloudinit.setUserdata(userdataText);
    CustomizationGlobalIPSettings ipSettings = new CustomizationGlobalIPSettings();
    CustomizationSpec custSpec = new CustomizationSpec();
    custSpec.setIdentity(cloudinit);
    custSpec.setGlobalIPSettings(ipSettings);
    Note: The nicSettingsMap property, if present, will be ignored for raw data customization. The cloud-init tool accepts network customization only from the identity.metadata property.
  2. Invoke the method VirtualMachine.CustomizeVM_Task, passing the customizationSpec as parameter. The method returns a Task object that you can use to monitor completion of the customization steps.
    Example:
    ManagedObjectReference custTask = service.CustomizeVM_Task(vmRef, custSpec);
  3. Power on the virtual machine. As it boots, cloud-init applies the metadata configuration settings to the guest operating system. After the guest finishes booting and before it opens a shell window, cloud-init applies the userdata configuration.