VMware {code} Community
ssandberg
Contributor
Contributor

Simple C# app to retrieve all hosts and their VMs

I am writing a simple app in C# to request all the hosts and their vms from Virtual Center 2.

It currently fetches all the hosts like this

pspec.type = "HostSystem";

pspec.pathSet = new string[] { "summary", "vm" };

I then have an array of morefs to all the vms hosted on each host.

All I really want from each host is contained in the summary. All I want from each vm is their ipaddress.

2 Questions

1. Is there a more efficient way to obtain this info? I.E. get all the hosts and vms (with ipaddresses) in a single retrieve operation.

2. Given the vms moref how do I request its GuestInfo (ipaddress)?

0 Kudos
1 Reply
admin
Immortal
Immortal

Try using the following PropertySpec to retrieve GuestInfo of VMs

PropertySpec specVm = new PropertySpec();

specVm.type = "VirtualMachine";

specVm.all = false;

specVm.pathSet = new String[5];

int index = 0;

specVm.pathSet[index++] = "parent";

specVm.pathSet[index++] = "name";

specVm.pathSet[index++] = "summary.config.template";

specVm.pathSet[index++] = "summary.runtime.powerState";

specVm.pathSet[index++] = "summary.guest.ipAddress";

0 Kudos