Highlighted
Contributor
Contributor

unable to create VM via vcloud API

Jump to solution

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 &lt;null&gt;."

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?

1 Solution

Accepted Solutions
Highlighted
Contributor
Contributor

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...

View solution in original post

2 Replies
Highlighted
Contributor
Contributor

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

0 Kudos
Highlighted
Contributor
Contributor

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...

View solution in original post