From e363a4869459915fed45d5e92005f61afa5ee6e8 Mon Sep 17 00:00:00 2001 From: Avishai Ish-Shalom Date: Thu, 21 Apr 2011 15:00:05 +0300 Subject: Allow configurable hostname prefix and hostname attribute --- cloudinit/CloudConfig/cc_set_hostname.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'cloudinit') 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) -- cgit v1.2.3