From 34bebd8569e9319b791802f4fd551537967aec69 Mon Sep 17 00:00:00 2001 From: Vlastimil Holer Date: Wed, 19 Sep 2012 15:31:10 +0200 Subject: Optionally resolve IPv4 hostname. --- cloudinit/sources/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'cloudinit/sources') diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index 3f611d44..9b68f99e 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -149,7 +149,7 @@ class DataSource(object): return "iid-datasource" return str(self.metadata['instance-id']) - def get_hostname(self, fqdn=False): + def get_hostname(self, fqdn=False, resolve_ip=False): defdomain = "localdomain" defhost = "localhost" domain = defdomain @@ -173,7 +173,13 @@ class DataSource(object): # make up a hostname (LP: #475354) in format ip-xx.xx.xx.xx lhost = self.metadata['local-hostname'] if util.is_ipv4(lhost): - toks = "ip-%s" % lhost.replace(".", "-") + if resolve_ip: + toks = util.gethostbyaddr(lhost) + + if toks: + toks = toks.split('.') + else: + toks = "ip-%s" % lhost.replace(".", "-") else: toks = lhost.split(".") -- cgit v1.2.3