From 09d978994325b28c76050f112af3ee66b84a5e1f Mon Sep 17 00:00:00 2001 From: "Kevin L. Mitchell" Date: Mon, 23 Jul 2012 16:01:47 -0500 Subject: 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 --- nova/api/openstack/compute/contrib/hypervisors.py | 30 ++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'nova/api') 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'})] -- cgit