Why No DatacenterRemovedEvent? A Deep Dive into vSphere Event Model
Last week I discussed how to get event type with vSphere API, followed by a comment asking why there is no DatacenterRemovedEvent? Very good question and almost got me there.
vSphere API has a comprehensive object model for event. In version 4.1, we have 474 different types of events representing different things happened in vSphere. When a managed entity is removed, there are normally events associated, for example, VmDeployedEvent, HostRemovedEvent, ClusterDestroyedEvent, ResourcePoolDestroyedEvent, DatastoreDestroyedEvent, DatastoreRemovedOnHostEvent, etc. It’s natural to expect DatacenterRemovedEvent. But you don’t find one.
Lost VMs or Containers? Too Many Consoles? Too Slow GUI? Time to learn how to "Google" and manage your VMware and clouds in a fast and secure HTML5 App.
It’s not only Datacenter which does have DatacenterCreatedEvent and DatacenterRenamedEvent. For Folder type, you find nothing other than VmBeingClonedNoFolderEvent which is not related to lifecycle of Folder at all.
Why are these events missing?
Instead of thinking, let’s try something. So I tried to remove a datacenter from vCenter and got an event there as shown below. A little surprise to me, the event is typed as TaskEvent which is a direct subtype of Event, and has one additional property called info (type TaskInfo).
Although vSphere has a big number of event types, it cannot capture all the things happened in the system. For one thing, vSphere 4.1 has 491 methods. If we create a type for every change as result of a method call, 474 event types are not enough. Of course, for some method calls there could be more than one thing happens; for others nothing. Luckily we have TaskEvent to capture all of them!
The upside of one for all is that you have one type to deal with. The downside is that the type itself doesn’t tell you much. So you want more concrete types representing the nature of the things happened without looking into the details of the object. Therefore vSphere includes many event types.
At the same time, you don’t want to go too far with all the things, important or trivia, represented by distinct types. The trick is really to get a balance point in between. The criteria are of course
1. Is this what people really care about? The more people care about, the more likely it should have a corresponding event type.
2. Is this something people use often? The more frequently it happens, the more likely it should have corresponding event type.
With above discussion in mind, you can understand why you cannot find some event types. The importance and frequency are of course subjective. You can always make a case that we should have some event types.
When you can find the concrete types, that is great; if not, look for the TaskEvent type. The is the key take away from this article.