summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/CloudConfig/cc_set_hostname.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/cloudinit/CloudConfig/cc_set_hostname.py b/cloudinit/CloudConfig/cc_set_hostname.py
index 2b130810..49368019 100644
--- a/cloudinit/CloudConfig/cc_set_hostname.py
+++ b/cloudinit/CloudConfig/cc_set_hostname.py
@@ -24,7 +24,12 @@ def handle(name,cfg,cloud,log,args):
return(True)
try:
- hostname = util.get_cfg_option_str(cfg,"hostname",cloud.get_hostname())
+ 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)