VMware Cloud Community
rami79
Contributor
Contributor

List managed machines per resource

Hi

I'm trying to write a script that would automate moving hundreds of VMs from one reservation to another.  I used PowerShell and CloudClient to do the actual move but now I'm trying to figure out how to get a list of VMs that belong to the old reservation. Since PowervRA is not supported by vRA 7.4 and the export button within the UI disappeared in version 7.4, is there another way to export that list? Does anyone know if it can be done using vRO or CloudClient?

Thank you,

Reply
0 Kudos
5 Replies
daphnissov
Immortal
Immortal

You can most certainly do it via vRO, but I don't have the custom code needed to do so.

Reply
0 Kudos
eoinbyrne
Expert
Expert

Check here for how this hangs together - Working with vCloud Automation Center IaaS entities

There's a Schema diagram there which you can examine but the crucial part you want is here

pastedImage_1.png

The IaaS HostReservation entity keeps a link to the VirtualMachines which belong to it

You can retrieve them from the vRA IaaS plugin like this

pastedImage_2.png

Once you have them in vRO you can

- print the details in CSV format in the log stream

- Write the CSV to a ResourceElement

- etc

HTH

Reply
0 Kudos
eoinbyrne
Expert
Expert

Slight correction, the objects returned will be vCAC:Entity but you can the properties for a vCAC VM from those like this

pastedImage_0.png

Once you've got the properties for each VM you can access values for the CSV like this

var hostname = vmProperties.get("Hostname");

var ipAddress = vmProperties.get("VirtualMachine.Network0.Address");

etc.

Check the vRA Extensibilty or Custom Properties guides to details on the values you can retrieve here

Reply
0 Kudos
rami79
Contributor
Contributor

Oh wow this is awesome ... thank you very much eoinbyrne.  I will try it out when I get back into the office.

I knew it could be done in vRO I just wasn't able to figure out where to start, I still have a lot to learn about vRO .... this is great thanks. 

Reply
0 Kudos
rami79
Contributor
Contributor

This is awesome I finally understand how the vCAC entities works .... yayyy!!!

Here's my final code in case someone else is interested.

var modelName = "ManagementModelEntities.svc";

var entitySetName = "HostReservations";

var filter = {'HostReservationName':reservation};  //filters for a specific reservationName

var reservationEntities = vCACEntityManager.readModelEntitiesByCustomFilter(vCACHost.id , modelName, entitySetName, filter, null);

for each (var reservationEntity in reservationEntities){

var vmReservationEntity = reservationEntity.getLink (vCACHost, "VirtualMachines");

if (vmReservationEntity != null){

for each (var vmName in vmReservationEntity) {

System.log (vmName.getProperty("VirtualMachineName"));

}

}

}

Thanks again guys for all the help.

Reply
0 Kudos