Hi,
I have an Ubuntu template in a public catalog and I was not able to instantiate an isolated VM from it via vCloud API.
Obs: I am testing against a vCloud 9.7 instance.
1- instantiateVmFromTemplate API
My first attempt was to call the instantiateVmFromTemplate API with very simple XML like this:
POST https://vcd01/api/vdc/c78e7423-ef80-4d50-bbea-3d58cf188ab9/action/instantiateVmFromTemplate
'Accept: application/*+xml;version=32.0'
'Content-Type: application/vnd.vmware.vcloud.instantiateVmTemplateParams+xml'
<InstantiateVmTemplateParams xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" name="myUbuntu02">
<SourcedVmTemplateItem>
<Source href="https://vcd01/api/vAppTemplate/vappTemplate-f835057c-2138-436f-9f34-3e3008d82030" id="urn:vcloud:vapptemplate:f835057c-2138-436f-9f34-3e3008d82030"/>
</SourcedVmTemplateItem>
</InstantiateVmTemplateParams>
The response was HTTP Status 400 and response XML with:
majorErrorCode="400"
message="Wrong resource type null, expected application/vnd.vmware.vcloud.vm+xml"
minorErrorCode="BAD_REQUEST"
2- createVM API
So I tried the createVM API again with very simple XML payload like this:
POST https://vcd01/api/vdc/c78e7423-ef80-4d50-bbea-3d58cf188ab9/action/createVm
'Accept: application/*+xml;version=32.0'
'Content-Type: application/vnd.vmware.vcloud.CreateVmParams+xml'
<CreateVmParams xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:environment_1="http://schemas.dmtf.org/ovf/environment/1" name="myUbuntu01">
<Description>created by cloud-server</Description>
<CreateVm name="myUbuntu01"/>
</CreateVmParams>
The response was HTTP Status 400 and response XML with:
majorErrorCode="400"
message="[ ec1f6a9e-c519-4ae5-8d6b-ad289282e1ad ] The value for Number of CPUs must be above zero. You provided <null>."
minorErrorCode="BAD_REQUEST"
The odd part of this response is that I could not see a request parameter to fill in this information.
3- instantiateVAppTemplate API
Than I tried instantiateVAppTemplate API with success:
POST https://vcd01/api/vdc/c78e7423-ef80-4d50-bbea-3d58cf188ab9/action/instantiateVAppTemplate
'Accept: application/*+xml;version=32.0'
'Content-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml'
<vcloud:InstantiateVAppTemplateParams xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:vcloud="http://www.vmware.com/vcloud/v1.5"
deploy="true" name="apiTest" powerOn="false">
<vcloud:Description>my last test</vcloud:Description>
<vcloud:Source href="https://vcd01/api/vAppTemplate/vappTemplate-f835057c-2138-436f-9f34-3e3008d82030" id="urn:vcloud:vapptemplate:f835057c-2138-436f-9f34-3e3008d82030"/>
</vcloud:InstantiateVAppTemplateParams>
For this one I had a HTTP Status OK and the vAPP+VM were created.
Conclusion
As I need to reproduce via API the vCloud web interface behaviour where we can launch a new isolated VM from an existing template (Virtual Machines -> New VM -> from template models -> select template), can anyone see what I am doing wrong?
Or it looks like a vCloud API application bug?
Hey RandellHynes,
I had to go this way:
1. Create a isolated VM, install/configure OS and change it to a VAPP template.
2. Add the template to a catalog.
3. Just call the API POST /vdc/{id}/action/instantiateVAppTemplate with XML body like this:
<InstantiateVAppTemplateParams xmlns=
"http://www.vmware.com/vcloud/v1.5"
xmlns:ovf=
"http://schemas.dmtf.org/ovf/envelope/1"
name=
"newVM"
>
<Description>a new VM from template<
/Description
>
<Source href=
"https://<vcd_url>/api/vAppTemplate/vappTemplate_ID"
id
=
"urn:vcloud:vapptemplate:ID"
/>
<AllEULAsAccepted>
true
<
/AllEULAsAccepted
>
<
/InstantiateVAppTemplateParams
>
And you should see the isolated VM 'newVM' created...
Did you resolve this issue? I ran into the same deal.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Error
xmlns="http://www.vmware.com/vcloud/v1.5"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:common="http://schemas.dmtf.org/wbem/wscim/1/common"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:vmw="http://www.vmware.com/schema/ovf"
xmlns:ovfenv="http://schemas.dmtf.org/ovf/environment/1"
xmlns:vmext="http://www.vmware.com/vcloud/extension/v1.5"
xmlns:ns9="http://www.vmware.com/vcloud/versions" majorErrorCode="400" message="Bad request" minorErrorCode="BAD_REQUEST"/>
Hey RandellHynes,
I had to go this way:
1. Create a isolated VM, install/configure OS and change it to a VAPP template.
2. Add the template to a catalog.
3. Just call the API POST /vdc/{id}/action/instantiateVAppTemplate with XML body like this:
<InstantiateVAppTemplateParams xmlns=
"http://www.vmware.com/vcloud/v1.5"
xmlns:ovf=
"http://schemas.dmtf.org/ovf/envelope/1"
name=
"newVM"
>
<Description>a new VM from template<
/Description
>
<Source href=
"https://<vcd_url>/api/vAppTemplate/vappTemplate_ID"
id
=
"urn:vcloud:vapptemplate:ID"
/>
<AllEULAsAccepted>
true
<
/AllEULAsAccepted
>
<
/InstantiateVAppTemplateParams
>
And you should see the isolated VM 'newVM' created...
It seems that i found more suitable solution.
You just need to set source's type. It this case you won't have a bunch of visible vapp per every created machine.
<InstantiateVmTemplateParams xmlns="http://www.vmware.com/vcloud/v1.5" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" name="NewVMName">
<SourcedVmTemplateItem>
<Source xmlns="http://www.vmware.com/vcloud/v1.5" id="urn:vcloud:vm:5fe44edb-110a-470c-9fed-bcd39509ebf3" href="https://somecloud/api/vAppTemplate/vm-5fe44edb-110a-470c-9fed-bcd39509ebf3" type="application/vnd.vmware.vcloud.vm+xml"/>
</SourcedVmTemplateItem>
<AllEULAsAccepted>true</AllEULAsAccepted>
</InstantiateVmTemplateParams>
Thanks. The above solution works. But when I have to create a new VM from a template in some existing vApp what should be done.
The above solution creates a VM in new vAPP.
I'm following below documentation to create VM but again this is to create a custom VM(where will be the template/OS information added), Also not working.
Online Documentation - vCloud Director API Programming Guide - VMware {code}
Hi.
You need to use the request https://vcloud.example.com/api/vApp/vapp-33/action/recomposeVApp.
What version of vCloud do you have?
Thanks @Macleud ,
I am using recomposeVApp now and it is working.
Below is the xml code for working API.