VMware {code} Community
eldhom
Contributor
Contributor

vSphere Java SDK - VM.list() is not listing templates

I have the following code to list VMs by name. The list method is not returning any templates, but only VMs. From the documentation, I guess, it's supposed to return both VMs and templates. Any help is appreciated. 

Builder searchSpec = new Builder();
searchSpec.setNames(Collections.singleton('template01'))
List<VMTypes.Summary> vms = client.vmService.list(searchSpec.build())

if (vms.size() == 0) {
println "Unable to find template"
}

 

But, getting template details using the ID of the template is working as expected.

VMTypes.Info info = client.vmService.get("vm-123") //vm-123 is the id of template "template01"

 

0 Kudos
1 Reply
doskiran
Enthusiast
Enthusiast

Data Object - VirtualMachineConfigInfo(vim.vm.ConfigInfo)
template - xsd:boolean - Flag indicating whether or not a virtual machine is a template.

Sample code using VIJava API:
---------------------------------------

ManagedEntity[] meArr = new InventoryNavigator(si.getRootFolder()).searchManagedEntities("VirtualMachine");
for (ManagedEntity me : meArr) {
	VirtualMachine vm = (VirtualMachine) me;
	System.out.println("VM Name::" + vm.getName()+" ,IsTemplate(config.template)::"+vm.getConfig().isTemplate());
}


Otherwise, Get All VirtualMachine objects along with the required properties using retrieveProperties() method of the PropertyCollector object.

0 Kudos