Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.