diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-08-03 13:06:55 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-08-03 13:06:55 -0400 |
commit | eec6618bea0ab204ce02e8c122e9960ac034595b (patch) | |
tree | d3ddcfa9340a2c2ba1cbb0789f55670914229649 /cloudinit/util.py | |
parent | 96edbdc300e6697d7160bccfbb8669c67e57164c (diff) | |
download | vyos-cloud-init-eec6618bea0ab204ce02e8c122e9960ac034595b.tar.gz vyos-cloud-init-eec6618bea0ab204ce02e8c122e9960ac034595b.zip |
add get_hostname_fqdn method to 'util' and use it for getting hostname
This adds a method 'get_hostname_fqdn' to cloudinit.util, and then
uses this method for getting the hostname and fqdn in places that get
hostname.
The single place for getting it right will help.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index b3842afa..64eafa29 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -422,3 +422,26 @@ def islxc(): raise return False + +def get_hostname_fqdn(cfg, cloud): + # return the hostname and fqdn from 'cfg'. If not found in cfg, + # then fall back to data from cloud + if "fqdn" in cfg: + # user specified a fqdn. Default hostname then is based off that + fqdn = cfg['fqdn'] + hostname = get_cfg_option_str(cfg,"hostname",fqdn.split('.')[0]) + else: + if "hostname" in cfg and cfg['hostname'].find('.') > 0: + # user specified hostname, and it had '.' in it + # be nice to them. set fqdn and hostname from that + fqdn = cfg['hostname'] + hostname = cfg['hostname'][:fqdn.find('.')] + else + # no fqdn set, get fqdn from cloud. + # get hostname from cfg if available otherwise cloud + fqdn = cloud.get_hostname(fqdn=True) + if "hostname" in cfg: + hostname = cfg['hostname'] + else: + hostname = cloud.get_hostname() + return(hostname, fqdn) |