Check state of resource before performing operation

,

Before performing operation such as powering on/off ESX VM (or any resource) check underlying state of VM and only carry out operation if state is expected. This is intended to stop user performing wrong operation, for example:

1/ I shutdown the VM via OS, e.g. shutdown -h now
2/ State remained as “Running”
3/ I was then able to select “Stop Server” from Actions
4/ State changed to “stopping” and all Actions became available, e…g both start / stop enabled.

There are other example where behavior is exhibited, for example VM is deleted from Cloud underneath Morpheus. When this happens, its still possible to power it on/off inside Morpheus. Selecting one of these options should immediately change state to Unknown and disable all Action options.

When writing up this I understand this to be a niche case as a cloud refresh operation should update status of VM (resource). However cloud refresh typically only takes place every 5 minutes, so there is a window of opportunity.