cloud-init-dev team mailing list archive
-
cloud-init-dev team
-
Mailing list archive
-
Message #00979
[Merge] lp:~sgolovatiuk/cloud-init/fix_no_server_cfg into lp:cloud-init
Sergii Golovatiuk has proposed merging lp:~sgolovatiuk/cloud-init/fix_no_server_cfg into lp:cloud-init.
Requested reviews:
cloud init development team (cloud-init-dev)
For more details, see:
https://code.launchpad.net/~sgolovatiuk/cloud-init/fix_no_server_cfg/+merge/298786
Generate server.cfg when it's absent in package
--
Your team cloud init development team is requested to review the proposed merge of lp:~sgolovatiuk/cloud-init/fix_no_server_cfg into lp:cloud-init.
=== modified file 'cloudinit/config/cc_mcollective.py'
--- cloudinit/config/cc_mcollective.py 2015-01-21 22:56:53 +0000
+++ cloudinit/config/cc_mcollective.py 2016-06-30 14:03:14 +0000
@@ -50,34 +50,40 @@
if 'conf' in mcollective_cfg:
# Read server.cfg values from the
# original file in order to be able to mix the rest up
- mcollective_config = ConfigObj(SERVER_CFG)
- # See: http://tiny.cc/jh9agw
- for (cfg_name, cfg) in mcollective_cfg['conf'].items():
- if cfg_name == 'public-cert':
- util.write_file(PUBCERT_FILE, cfg, mode=0o644)
- mcollective_config['plugin.ssl_server_public'] = PUBCERT_FILE
- mcollective_config['securityprovider'] = 'ssl'
- elif cfg_name == 'private-cert':
- util.write_file(PRICERT_FILE, cfg, mode=0o600)
- mcollective_config['plugin.ssl_server_private'] = PRICERT_FILE
- mcollective_config['securityprovider'] = 'ssl'
- else:
- if isinstance(cfg, six.string_types):
- # Just set it in the 'main' section
- mcollective_config[cfg_name] = cfg
- elif isinstance(cfg, (dict)):
- # Iterate through the config items, create a section
- # if it is needed and then add/or create items as needed
- if cfg_name not in mcollective_config.sections:
- mcollective_config[cfg_name] = {}
- for (o, v) in cfg.items():
- mcollective_config[cfg_name][o] = v
+
+ try:
+ mcollective_config = ConfigObj(SERVER_CFG, file_error=True)
+ except IOError:
+ log.warn("Did not find file %s", SERVER_CFG)
+ mcollective_config = ConfigObj(mcollective_cfg['conf'])
+ else:
+ for (cfg_name, cfg) in mcollective_cfg['conf'].items():
+ if cfg_name == 'public-cert':
+ util.write_file(PUBCERT_FILE, cfg, mode=0o644)
+ mcollective_config['plugin.ssl_server_public'] = PUBCERT_FILE
+ mcollective_config['securityprovider'] = 'ssl'
+ elif cfg_name == 'private-cert':
+ util.write_file(PRICERT_FILE, cfg, mode=0o600)
+ mcollective_config['plugin.ssl_server_private'] = PRICERT_FILE
+ mcollective_config['securityprovider'] = 'ssl'
else:
- # Otherwise just try to convert it to a string
- mcollective_config[cfg_name] = str(cfg)
- # We got all our config as wanted we'll rename
- # the previous server.cfg and create our new one
- util.rename(SERVER_CFG, "%s.old" % (SERVER_CFG))
+ if isinstance(cfg, six.string_types):
+ # Just set it in the 'main' section
+ mcollective_config[cfg_name] = cfg
+ elif isinstance(cfg, (dict)):
+ # Iterate through the config items, create a section
+ # if it is needed and then add/or create items as needed
+ if cfg_name not in mcollective_config.sections:
+ mcollective_config[cfg_name] = {}
+ for (o, v) in cfg.items():
+ mcollective_config[cfg_name][o] = v
+ else:
+ # Otherwise just try to convert it to a string
+ mcollective_config[cfg_name] = str(cfg)
+ # We got all our config as wanted we'll rename
+ # the previous server.cfg and create our new one
+ util.rename(SERVER_CFG, "%s.old" % (SERVER_CFG))
+
# Now we got the whole file, write to disk...
contents = StringIO()
mcollective_config.write(contents)
Follow ups