vmware / pyvmomi

VMware vSphere API Python Bindings
Apache License 2.0
2.2k stars 767 forks source link

Getting information about system #275

Open alans09 opened 9 years ago

alans09 commented 9 years ago

Hi, I'm facing some problems again. I have something like this (part of bigger class):

self.template = self._find_vm(self.si, name)  [instance of vim.VirtualMachine]
timeout = 60
l_timeout = 0
while l_timeout <= 0:
    guest_operations = self.template.guest.guestOperationsReady
    vmtools = self.template.guestHeartbeatStatus 
    if not guest_operations and vmtools == 'red':
        return True
    else:
        time.sleep(2)
return False

Problem is that self.template.guest.guestOperationsReady and guestHeartbeatStatus is not updated 'realtime'. I can see that machine is turned off (or restarting) and guestHeartbeatStatus is still green (also guestOperationsReady returns True) Sometimes it takes 1second to return valid values, sometimes that values are bad even after 10sec

Is there any 'cache' that is responsible for this? Maybe if you take vim.VirtualMachine instance all properties are queried in a single request and cached continuously?

So far I can find only one way how to reload this properties. This way is to 'reload' full vim.VirtualMachine object and than it looks ok.

Question is if it this is a right way to do it.

prziborowski commented 8 years ago

I am not aware of a cache (perhaps something is happening in pyVmomi, but I wouldn't expect it to cache without an update mechanism). Something you could compare against (to rule out pyVmomi vs vSphere misbehaving) is to look at https:///mob/?id=&doPath=guest and see if it is updating correctly or not.

If it is, then I'd suggest using the PropertyCollector against ['guest.guestOperationsReady', 'guestHeartbeatStatus'] and you could remove the sleeping part (and could timeout after 60 seconds).

I believe the guest* values are provided to the server is a periodic update, so it might be possible they are not always real time values (this is speculation).