VMware Cloud Community
maguar9999
Contributor
Contributor

Need some help getting started with cloning via customization specification

I am interested in extending the pre-created Workflow "CloneVM from properites". I do not want to have to specify the properties within orchestrator, but would like to use one of my named "Customization Specifications" that I create and maintain in Virtual Center. Is that possible to do? I have not been able to find the API that can load a "Customization Specification" can pass it to this workflow.

11 Replies
maguar9999
Contributor
Contributor

If it helps, I am looking for an analog of this Simple PowerCLI command:

$strNewVMName = "NEWVM"

$strTemplate = "Template"

$strDestinationHost = "10.32.0.222"

$strCustomSpec = "MyCustomizationSpecInVC"

New-VM -Name $strNewVMName -Template $(get-template $strTemplate) -VMHost $(Get-VMHost $strDestinationHost) -DiskStorageFormat Thin -OSCustomizationSpec $(Get-OSCustomizationSpec $strCustomSpec) -Datastore Storage3

Reply
0 Kudos
admin
Immortal
Immortal

Hi,

I think you are looking out for a saved customization spec and pass the same in the Clone VM API call instead of creating a new one.

You can refer to the API GetCustomizationSpec which is defined in CustomizationSpecManager MO. Using this you can fetch the saved customization spec and also create a new one.

I hope this helps you!!

- Angela -

Reply
0 Kudos
hodnov2
Contributor
Contributor

Has anyone figured out how to do this?

When I look at the "getCustomizationSpec" I don't see any way to match an attribute to a Customization Spec Name.

I'm new to Orchestrator, so bare with me.  But I'd like to be able to create a workflow that will clone a vm and have the new vm be customized by a pre-existing customization spec.

There doesn't seem to be a pre-defined object in Orchestrator for existing Customization Specs (such as VC:vmFolder, or VC:VirtualMachine)

I don't want to have to input the Customization Spec name as a string.  It should be something you can pick like how you can pick what folder the new vm will be located in.

Please help.

Thanks.

Reply
0 Kudos
tschoergez
Leadership
Leadership

Hi!

Don't get confused: The Action "getCusomizationSpec" creates a new CustomizationSpec-Object "on-the-fly". It has nothing to do with the API-method Angela mentioned.

If you want to use an exisiting speficication, you have to do your own scripting:


var custspec = new VcCustomizationSpec();
var con = SDKConnection;
//System.debug("con: " + con);
var cms = con.customizationSpecManager;
//System.debug("cms : " + cms);
var customSpecExists = cms.doesCustomizationSpecExist(specName);
//System.debug("isda: " + customSpecExists);

//CustSpec holen, wenn sie existiert
if (customSpecExists) {
     var customSpecItem = cms.getCustomizationSpec(specName);
    System.debug("got custSpecItem: " + customSpecItem);
    custspec = customSpecItem.spec;
    System.debug("contents custSpec: " + custspec);
    } else throw "customspec not found";

In my example: "SDKConnection" has to be an VCSDKConnection to the vCenter which holds the Specification, and "specName" is the name of the Spec (unfortunately, there is no kind of "ID" for that, so you only can find it by name)

"custspec" at the end holds the specification which can be used in the cloneVM-Action.

If you need a full example, write some answer here an I can upload an example-Workflow.

Cheers ,

Joerg

admin
Immortal
Immortal

I am working through a very similar task of attempting to clone a VM and I want to use a already existing custom template.  I would like to take you up on the offer of seeing a workflow you have already created to perform a similar task.  Please post it if you have one available.

Reply
0 Kudos
tschoergez
Leadership
Leadership

Hi!

sorry for the late answer, somehow I missed this during VMworld :smileycool:

If it's still useful, some scripting example how to get an existing customization spec:

var custspec = new VcCustomizationSpec();
var con = SDKConnection;
//System.debug("con: " + con);
var cms = con.customizationSpecManager;
//System.debug("cms : " + cms);
var customSpecExists = cms.doesCustomizationSpecExist(specName);
//System.debug("isda: " + customSpecExists);

//CustSpec holen, wenn sie existiert
if (customSpecExists) {
     var customSpecItem = cms.getCustomizationSpec(specName);
    System.debug("got custSpecItem: " + customSpecItem);
    custspec = customSpecItem.spec;
    System.debug("contents custSpec: " + custspec);
    } else throw "customspec not found";

and for the parameters a screenshot of the action...

1834001.png

In my case I just changed the IP-Address, rest was hardcoded in the custom spec in vCenter....

Regards,

Joerg

admin
Immortal
Immortal

How would you tie the action below to get the existing customization spec passed into a Clone VM workflow?  That Clone VM workflow seem so complicated for seemingly easy operation from the GUI?  Where would I pass in the existing customization spec in as an input?  Also does it still need be serialized as the out of the box clone with sysprep customziation seems to do?

Thanks,

Joe

Reply
0 Kudos
Hpang
Contributor
Contributor

Anyone ever figured this out?

Reply
0 Kudos
Todar
Contributor
Contributor

Here is what I did:

I create an action; with 3 inputs as follows:

specName                string                              Name of the customization Specification to look for             

SDKConnection        VC:SdkConnection           Vcenter Server to connect to

VMtocustomize        VC:VirtualMachine            Name of the VM to Customize

script in the action:

var custspec = new VcCustomizationSpec();

var con = SDKConnection;

var cms = con.customizationSpecManager;

var customSpecExists = cms.doesCustomizationSpecExist(specName);

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";

//let it sleep so it is ready

System.sleep(10*1000);

//Start the VM

VMtocustomize.powerOnVM_Task(null);

I created a workflow; added the built in  workflow "Clone Virtual Machine, no customization" and after that I added my action.

Works like a charm for me. Notice I added the powerOnVM at the bottom, the customization will not start until the VM is turned on. Wait about 5 min. and all is well.

I did try the code from above from Joerg to change the IP in the spec..;I could find no way to get that to work. I would love to though if someone could help?

meisterheister
Contributor
Contributor

Hi,

Thank you for sharing how to create the workflow. I used this to create my own workflow to easily create test machines.

In my particular case I did not specify any computer name in the customization spec because I want to let the user decide which name it should get. So, how can I get this parameter (computer name) and paste it into the customization workflow?

Many thanks in advance!

Reply
0 Kudos
GreenDotAdmin1
Contributor
Contributor

There is a typo in the code and that's probably why you're seeing an error.  The example shows the NIC settings map as custspec.nicSettingsMap[0] but it's not supposed to include an "s" in Settings. So it's supposed to be like this.

System.debug("Getting Old IP");
var oldIP = custspec.nicSettingMap[0].adapter.ip;
System.debug("Old IP: " + oldIP);

//Set new IP for this custom spec
var fixedIP = new VcCustomizationFixedIp();
fixedIP.ipAddress = ip;
System.debug("Fixed IP: " + fixedIP.ipAddress);

System.debug("Setting new ip address");
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 IP Address in custspec: " + custspec.nicSettingMap[0].adapter.ip.ipAddress);

return custspec;

Hope it helps.

Reply
0 Kudos