Created
May 10, 2018 17:52
-
-
Save asvignesh/fd97f4cbc41ac55e5b289c3424c0f09a to your computer and use it in GitHub Desktop.
Get vSphere Virtual Machine creation time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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