summaryrefslogtreecommitdiff
path: root/cloudinit/DataSource.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-09-14 14:28:44 -0400
committerScott Moser <smoser@ubuntu.com>2011-09-14 14:28:44 -0400
commita826e7b9197d0001fb4d615040cae3c84890575d (patch)
tree0efa7694e38abc8e3045908cb4935b7ed3081e0f /cloudinit/DataSource.py
parent5c520f4e15cb20b694332aa03080f34666873885 (diff)
downloadvyos-cloud-init-a826e7b9197d0001fb4d615040cae3c84890575d.tar.gz
vyos-cloud-init-a826e7b9197d0001fb4d615040cae3c84890575d.zip
try a little harder to get a fqdn rather than defaulting to localdomain
This fixes (LP: #850206). See bug for more info. LP: #850206
Diffstat (limited to 'cloudinit/DataSource.py')
-rw-r--r--cloudinit/DataSource.py40
1 files changed, 19 insertions, 21 deletions
diff --git a/cloudinit/DataSource.py b/cloudinit/DataSource.py
index 7f40c0f8..cd6d6731 100644
--- a/cloudinit/DataSource.py
+++ b/cloudinit/DataSource.py
@@ -22,7 +22,7 @@ DEP_NETWORK = "NETWORK"
import UserDataHandler as ud
import cloudinit.util as util
-import platform
+import socket
class DataSource:
userdata = None
@@ -113,32 +113,30 @@ class DataSource:
# and didn't have one. raising error might be more appropriate
# but instead, basically look up the existing hostname
toks = []
- pfn = platform.node()
- # platform.node says: Returns the computer's network
- # name (which may not be fully qualified)
- toks = pfn.split(".")
- if pfn.find(".") > 0:
- toks = pfn.split(".")
- elif pfn:
- toks = [ pfn, defdomain ]
+ hostname = socket.gethostname()
- if len(toks) == 0:
+ fqdn = util.get_fqdn_from_hosts()
+
+ if fqdn and fqdn.find(".") > 0:
+ toks = fqdn.split(".")
+ elif hostname:
+ toks = [ hostname, defdomain ]
+ else:
toks = [ defhost, defdomain ]
- #log.warn("unable to find hostname, using defaults")
+
else:
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:
- toks = [ "ip-%s" % '-'.join(r) ]
- except:
- pass
+ # 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:
+ toks = [ "ip-%s" % '-'.join(r) ]
+ except:
+ pass
if len(toks) > 1:
hostname = toks[0]