Skip to content

Commit

Permalink
Use sysmetadata to get instance_name in API
Browse files Browse the repository at this point in the history
Change-Id: If2ca9ff307f0d9b977d76f6ba8f34fb828c893cd
  • Loading branch information
sorrison committed Jan 8, 2015
1 parent 808a725 commit 6bf1cf7
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion nova/api/openstack/compute/contrib/extended_server_attributes.py
Expand Up @@ -14,15 +14,26 @@

"""The Extended Server Attributes API extension."""

from oslo.config import cfg

from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import utils

CONF = cfg.CONF

authorize = extensions.soft_extension_authorizer('compute',
'extended_server_attributes')


class ExtendedServerAttributesController(wsgi.Controller):
def _get_hypervisor_instance_name(self, context, instance):
if not CONF.cells.enable:
return instance['name']
sys_metadata = utils.instance_sys_meta(instance)
return sys_metadata.get('instance_name', '')

def _extend_server(self, context, server, instance):
key = "%s:hypervisor_hostname" % Extended_server_attributes.alias
server[key] = instance['node']
Expand All @@ -31,9 +42,11 @@ def _extend_server(self, context, server, instance):
if attr == 'name':
key = "%s:instance_%s" % (Extended_server_attributes.alias,
attr)
server[key] = self._get_hypervisor_instance_name(context,
instance)
else:
key = "%s:%s" % (Extended_server_attributes.alias, attr)
server[key] = instance[attr]
server[key] = instance[attr]

@wsgi.extends
def show(self, req, resp_obj, id):
Expand Down

0 comments on commit 6bf1cf7

Please sign in to comment.