VMware Cloud Community
BWinchell
Enthusiast
Enthusiast

VM Template deployment with Customization or Sysprep?

Hello,

I am trying to build a workflow that will deploy a VM pre-built template, apply the customization spec via the Customization Manager, then finally customize the VM with additional disks, network, etc...

My current issue is with really understanding the actual terminology/category of the Customization Manager Spec.  Inside of there, we have multiple specs for Windows & Linux.

I have this piece of test code that seems to get the correct spec.

//Set SDK connection

var vcDatacentreString = vcDatacentre.name;

var sdkUrl = "https://vcenter.domain.local:443/sdk";

var allSdk = VcPlugin.allSdkConnections;

var vcs = [];

    //Debug

        if (debugOutput == true) {

            System.debug("DEBUG_LOG_Module=SetVmFolder: var sdkUrl = " + sdkUrl);

            System.debug("DEBUG_LOG_Module=SetVmFolder: var allSdk = " + allSdk);

        }

// Validate SDK connection to target vCenter

    var len = allSdk.length;

    for (i = 0; i < len; i++) {

        if (allSdk[i].displayName == sdkUrl) {

            vcs.push(allSdk[i]);

        }

        //Debug

            if (debugOutput == true) {

                System.debug("DEBUG_LOG_Module=SetVmFolder: var allSdk[i] = " + allSdk[i]);

                System.debug("DEBUG_LOG_Module=SetVmFolder: var allSdk[i].displayName = " + allSdk[i].displayName);

            }

    }

    System.log("Target vCenter SDK connection: " + vcs)

    // Error check

        if (vcs.length != 1) {

            System.error("!!!!!!!!!!!!!!!!!!!!!Error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

            System.error("Module=SetVmFolder");

            System.error("Too many/few vCenters match SDK string");

            System.error("!!!!!!!!!!!!!!!!!!!!!Error!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");

            throw Error();

        }

var SDKConnection = vcs[0];

//var ip = "10.10.10.233";

//var custspec = new VcCustomizationSpec();

//var custspec = new VcVirtualMachineCloneSpec();

var con = SDKConnection;

System.debug("con: " + con);

var cms = con.customizationSpecManager;

System.debug("cms : " + cms);

System.debug("cmsType: " + cms.vimType);

var customSpecExists = cms.doesCustomizationSpecExist(specName);

System.debug("isda: " + customSpecExists);

//Get CustSpec if it exist

if (customSpecExists) {

     var customSpecItem = cms.getCustomizationSpec(specName);

    System.debug("got custSpecItem: " + customSpecItem);

    custspec = customSpecItem.spec;

    System.debug("contents custSpec: " + custspec);

    System.debug("custspec name: " + customSpecItem.info.name);

    System.debug("custspec type: " + customSpecItem.info.type);

    System.debug("custspec description: " + customSpecItem.info.description);

    } else throw "customspec not found";

/*

var oldip = custspec.nicSettingMap[0].adapter.ip;

System.debug("oldip: " + oldip);

var fixedIp = new VcCustomizationFixedIp();

fixedIp.ipAddress = ip;

custspec.nicSettingMap[0].adapter.ip = null;

custspec.nicSettingMap[0].adapter.ip = fixedIp;

System.debug("new ip in custspec: " + custspec.nicSettingMap[0].adapter.ip);

System.debug("new ipAddress in custspec: " + custspec.nicSettingMap[0].adapter.ip.ipAddress);

*/

var newSpec = custspec;

My confusion comes in with what type of spec is needed to equate the manual template deployment process in vCenter when you select Customization Manager?

I have looked through the API and found:

VcCustomizationSysprep

VcVirtualMachineSpec

VcVirtualMachineCloneSpec

and a few others

If I try to pass this spec to com.vmware.library.vc.vm(cloneVM) = I get the error that the spec is not a VirtualMachineCloneSpec

If I try to pass this spec to com.vmware.library.vc.vm(customizeVM) = it complains the customization cannot happen when the VM is powered on (leading me to believe it thinks this is a device spec config)

Thanks

B

0 Kudos
5 Replies
BWinchell
Enthusiast
Enthusiast

Hello,

Nobody has any suggestions or a direction?

Thanks

B

0 Kudos
BWinchell
Enthusiast
Enthusiast

Hello,

Let me ask this question to try to clarify what I am trying to do.

Is there a difference between "Clone VM" & "Deploy from Template" when it comes to the actual actions?

My understanding is:

CLONE = make an exact copy

DEPLOY = Make a copy and then change things (name, mac, etc...)

I am still trying to figure out how to deploy from a template and apply the Windows customization that is built into vCenter.  Sounds simple enough but.....

Thanks

B

0 Kudos
tschoergez
Leadership
Leadership

Hi,

I think clone and deploy are just different terms, but both refer to the same "cloneVM_Task()" method of the vCenter API.

For this you have to specify the cloneSpec, (new vm name, datastore, ....). The clone spec now optionally can contain customization.

In addition there is also a "pure" customizeVM_Task(), which just takes customizationSpec, and does not clone a VM, but just applies the cusomization for next restart of the VM.

I would recommend to separate the task even if you want to automate the whole story (clone / deplyoe a template, then customize). So you can make sure each part individually works.

The customizationSpec is indeed a bit confusing, and hard to get right for all the variables. By separating you save some time because you can apply the customization after the VM is cloned, and don't havce to redo the cloning all the time (might not matter that much with modern high-performance storage though 😄 ).

For the customizationSpec it might be easier to start with a existing customization Specification from vCenter, for which you know it works when using manually in vSphere Client.

Find some more examples in these (old, but still valid) threads:

Clone VM using existing CustomizationSpec and changing ComputerName property

Use vCenter custom specification during VRO flow

Regards,

Joerg

0 Kudos
BWinchell
Enthusiast
Enthusiast

Makes sense.  I have been caught up with some other projects but will circle back to this next week.

Thanks

B

0 Kudos
A13x
Hot Shot
Hot Shot

We powershell script our deployments so we deploy from template, once it has been deployed from template (in a powered off state still) we then pass through the spec (change /customise it while powered off). Then we execute the power on command and it goes through the customised sysprep based on what parameters are passed through.

The reason for deploying from template compared to clone is that you have the ability to customise using profiles where as a clone is an exact copy

0 Kudos