Skip to content

Commit

Permalink
Refactor the *.perf.counter.info methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Jan 6, 2015
1 parent 62a33fb commit d09506c
Showing 1 changed file with 28 additions and 55 deletions.
83 changes: 28 additions & 55 deletions src/vpoller/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,29 @@ def _get_perf_counter_info(self, counter_id):

return result

def _entity_perf_counter_info(self, entity):
"""
Get info about supported performance counters for entity
Args:
entity (pyVmomi.vim.*): A managed object to lookup
Returns:
Information about supported performance counters for entity
"""
try:
metric_id = self.si.content.perfManager.QueryAvailablePerfMetric(entity=obj)
except pyVmomi.vim.InvalidArgument as e:
return {
'success': 1,
'msg': 'Cannot retrieve performance counters for %s: %s' % (msg['name'], e)
}

counter_id = [m.counterId for m in metric_id]

return self._get_perf_counter_info(counter_id=counter_id)

def event_latest(self, msg):
"""
Get the latest event registered
Expand Down Expand Up @@ -1004,17 +1027,7 @@ def datacenter_perf_counter_info(self, msg):
obj_type=pyVmomi.vim.Datacenter
)

try:
metric_id = self.si.content.perfManager.QueryAvailablePerfMetric(entity=obj)
except pyVmomi.vim.InvalidArgument as e:
return {
'success': 1,
'msg': 'Cannot retrieve performance counters for %s: %s' % (msg['name'], e)
}

counter_id = [m.counterId for m in metric_id]

return self._get_perf_counter_info(counter_id=counter_id)
return self._entity_perf_counter_info(entity=obj)

def datacenter_get(self, msg):
"""
Expand Down Expand Up @@ -1132,17 +1145,7 @@ def cluster_perf_counter_info(self, msg):
obj_type=pyVmomi.vim.ClusterComputeResource
)

try:
metric_id = self.si.content.perfManager.QueryAvailablePerfMetric(entity=obj)
except pyVmomi.vim.InvalidArgument as e:
return {
'success': 1,
'msg': 'Cannot retrieve performance counters for %s: %s' % (msg['name'], e)
}

counter_id = [m.counterId for m in metric_id]

return self._get_perf_counter_info(counter_id=counter_id)
return self._entity_perf_counter_info(entity=obj)

def cluster_get(self, msg):
"""
Expand Down Expand Up @@ -1388,17 +1391,7 @@ def host_perf_counter_info(self, msg):
obj_type=pyVmomi.vim.HostSystem
)

try:
metric_id = self.si.content.perfManager.QueryAvailablePerfMetric(entity=obj)
except pyVmomi.vim.InvalidArgument as e:
return {
'success': 1,
'msg': 'Cannot retrieve performance counters for %s: %s' % (msg['name'], e)
}

counter_id = [m.counterId for m in metric_id]

return self._get_perf_counter_info(counter_id=counter_id)
return self._entity_perf_counter_info(entity=obj)

def host_cluster_get(self, msg):
"""
Expand Down Expand Up @@ -1640,17 +1633,7 @@ def vm_perf_counter_info(self, msg):
obj_type=pyVmomi.vim.VirtualMachine
)

try:
metric_id = self.si.content.perfManager.QueryAvailablePerfMetric(entity=obj)
except pyVmomi.vim.InvalidArgument as e:
return {
'success': 1,
'msg': 'Cannot retrieve performance counters for %s: %s' % (msg['name'], e)
}

counter_id = [m.counterId for m in metric_id]

return self._get_perf_counter_info(counter_id=counter_id)
return self._entity_perf_counter_info(entity=obj)

def vm_discover(self, msg):
"""
Expand Down Expand Up @@ -2552,14 +2535,4 @@ def datastore_perf_counter_info(self, msg):
obj_type=pyVmomi.vim.Datastore
)

try:
metric_id = self.si.content.perfManager.QueryAvailablePerfMetric(entity=obj)
except pyVmomi.vim.InvalidArgument as e:
return {
'success': 1,
'msg': 'Cannot retrieve performance counters for %s: %s' % (msg['name'], e)
}

counter_id = [m.counterId for m in metric_id]

return self._get_perf_counter_info(counter_id=counter_id)
return self._entity_perf_counter_info(entity=obj)

0 comments on commit d09506c

Please sign in to comment.