Skip to content

Instantly share code, notes, and snippets.

@asvignesh
Created May 10, 2018 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asvignesh/fd97f4cbc41ac55e5b289c3424c0f09a to your computer and use it in GitHub Desktop.
Save asvignesh/fd97f4cbc41ac55e5b289c3424c0f09a to your computer and use it in GitHub Desktop.
Get vSphere Virtual Machine creation time
public Timestamp getCreatedDate() throws RemoteException {
final EventFilterSpec eventFilterSpec = new EventFilterSpec();
eventFilterSpec.setEventTypeId(new String[]{"VmCreatedEvent", "VmBeingDeployedEvent", "VmRegisteredEvent", "VmClonedEvent"});
EventFilterSpecByEntity entity = new EventFilterSpecByEntity();
entity.setEntity(virtualMachine.getMOR());
EventFilterSpecRecursionOption recOption = EventFilterSpecRecursionOption.self;
entity.setRecursion(recOption);
eventFilterSpec.setEntity(entity);
final Event[] events = serviceInstance.getEventManager().queryEvents(eventFilterSpec);
Calendar calendar = null;
if (events != null) {
for (Event event : events) {
// event.fullFormattedMessage.contains("Created virtual machine");
calendar = event.createdTime;
if (calendar == null) {
continue;
} else {
return calendar.getTimeInMillis();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment