VMware {code} Community
aturli
Contributor
Contributor

How to list vms inside a vAppTemplate

Hi,

I'd like to know what API I can use to list all the vms inside a vAppTemplate.

Thanks,

Andrea

0 Kudos
10 Replies
ttonchev
VMware Employee
VMware Employee

Hi Andrea,

You can use the Query Service described in Chapter 9 of the vCloud API Programming Guide (http://www.vmware.com/pdf/vcd_15_api_guide.pdf).

Specifically for VMs you can use the 'vm' query if you are a tenant user or the 'adminVM' query if you are a system administrator. For example:

  GET https://vcloud.example.com/api/query?type=vm

or

  GET https://vcloud.example.com/api/query?type=adminVM    (for sys admins)

will return the list of all VMs to which the user has access. If you are interested in the VMs in the vAppTemplate that has URI 'https://vcloud.example.com/api/vAppTemplate/vappTemplate-4252bcdd-24df-4988-88d5-02ceb317a46e' you can filter the results in the following way:

  GET https://vcloud.example.com/api/query?type=adminVM&filter=container==https://vcloud.example.com/api/vAppTemplate/vappTemplate-4252bcdd-24df-4988-88d5-02ceb317a46e

or just

  GET https://vcloud.example.com/api/query?type=adminVM&filter=container==4252bcdd-24df-4988-88d5-02ceb317a46e

You can also apply various other filters and query options (e.g. to choose the returned information). Please see the documentation mentioned above for details.

I hope this addresses your question.

Best regards,

- Teodor Tonchev

0 Kudos
Todor_Todorov
Hot Shot
Hot Shot

Hi Andrea,

If you have already retrieved a <VAppTemplate> object from the REST API, you can look at the <Children> element inside it - it's a list of <Vm> elements each representing a VM in the vApp template.

If you're using the SDK and you have obtained a VappTemplate object you can call the following method to get this list:

public java.util.List<VappTemplate> getChildren()

Regards,

Todor Todorov

0 Kudos
aturli
Contributor
Contributor

Thanks Todor Todorov,

If you're using the SDK and you have obtained a VappTemplate object you can call the following method to get this list:

public java.util.List<VappTemplate> getChildren()

Using getChildren() I will get a list of VappTemplate but how can I access to their vms?

Andrea

0 Kudos
cfor
Expert
Expert

The children vapps returned in the SDK are VM's.  It is a little misleading.  (If you look at the .IsVM property it will be set to true)

ChrisF (VCP4, VCP5, VCP-Cloud) - If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
stu42j
Contributor
Contributor

Why do VMs inside a Template not have all of the same elements as VMs inside a vApp?  For example, OperatingSystemSection is missing.

0 Kudos
grkvlt
Contributor
Contributor

Just checking, the Vm elements containing the children of a VAppTemplates are definitelyVAppTemplates, not Vms? And a VApp built from that template would then have children that are Vms?

0 Kudos
stu42j
Contributor
Contributor

The schema docs say that the Children of a vAppTemplate contains vAppTemplates.  In reality, of course, it actually contains VMs.

0 Kudos
grkvlt
Contributor
Contributor

So, the schema documentation is wrong? Will this be fixed in the next 1.5.x?

0 Kudos
stu42j
Contributor
Contributor

Based on the behavior of the server, I would say the schema is wrong, not the documentation. Looks like this is not fixed in 5.1.

http://pubs.vmware.com/vcd-51/topic/com.vmware.vcloud.api.reference.doc_51/doc/types/VAppTemplateChi...

0 Kudos
fsivignon
Contributor
Contributor

Hello,

I'm also need to list of VMs within a vApp Template (I also do it easilly from a vApp).

So, I retrieved all children from the vappTemplate. And if a child is a VM (IsVm() gives me true), I'm using the Reference.id to try to get the corresponding VM object (the id looks like "urn:vcloud:vm:f1b8f5b2-6167-4f48-9ea1-58699a4a21c5" so it seems to be a valid VM).

But, when I call the static method VM.GetVMById(), by giving the previous id, I've got the error "There is an error in XML document (2, 2)".

Not a big deal for me, as I only need the name of those VMs, retrieved via the reference property; so a call to GetVMById() is not really needed in this case. I assume it is due to the fact that there is no possible action on a VM referenced inside a vApp Template ? So it does not make sense to retrieve a reference to a VM object ?

0 Kudos