summaryrefslogtreecommitdiff
path: root/cloudinit/sources/__init__.py
diff options
context:
space:
mode:
authorVlastimil Holer <vlastimil.holer@gmail.com>2012-09-19 15:31:10 +0200
committerVlastimil Holer <vlastimil.holer@gmail.com>2012-09-19 15:31:10 +0200
commit34bebd8569e9319b791802f4fd551537967aec69 (patch)
tree24051f7c91ed473fa71016177867df470841e233 /cloudinit/sources/__init__.py
parentc59e06c6d20ce585927f336630e8ae3cca12c110 (diff)
downloadvyos-cloud-init-34bebd8569e9319b791802f4fd551537967aec69.tar.gz
vyos-cloud-init-34bebd8569e9319b791802f4fd551537967aec69.zip
Optionally resolve IPv4 hostname.
Diffstat (limited to 'cloudinit/sources/__init__.py')
-rw-r--r--cloudinit/sources/__init__.py10
1 files changed, 8 insertions, 2 deletions
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(".")