Treyvon
Contributor
Contributor

vRA Days Active VM Property

Hi guys, currently I'm trying to pull a property for the amount of days a machine has been active through an API call.  At the moment I was using leaseForDisplay.amount, but then I realized that the days weren't accurate, and were just showing the number of days that the lease was for. So it always showed 90 days no matter how long a machine had been provisioned. So I was wondering if there was a different property I could pull instead that would show the amount of days a machine has been active, or if I would have to use the expiration date property, and do math to set how many days the machine would have left before expiration. Any help is appreciated! Thanks!

Labels (3)
0 Kudos
1 Reply
xian_
Expert
Expert

var vcacHost = Server.findAllForType("VCAC:VCACHost")[0];
var props = new Properties({VirtualMachineName: "myvm"});
var entity = vCACEntityManager.readModelEntitiesByCustomFilter(vcacHost.id, "ManagementModelEntities.svc", "VirtualMachines", props, null)[0];
var created = entity.getProperty("VMCreationDate");
var now = new Date();
System.log("Active for " + (now.getTime() - created.getTime())/1000/60/60/24 + " days.");
0 Kudos