summaryrefslogtreecommitdiff
path: root/cloudinit/CloudConfig/cc_set_hostname.py
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit/CloudConfig/cc_set_hostname.py')
-rw-r--r--cloudinit/CloudConfig/cc_set_hostname.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/cloudinit/CloudConfig/cc_set_hostname.py b/cloudinit/CloudConfig/cc_set_hostname.py
index 49368019..bc190049 100644
--- a/cloudinit/CloudConfig/cc_set_hostname.py
+++ b/cloudinit/CloudConfig/cc_set_hostname.py
@@ -23,21 +23,16 @@ def handle(name,cfg,cloud,log,args):
log.debug("preserve_hostname is set. not setting hostname")
return(True)
+ ( hostname, fqdn ) = util.get_hostname_fqdn(cfg, cloud)
try:
- hostname_prefix = util.get_cfg_option_str(cfg, "hostname_prefix", None)
- hostname_attr = util.get_cfg_option_str(cfg, "hostname_attribute", "hostname")
- hostname_function = getattr(cloud, 'get_' + hostname_attr, None)
- if hostname_fucntion is None: hostname_fucntion = cloud.get_hostname
- hostname = util.get_cfg_option_str(cfg,"hostname", hostname_function)
- if hostname_prefix: hostname = hostname_prefix + "-" + hostname
set_hostname(hostname, log)
except Exception as e:
util.logexc(log)
- log.warn("failed to set hostname\n")
+ log.warn("failed to set hostname to %s\n", hostname)
return(True)
def set_hostname(hostname, log):
- subprocess.Popen(['hostname', hostname]).communicate()
+ util.subp(['hostname', hostname])
util.write_file("/etc/hostname","%s\n" % hostname, 0644)
log.debug("populated /etc/hostname with %s on first boot", hostname)