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
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
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.
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
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.
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.
Hi,
This is a bug with the .NET SDK 1.5
Regards,
Rajesh Kamal.
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
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.
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;
}