summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorKevin L. Mitchell <kevin.mitchell@rackspace.com>2012-07-23 16:01:47 -0500
committerKevin L. Mitchell <kevin.mitchell@rackspace.com>2012-07-23 16:02:18 -0500
commit09d978994325b28c76050f112af3ee66b84a5e1f (patch)
tree6c14f38b7c7428b528c7961360fdcdc67a8f4db2 /nova/api
parent9b653109bb4cc83b610ca0eeb404b991157f3c9e (diff)
Add call to get hypervisor statistics
Adds an admin API call to retrieve the compute node statistics for an entire nova instance. Counts up all hypervisors and sums all their values (vcpus, vcpus_used, etc.). Change-Id: I36272656bb417c1549133fd2963bac54db0e86c6
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/compute/contrib/hypervisors.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/contrib/hypervisors.py b/nova/api/openstack/compute/contrib/hypervisors.py
index 49b050871..33aaa014b 100644
--- a/nova/api/openstack/compute/contrib/hypervisors.py
+++ b/nova/api/openstack/compute/contrib/hypervisors.py
@@ -104,6 +104,26 @@ class HypervisorServersTemplate(xmlutil.TemplateBuilder):
return xmlutil.MasterTemplate(root, 1)
+class HypervisorStatisticsTemplate(xmlutil.TemplateBuilder):
+ def construct(self):
+ root = xmlutil.TemplateElement('hypervisor_statistics',
+ selector='hypervisor_statistics')
+ root.set('count')
+ root.set('vcpus')
+ root.set('memory_mb')
+ root.set('local_gb')
+ root.set('vcpus_used')
+ root.set('memory_mb_used')
+ root.set('local_gb_used')
+ root.set('free_ram_mb')
+ root.set('free_disk_gb')
+ root.set('current_workload')
+ root.set('running_vms')
+ root.set('disk_available_least')
+
+ return xmlutil.MasterTemplate(root, 1)
+
+
class HypervisorsController(object):
"""The Hypervisors API controller for the OpenStack API."""
@@ -211,6 +231,13 @@ class HypervisorsController(object):
msg = _("No hypervisor matching '%s' could be found.") % id
raise webob.exc.HTTPNotFound(explanation=msg)
+ @wsgi.serializers(xml=HypervisorStatisticsTemplate)
+ def statistics(self, req):
+ context = req.environ['nova.context']
+ authorize(context)
+ stats = db.compute_node_statistics(context)
+ return dict(hypervisor_statistics=stats)
+
class Hypervisors(extensions.ExtensionDescriptor):
"""Admin-only hypervisor administration"""
@@ -223,7 +250,8 @@ class Hypervisors(extensions.ExtensionDescriptor):
def get_resources(self):
resources = [extensions.ResourceExtension('os-hypervisors',
HypervisorsController(),
- collection_actions={'detail': 'GET'},
+ collection_actions={'detail': 'GET',
+ 'statistics': 'GET'},
member_actions={'uptime': 'GET',
'search': 'GET',
'servers': 'GET'})]