vRO action to get all reservation's network profile

var username = Server.getCurrentLdapUser().userPrincipalName;
System.log(username);
var resList = vCACCAFEEntitiesFinder.findReservations(vCACHost, "");
System.debug("Reservations found: " + resList.length);
var nets = [];
for (var i in resList) {
 var reservation = resList[i];
 var typeId = reservation.getReservationTypeId();

 if (typeId == "Infrastructure.Reservation.Virtual.vSphere") { //check only vSphere reservations
  try {
   var exData = reservation.getExtensionData();
   var netData = exData.get("reservationNetworks").getValue(); //convert to Array/Literals
   for (var j in netData) {
    var n = netData[j].getValue(); //get value of ComplexLiteral
    var networkPath = n.get("networkPath"); //get network path - vSphere portgroup
    var lbl = networkPath.getLabel();
    if (nets.indexOf(lbl) < 0 && lbl) { //check if already added
     nets.push(lbl);
    }
   }
  } catch (e) {
   System.error("Error parsing reservation extension data for its networks: " + e);
   //do nothing
  }
 }
}


function sortArray(a,b)
{
 var c = a.split("|")[2];
 var d = b.split("|")[2];
 return c-d;
}

nets = nets.sort(sortArray);
System.debug("Networks found: " + JSON.stringify(nets));
System.log(nets);
Post a Comment (0)
Previous Post Next Post