VMware Cloud Community
sean_gadson
Enthusiast
Enthusiast

Array of Objects

Hello,

I am trying to create a capacity report to email out every so often from vRA with vRO but I am having trouble creating a property array of property objects.  For some reason even though it iterates through the all of the reservations (7).  In the end it only prints out the last reservation name 7 times

resrevationProperties = new Properties {}

reservationCapacityInformation = []

for (var i = 0; i < reservations.length; i++) {

var reservStorages = reservations[i].getLink(vcacHost, "HostReservationToStorages");

reservationName = reservations[i].getProperty("HostReservationName");

var storage = reservStorages[0].getLink(vcacHost, "HostToStorage")[0];

var storagePath = storage.getProperty("StoragePath");

reservationCapacityInformation.push(resrevationProperties);

}

for each (var prop in reservationCapacityInformation){

System.log(prop.get("ReservationName"));

System.log(prop.get("StoragePath"))

}

output:

[2019-09-04 10:31:23.507] [I] Reservation Name of Last Reservation

[2019-09-04 10:31:23.508] [I] Storage path of Last Reservation

[2019-09-04 10:31:23.509] [I] Reservation Name of Last Reservation

[2019-09-04 10:31:23.510] [I] Storage path of Last Reservation

[2019-09-04 10:31:23.511] [I] Reservation Name of Last Reservation

[2019-09-04 10:31:23.512] [I] Storage path of Last Reservation

[2019-09-04 10:31:23.513] [I] Reservation Name of Last Reservation

[2019-09-04 10:31:23.515] [I] Storage path of Last Reservation

[2019-09-04 10:31:23.516] [I] Reservation Name of Last Reservation

[2019-09-04 10:31:23.518] [I] Storage path of Last Reservation

[2019-09-04 10:31:23.519] [I] Reservation Name of Last Reservation

[2019-09-04 10:31:23.521] [I] Storage path of Last Reservation

[2019-09-04 10:31:23.523] [I] Reservation Name of Last Reservation

[2019-09-04 10:31:23.524] [I] Storage path of Last Reservation

Reply
0 Kudos
1 Reply
eoinbyrne
Expert
Expert

Try this?

reservationCapacityInformation = [];

for (var i = 0; i < reservations.length; i++) {

    var reservStorages = reservations[i].getLink(vcacHost, "HostReservationToStorages");

    reservationName = reservations[i].getProperty("HostReservationName");

    var storage = reservStorages[0].getLink(vcacHost, "HostToStorage")[0];

    var storagePath = storage.getProperty("StoragePath");

   // create a new one each time...

    var resrevationProperties = new Properties();

    reservationProperies.put("ReservationName", reservationName);

    reservationProperties.put("StoragePath", storagePath);

    reservationCapacityInformation.push(resrevationProperties);

}

for each (var prop in reservationCapacityInformation){

    System.log(prop.get("ReservationName"));

    System.log(prop.get("StoragePath"))

}

Reply
0 Kudos