VMware {code} Community
imex1
Contributor
Contributor
Jump to solution

How to use API to perform "Power On and Force Recustomization" in 1.5?

Using VMWare vCloud Director, when the VM is powered off, I have the menu "Power On and Force Recustomization" to power the machine on and do some recustomization jobs such as reset the Administrator's password.

However, I cannot perform this operation using the API. The vm/vapp.PowerOn() does not have parameter. The vm/vapp.Deploy(true, 0, true) can (re)deploy the vm/vapp and the machine is on. But the recustomization never executes.

My code can successfully update the "Guest OS Customization" section. I can see it in vCloud Director. And then if I manually "Power On and Force Recustomization", the machine will be powered on and the password get reset. But if I use the codes above, none of them works. So I conclude that the problem happens in how to send the "Power On and Force Recustomization" instruction using API.

Any help will be apprecitated.

Ref:

http://communities.vmware.com/message/1691773

http://communities.vmware.com/message/1837194

http://communities.vmware.com/message/1805142

http://communities.vmware.com/message/1844513

0 Kudos
1 Solution

Accepted Solutions
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

For performing the PowerOn + ForceCustomization option on the UI using the API.

Perform the same Deploy operation on the VM.

     Ex: POST - api/vApp/vm-uuid/action/deploy

           POST XML

                      <ns6:DeployVAppParams xmlns="http://www.vmware.com/vcloud/versions" xmlns:ns6="http://www.vmware.com/vcloud/v1.5" powerOn="true" forceCustomization="true" deploymentLeaseSeconds="10000"/>

Using Java SDK - Use the VM->deploy();

           Make sure the guest customization is enabled on the VM.

           Make sure that the deploy params - forceCustomization and powerOn are set to true;

Regards,

Rajesh Kamal.

View solution in original post

0 Kudos
6 Replies
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

For performing the PowerOn + ForceCustomization option on the UI using the API.

Perform the same Deploy operation on the VM.

     Ex: POST - api/vApp/vm-uuid/action/deploy

           POST XML

                      <ns6:DeployVAppParams xmlns="http://www.vmware.com/vcloud/versions" xmlns:ns6="http://www.vmware.com/vcloud/v1.5" powerOn="true" forceCustomization="true" deploymentLeaseSeconds="10000"/>

Using Java SDK - Use the VM->deploy();

           Make sure the guest customization is enabled on the VM.

           Make sure that the deploy params - forceCustomization and powerOn are set to true;

Regards,

Rajesh Kamal.

0 Kudos
imex1
Contributor
Contributor
Jump to solution

It works if I do the REST. Thank you rkamal.

The bug in API for .NET I figured out is:

DeployVAppParamsType type = new DeployVAppParamsType

{

powerOn = true,

deploymentLeaseSeconds = 0,

forceCustomization = true

};

string content = SerializationUtil.SerializeObject(type, "com.vmware.vcloud.api.rest.schema_v1_5");

The SerializationUtil.SerializeObject function does not serialize the three properties into the content. So the parameters of vm/vapp.Deploy function will not be posted to the server. I guess than the server will then use the default value like vm/vapp.Deploy(true, 0, false) regardless what the forceRecustomization value I set. By the way, even I send Deploy(false,...) the machine is still powered on.

0 Kudos
rkamal
VMware Employee
VMware Employee
Jump to solution

Hi,

This is a bug with the .NET SDK 1.5

Regards,

Rajesh Kamal.

0 Kudos
Prasadv20111014
Contributor
Contributor
Jump to solution

Writing our own REST call the only way or there is any work around for this issue? Can we enforce guest customization in any otherway without manual intervention?

Thank you

Prasad

0 Kudos
balajia
Contributor
Contributor
Jump to solution

Hi,

Can you give me a sample C# code to accomplish this through REST way. I seriously needed it since i had to programatically trigger "poweron with force recustomization" as the Deploy() parameter ForceCustomization has no effect.

Thanks.

0 Kudos
balajia
Contributor
Contributor
Jump to solution

Sometimes self help is the best help. After several retries and reading i managed to get this working for VM "Poweron with Force recustomization"....

string url = vm.Resource.href + @"/action/deploy";

string body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1.5\" powerOn=" + "\"" + "true" + "\"" + " deploymentLeaseSeconds=" + "\"" + orgLeaseSettings.DeploymentLeaseSeconds.ToString() + "\"" + " forceCustomization=" + "\"" + ForceCustomization.ToString().ToLower() + "\"" + "/>";

string contentType = "application/vnd.vmware.vcloud.deployVAppParams+xml";

Response rp = com.vmware.vcloud.sdk.utility.RestUtil.Post(vCloudSession, url, body, contentType, "UTF-8");

XmlDocument doc = new XmlDocument();

try

{

doc.LoadXml(rp.ResponseXml);

XmlNode task_node = null;

foreach (XmlNode temp in doc.ChildNodes)

{

if (temp.Name == "Task")

{

task_node = temp;

break;

}

}

if (task_node != null)

{

string task_id = task_node.Attributes["id"].Value;

Task t1 = Task.GetTaskById(vCloudSession, task_id);

t1.WaitForTask(timeout);

}

}

catch (Exception e1)

{

retval =

false;

failure_reason =

"RestUtil returned invalid POST response.";

return retval;

}

0 Kudos