From f0bef902d13ecc55e21166eb9acc8d9ef0864f88 Mon Sep 17 00:00:00 2001 From: Josh Kearney Date: Wed, 29 Feb 2012 12:05:28 -0600 Subject: Include hypervisor_hostname in the extended server attributes. Change-Id: I5424ee3defea76ac4cdbfcf6fe8675aad8e66c7a --- .../compute/contrib/extended_server_attributes.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/extended_server_attributes.py b/nova/api/openstack/compute/contrib/extended_server_attributes.py index 102477db3..c1c85c62e 100644 --- a/nova/api/openstack/compute/contrib/extended_server_attributes.py +++ b/nova/api/openstack/compute/contrib/extended_server_attributes.py @@ -20,6 +20,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import compute +from nova import db from nova import exception from nova import flags from nova import log as logging @@ -43,7 +44,18 @@ class ExtendedServerAttributesController(wsgi.Controller): instances = self.compute_api.get_all(context, filters) return dict((instance['uuid'], instance) for instance in instances) - def _extend_server(self, server, instance): + def _get_hypervisor_hostname(self, context, instance): + compute_node = db.compute_node_get_by_host(context, instance["host"]) + + try: + return compute_node["hypervisor_hostname"] + except TypeError: + return + + def _extend_server(self, context, server, instance): + key = "%s:hypervisor_hostname" % Extended_server_attributes.alias + server[key] = self._get_hypervisor_hostname(context, instance) + for attr in ['host', 'name']: if attr == 'name': key = "%s:instance_%s" % (Extended_server_attributes.alias, @@ -65,7 +77,7 @@ class ExtendedServerAttributesController(wsgi.Controller): explanation = _("Server not found.") raise exc.HTTPNotFound(explanation=explanation) - self._extend_server(resp_obj.obj['server'], instance) + self._extend_server(context, resp_obj.obj['server'], instance) @wsgi.extends def detail(self, req, resp_obj): @@ -85,7 +97,7 @@ class ExtendedServerAttributesController(wsgi.Controller): # Ignore missing instance data continue - self._extend_server(server_object, instance_data) + self._extend_server(context, server_object, instance_data) class Extended_server_attributes(extensions.ExtensionDescriptor): -- cgit