Skip to content

Commit

Permalink
Fixed return of inaccessible vms
Browse files Browse the repository at this point in the history
  • Loading branch information
psav committed May 26, 2016
1 parent 55e2052 commit 7bcbb17
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mgmtsystem/virtualcenter.py
Expand Up @@ -228,7 +228,7 @@ def get_ip_address(self, vm_name, timeout=600):
ip_address = None
return ip_address

def _get_list_vms(self, get_template=False):
def _get_list_vms(self, get_template=False, inaccessible=False):
""" Obtains a list of all VMs on the system.
Optional flag to obtain template names too.
Expand All @@ -241,7 +241,8 @@ def _get_list_vms(self, get_template=False):
# so we skip the network overhead of returning full managed objects
property_spec = self.api.create('PropertySpec')
property_spec.all = False
property_spec.pathSet = ['name', 'config.template']
property_spec.pathSet = ['name', 'config.template', 'config.uuid',
'runtime.connectionState']
property_spec.type = 'VirtualMachine'
pfs = self.api.get_search_filter_spec(self.api.si.content.rootFolder, property_spec)
object_contents = self.api.si.content.propertyCollector.RetrieveProperties(specSet=[pfs])
Expand All @@ -257,9 +258,11 @@ def _get_list_vms(self, get_template=False):
# object already "knows" the answer in its cached object
# content. So we just pull the value straight out of the cache.
vm_props = {p.name: p.val for p in object_content.propSet}

if vm_props.get('config.template') == get_template:
obj_list.append(vm_props['name'])
if (vm_props.get('runtime.connectionState') == "inaccessible"
and inaccessible) or vm_props.get(
'runtime.connectionState') != "inaccessible":
obj_list.append(vm_props['name'])
return obj_list

def all_vms(self):
Expand Down Expand Up @@ -372,8 +375,8 @@ def restart_vm(self, vm_name):
self.logger.info(" Restarting vSphere VM %s" % vm_name)
return self.stop_vm(vm_name) and self.start_vm(vm_name)

def list_vm(self):
return self._get_list_vms()
def list_vm(self, inaccessible=False):
return self._get_list_vms(inaccessible=inaccessible)

def list_template(self):
return self._get_list_vms(get_template=True)
Expand Down

0 comments on commit 7bcbb17

Please sign in to comment.