summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorAvishai Ish-Shalom <avishai.ish-shalom@mail.huji.ac.il>2011-04-21 15:00:05 +0300
committerAvishai Ish-Shalom <avishai.ish-shalom@mail.huji.ac.il>2011-04-21 15:00:05 +0300
commite363a4869459915fed45d5e92005f61afa5ee6e8 (patch)
treef3075e13d7c43932f5b8347a7763235c722e5963 /cloudinit
parentf613aba32e7652a27f744d27c2d000831723023c (diff)
downloadvyos-cloud-init-e363a4869459915fed45d5e92005f61afa5ee6e8.tar.gz
vyos-cloud-init-e363a4869459915fed45d5e92005f61afa5ee6e8.zip
Allow configurable hostname prefix and hostname attribute
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)