From ff522791cb2b58e83da4efea1be76757f05a1f1f Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 3 Feb 2010 17:47:20 -0500 Subject: make up a 'hostname' if there is a ip in local-hostname LP: #513842 --- ec2init/DataSourceEc2.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'ec2init') 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' -- cgit v1.2.3