diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-09-01 10:07:05 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-09-01 10:07:05 -0400 |
commit | 8a42512443986326f3bdcf25fadc0c2aad9cccff (patch) | |
tree | 17415c59f59c74ac8fdb3b04c76641475cd03439 /cloudinit | |
parent | c90df6b03af752742bf08f52322048d1c5e8948a (diff) | |
download | vyos-cloud-init-8a42512443986326f3bdcf25fadc0c2aad9cccff.tar.gz vyos-cloud-init-8a42512443986326f3bdcf25fadc0c2aad9cccff.zip |
improve DataSource's get_hostname function
This allows for the chance that platform.node returned
a fully qualified domainname. Per its doc:
Returns the computer's network name (which may not be fully
qualified)
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/DataSource.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/cloudinit/DataSource.py b/cloudinit/DataSource.py index 3c4ca995..3f851e14 100644 --- a/cloudinit/DataSource.py +++ b/cloudinit/DataSource.py @@ -98,9 +98,31 @@ class DataSource: return(self.metadata['instance-id']) def get_hostname(self, fqdn=False): - domain = "localdomain" + defdomain = "localdomain" + defhost = "localhost" + + domain = defdomain if not 'local-hostname' in self.metadata: - toks = [ platform.node(), domain ] + + # this is somewhat questionable really. + # the cloud datasource was asked for a hostname + # 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 ] + + if len(toks) == 0: + toks = [ defhost, defdomain ] + #log.warn("unable to find hostname, using defaults") + else: toks = self.metadata['local-hostname'].split('.') |