VMware {code} Community
shaggeeey
Contributor
Contributor
Jump to solution

How do I determine the age of a virtual machine?

I've seen some Powershell to go through all the events and find the creation event, but this method doesn't seem ideal, as I understand it can get confused by software version upgrades, and the events may not be retained depending on settings.  

I can get the creation time of the first root snapshot, e.g. vm.snapshot.rootSnapshotList[0].createTime.   This is quite useful, and coincides with creation dates for many machines, however some VMs don't have a root snapshot.

Can I do better?

Thanks!

PS:  I am using pyVmomi, however I don't think this is the problem, and can switch to another language if necessary.

0 Kudos
1 Solution

Accepted Solutions
stumpr
Virtuoso
Virtuoso
Jump to solution

Yes, if a DB maintenance job runs it'll clean up old events from the database.  So it's not really a PyVmomi or SDK issue, but just the fact the actual event is cleaned from the DB.

The disk creation time stamp isn't a bad idea, that's creative.  I guess the negative there is you won't be able to get who created the VM, just the creation time.

If you have control of your VM creation process, you can add some CustomValue tags in vSphere to the VM for the creation date.  I had a few customers who used a daily script or vCO workflow to get the VMCreated events, turn those into CustomValues (so they don't get pruned on a DB maintenance job) and that works well (since it's rare that you'll have VM events wiped in the 24 hr period of the script/workflow task).

Reuben Stump | http://www.virtuin.com | @ReubenStump

View solution in original post

0 Kudos
2 Replies
stumpr
Virtuoso
Virtuoso
Jump to solution

Yes, if a DB maintenance job runs it'll clean up old events from the database.  So it's not really a PyVmomi or SDK issue, but just the fact the actual event is cleaned from the DB.

The disk creation time stamp isn't a bad idea, that's creative.  I guess the negative there is you won't be able to get who created the VM, just the creation time.

If you have control of your VM creation process, you can add some CustomValue tags in vSphere to the VM for the creation date.  I had a few customers who used a daily script or vCO workflow to get the VMCreated events, turn those into CustomValues (so they don't get pruned on a DB maintenance job) and that works well (since it's rare that you'll have VM events wiped in the 24 hr period of the script/workflow task).

Reuben Stump | http://www.virtuin.com | @ReubenStump
0 Kudos
shaggeeey
Contributor
Contributor
Jump to solution

Not sure about creativity, more of a brute-force approach:  I grepped the pyVmomi sources and docs for 'dateTime', and printed all of them to see if they made sense!

Although it's not exactly an answer, I marked it as such, because it's a good strategy.  Thanks.

0 Kudos