summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2010-02-03 17:47:20 -0500
committerScott Moser <smoser@ubuntu.com>2010-02-03 17:47:20 -0500
commitff522791cb2b58e83da4efea1be76757f05a1f1f (patch)
treed31d6506b2fb8d181bac20367b96cb5f8a71d05b
parentcfb7cda5b05232d014e56f06e0531d8d4dca5658 (diff)
downloadvyos-cloud-init-ff522791cb2b58e83da4efea1be76757f05a1f1f.tar.gz
vyos-cloud-init-ff522791cb2b58e83da4efea1be76757f05a1f1f.zip
make up a 'hostname' if there is a ip in local-hostname LP: #513842
-rw-r--r--ec2init/DataSourceEc2.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/ec2init/DataSourceEc2.py b/ec2init/DataSourceEc2.py
index 1e81fddb..dae2873d 100644
--- a/ec2init/DataSourceEc2.py
+++ b/ec2init/DataSourceEc2.py
@@ -61,9 +61,16 @@ class DataSourceEc2(DataSource.DataSource):
return(self.location_locale_map["default"])
def get_hostname(self):
- hostname = self.metadata['local-hostname']
- hostname = hostname.split('.')[0]
- return hostname
+ toks = self.metadata['local-hostname'].split('.')
+ # if there is an ipv4 address in 'local-hostname', then
+ # make up a hostname (LP: #475354)
+ if len(toks) == 4:
+ try:
+ r = filter(lambda x: int(x) < 256 and x > 0, toks)
+ if len(r) == 4:
+ return("ip-%s" % '-'.join(r))
+ except: pass
+ return toks[0]
def get_mirror_from_availability_zone(self, availability_zone = None):
# availability is like 'us-west-1b' or 'eu-west-1a'