Skip to content

Commit

Permalink
Fix for issue #33
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Jul 24, 2014
1 parent b434f4e commit 3e1be0e
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1417,14 +1417,16 @@ def vm_cpu_usage_percent(self, msg):
# properties required to calculate the CPU usage in percentage.
# The CPU usage in percentage is directly related to the host the
# Virtual Machine is running on, so we need to collect the 'runtime.host' property as well.
required_properties = [
'name',
'runtime.host',
'summary.quickStats.overallCpuUsage',
'config.hardware.numCoresPerSocket',
'config.hardware.numCPU',
]

data = self._get_object_properties(
properties=[
'name',
'runtime.host',
'summary.quickStats.overallCpuUsage',
'config.hardware.numCoresPerSocket',
'config.hardware.numCPU',
],
properties=required_properties,
obj_type=pyVmomi.vim.VirtualMachine,
obj_property_name='name',
obj_property_value=msg['name'],
Expand All @@ -1436,6 +1438,18 @@ def vm_cpu_usage_percent(self, msg):
# Get the VM properties
props = data['result'][0]

# TODO: A fix for VMware vSphere 4.x versions, where not always
# the properties requested are returned by vCenter server,
# which could result in a KeyError exception.
# See this issue for more details:
#
# - https://github.com/dnaeon/py-vpoller/issues/33
#
# We should ensure that vPoller Workers do not fail under
# such circumstances and return an error message.
if not all(required_properties) in props:
return { 'success': 1, 'msg': 'Unable to retrieve required properties' }

# Calculate CPU usage in percentage
# The overall CPU usage returned by vSphere is in MHz, so
# we first convert it back to Hz and then calculate percentage
Expand Down

0 comments on commit 3e1be0e

Please sign in to comment.