diff options
author | Vlastimil Holer <vlastimil.holer@gmail.com> | 2012-09-19 15:31:10 +0200 |
---|---|---|
committer | Vlastimil Holer <vlastimil.holer@gmail.com> | 2012-09-19 15:31:10 +0200 |
commit | 34bebd8569e9319b791802f4fd551537967aec69 (patch) | |
tree | 24051f7c91ed473fa71016177867df470841e233 /cloudinit/sources/__init__.py | |
parent | c59e06c6d20ce585927f336630e8ae3cca12c110 (diff) | |
download | vyos-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__.py | 10 |
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(".") |