move the reading of the cmdline cloud-config url to cloud-init.py

The reason for moving this from cloudinit/__init__.py was that it
was running too late there.

The cloudinit.parsed_cfgs variable was already filled by cloud-init.py's
reading of cloud config.  I'm sure I had done this so that it would not have to
re-parse configs.

I think the right way to handle this is to move that logic back to 
cloudinit/__init__.py and add some function like 'reread_configs()'
that would re-read all releavent cofnigs and re-setup logging.

That seemed more error prone at the moment, with limited time.
This commit is contained in:
Scott Moser 2012-04-05 00:08:42 -04:00
parent 1f31e1a89b
commit e6b02f59a5
2 changed files with 26 additions and 18 deletions

View File

@ -28,6 +28,7 @@ import cloudinit.CloudConfig as CC
import cloudinit.DataSource as ds
import cloudinit.netinfo as netinfo
import time
import traceback
import logging
import errno
import os
@ -67,6 +68,26 @@ def main():
warn("unable to open /proc/uptime\n")
uptime = "na"
cmdline_msg = None
cmdline_exc = None
if cmd == "start":
target = "%s.d/%s" % (cloudinit.system_config,
"91_kernel_cmdline_url.cfg")
if os.path.exists(target):
cmdline_msg = "cmdline: %s existed" % target
else:
try:
(key, url, content) = cloudinit.get_cmdline_url()
if key and content:
util.write_file(target, content, mode=0600)
cmdline_msg = ("cmdline: wrote %s from %s, %s" %
(target, key, url))
elif key:
cmdline_msg = ("cmdline: %s, %s had no cloud-config" %
(key, url))
except Exception:
cmdline_exc = traceback.format_exc()
try:
cfg = cloudinit.get_base_cfg(cfg_path)
except Exception as e:
@ -86,6 +107,11 @@ def main():
cloudinit.logging_set_from_cfg(cfg)
log = logging.getLogger()
if cmdline_exc:
log.warn(cmdline_exc)
elif cmdline_msg:
log.debug(cmdline_msg)
try:
cloudinit.initfs()
except Exception as e:

View File

@ -140,24 +140,6 @@ class CloudInit:
self.sysconfig = sysconfig
if DataSource.DEP_NETWORK in self.ds_deps:
target = "%s.d/%s" % (self.sysconfig, "91_kernel_cmdline_url.cfg")
if os.path.exists(target):
log.debug("cmdline: %s existed" % target)
else:
try:
(key, url, content) = get_cmdline_url()
if key and content:
util.write_file(target, content, mode=0600)
log.debug("cmdline: wrote %s from %s, %s" %
(target, key, url))
elif key:
log.debug("cmdline: %s, %s had no cloud-config" %
(key, url))
except Exception:
util.logexc(log)
log.warn("cmdline: exception occurred while reading")
self.cfg = self.read_cfg()
def read_cfg(self):