Skip to content

Commit

Permalink
Search for HostSystem objects only by traversing the properties and d…
Browse files Browse the repository at this point in the history
…on't call get_hosts() method
  • Loading branch information
dnaeon committed Sep 5, 2013
1 parent 123772e commit ce8da44
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/vmpoller/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,35 +429,31 @@ def get_host_property(self, msg):

syslog.syslog('[%s] Retrieving %s for host %s' % (self.vcenter, msg['property'], msg['name']))

# Find the host's Managed Object Reference (MOR)
mor = [x for x, host in self.viserver.get_hosts().items() if host == msg['name']]

# Do we have a match?
if not mor:
return "Unable to find the requested host"
else:
mor = mor.pop()

# Get the properties
# Get the properties for all registered hosts
try:
results = self.viserver._retrieve_properties_traversal(property_names=property_names,
from_node=mor,
obj_type=MORTypes.HostSystem).pop()
obj_type=MORTypes.HostSystem)
except Exception as e:
return "Cannot get property for host %s: %s" % (msg["name"], e)

# Do we have something to return?
if not results:
return "Did not find property %s for host %s" % (msg["property"], msg["name"])

# Get the property value
val = [x.Val for x in results.PropSet if x.Name == msg['property']]

if not val:
return "Cannot find the requested property value"
# Find the host we are looking for
for item in results:
props = [(p.Name, p.Val) for p in item.PropSet]
d = dict(props)

# Break if we have a match
if d["name"] == msg["name"]:
break
else:
val = val.pop()
return "Unable to find host %s" % msg["name"]

# Get the property value
val = d[msg["property"]] if d.get(msg["property"]) else 0

# Do we need to convert this value to a Zabbix-friendly one?
if msg["property"] in zbx_helpers:
val = zbx_helpers[msg["property"]](val)
Expand Down

0 comments on commit ce8da44

Please sign in to comment.