VMware {code} Community
hanish
Contributor
Contributor
Jump to solution

Retrieve list of hosts connected to vCenter

I'm creating an administrator extension, which is not associated with any context object. I want to show all the hosts and VMs running on those hosts as a tree. How can I retrieve this information using DAM?

1 Solution

Accepted Solutions
laurentsd
VMware Employee
VMware Employee
Jump to solution

Or you should be able to do something like this to retrieve a model for the list of vms in a host.

[Model(type="HostSystem")]

public class VmData extends DataObject {

   [Model(relation="vm as VirtualMachine",

         nestedModel="com.vmware.samples.viewspropertiesui.model.VmDataItem")]

   [ArrayElementType("com.vmware.samples.viewspropertiesui.model.VmDataItem")]

   public var vms:Array /*VmDataItem*/;

...

}

View solution in original post

8 Replies
vaibhav87
Enthusiast
Enthusiast
Jump to solution

Hi hanish,

  Yes it is possible to show all the hosts and VMs running on those hosts as a tree using dam. The only think which you need to do is write you own PropertyCollector.

  For samples browse vsphere-client-sdk\samples\vsphereviews here you will get all the required information to build your own propertyCollector.

0 Kudos
hanish
Contributor
Contributor
Jump to solution

Thanks Vaibhav for the response. I want to display all the hosts and VMs in a new view. It's not associated with a contectObject. So why do I have to write a property collector?

0 Kudos
laurentsd
VMware Employee
VMware Employee
Jump to solution

To use DAM to retrieve a list of objects you need to have a root object reference and a property path according to the vSphere API (vSphere Management SDK)  I don't think it's possible to retrieve all hosts and VMs with simple calls.  Your best option is to write a simple Java service that does everything you need on the Java side with the same Management SDK.

0 Kudos
vaibhav87
Enthusiast
Enthusiast
Jump to solution

Hi hanish,

     it is not compulsory  to pass context object for data collection.

     Check this example vSphere Documentation Center


0 Kudos
hanish
Contributor
Contributor
Jump to solution

I'm able to retrieve list of host using 'DataByConstraintRequest'. The model I'm using is

[Model]

    public class HostSystemInfo extends DataObject {

[Model(property="name")]
public var hsName:String;
[Model(property="vm")]
public var vms:Array;

    }

But the problem is  'vms' array contains elements of type ServerObjectRef . Is it possible to get actual VM names or use my custom Model?

The documentation specifies about fetching data of multi-hop relationship ([Model(relation=”runtime.host,cluster”, property=”name”)]).

Will something of this sort would be useful?

0 Kudos
laurentsd
VMware Employee
VMware Employee
Jump to solution

See this sample for building more complex DAM queries to retrieve various vm properties for all vms of a host:

samples/vsphereviews/views-properties-ui/swf/src/main/flex/com/vmware/samples/viewspropertiesui/views/HostSampleMonitorViewMediator.as

0 Kudos
laurentsd
VMware Employee
VMware Employee
Jump to solution

Or you should be able to do something like this to retrieve a model for the list of vms in a host.

[Model(type="HostSystem")]

public class VmData extends DataObject {

   [Model(relation="vm as VirtualMachine",

         nestedModel="com.vmware.samples.viewspropertiesui.model.VmDataItem")]

   [ArrayElementType("com.vmware.samples.viewspropertiesui.model.VmDataItem")]

   public var vms:Array /*VmDataItem*/;

...

}

hanish
Contributor
Contributor
Jump to solution

Thanks for the pointer. What I missed was the `nestedModel` property.

Thanks again!

0 Kudos