From 46b7b6392575c645a0d34739605d9165f4358d8a Mon Sep 17 00:00:00 2001 From: Melanie Witt Date: Sat, 13 Oct 2012 00:19:24 +0000 Subject: handles empty dhcp_domain with hostname in metadata Fixes bug 1064713. Currently hostname in metadata is created by concatenating the instance hostname with the dhcp_domain. When dhcp_domain is empty, it results in a hostname with a trailing dot. Change-Id: I52a50ff7f62c0a0dc900ddf707cc3dddce62bcb3 --- nova/api/metadata/base.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'nova/api') diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index a35eb4c2a..6a472df58 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -163,7 +163,8 @@ class InstanceMetadata(): if version not in VERSIONS: raise InvalidMetadataVersion(version) - hostname = "%s.%s" % (self.instance['hostname'], FLAGS.dhcp_domain) + hostname = self._get_hostname() + floating_ips = self.ip_info['floating_ips'] floating_ip = floating_ips and floating_ips[0] or '' @@ -290,8 +291,7 @@ class InstanceMetadata(): self.instance['key_name']: self.instance['key_data'] } - metadata['hostname'] = "%s.%s" % (self.instance['hostname'], - FLAGS.dhcp_domain) + metadata['hostname'] = self._get_hostname() metadata['name'] = self.instance['display_name'] metadata['launch_index'] = self.instance['launch_index'] @@ -306,6 +306,11 @@ class InstanceMetadata(): def _check_version(self, required, requested): return VERSIONS.index(requested) >= VERSIONS.index(required) + def _get_hostname(self): + return "%s%s%s" % (self.instance['hostname'], + '.' if FLAGS.dhcp_domain else '', + FLAGS.dhcp_domain) + def lookup(self, path): if path == "" or path[0] != "/": path = os.path.normpath("/" + path) -- cgit