diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-01-18 20:25:57 +0000 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-01-18 20:25:57 +0000 |
commit | c11b93cf03e4ff0dd90c83d09f27c512513be9b7 (patch) | |
tree | 02ac85268a561da63cb6dd967bd60399350227fe /cloudinit | |
parent | e40a1c8143ee88e0eb9b979fabff587ec53b971d (diff) | |
download | vyos-cloud-init-c11b93cf03e4ff0dd90c83d09f27c512513be9b7.tar.gz vyos-cloud-init-c11b93cf03e4ff0dd90c83d09f27c512513be9b7.zip |
support reading cloud_config from kernel command line
This allows the user to specify portions of the cloud-config
system config on the kernel command line. values found on the
kernel command line have preference over those in system config.
The format is:
cc:[ ]<yaml content here> [end_cc]
Where:
'cc:' indicates the beginning of cloud config syntax
[ ] optionally followed by whitespace (which will be trimmed)
<yaml content here> :
this content is passed untouched to yaml
end_cc:
this is optional. If no 'end_cc' tag is found, all data from
the begin tag to the end of the command line is consumed
Multiple occurences of the cc:<data>end_cc will be joined with
carriage return before passing to yaml.
Any litteral '\n' (backslash followed by lower case 'n') are converted
to a carriage return.
The following are examples:
cc: ssh_import_id: [smoser, kirkland]
cc: ssh_import_id: [smoser, bob]\\nruncmd: [ [ ls, -l ], echo hi ] end_cc
cc:ssh_import_id: [smoser] end_cc cc:runcmd: [ [ ls, -l ] ] end_cc
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/DataSourceNoCloud.py | 14 | ||||
-rw-r--r-- | cloudinit/util.py | 58 |
2 files changed, 59 insertions, 13 deletions
diff --git a/cloudinit/DataSourceNoCloud.py b/cloudinit/DataSourceNoCloud.py index cd988d08..78c9c9c8 100644 --- a/cloudinit/DataSourceNoCloud.py +++ b/cloudinit/DataSourceNoCloud.py @@ -108,16 +108,10 @@ class DataSourceNoCloud(DataSource.DataSource): # root=LABEL=uec-rootfs ro ds=nocloud def parse_cmdline_data(ds_id,fill,cmdline=None): if cmdline is None: - if 'DEBUG_PROC_CMDLINE' in os.environ: - cmdline = os.environ["DEBUG_PROC_CMDLINE"] - else: - cmdfp = open("/proc/cmdline") - cmdline = cmdfp.read().strip() - cmdfp.close() - cmdline = " %s " % cmdline.lower() - - if not ( " %s " % ds_id in cmdline or " %s;" % ds_id in cmdline ): - return False + cmdline = util.get_cmdline() + + if not ( " %s " % ds_id in cmdline or " %s;" % ds_id in cmdline ): + return False argline="" # cmdline can contain: diff --git a/cloudinit/util.py b/cloudinit/util.py index 05462b9d..48c9bafc 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -43,13 +43,25 @@ def read_conf(fname): raise def get_base_cfg(cfgfile,cfg_builtin=""): + kerncfg = { } + syscfg = { } contents = read_file_with_includes(cfgfile) - syscfg = yaml.load(contents) + if contents: + syscfg = yaml.load(contents) + + kern_contents = read_cc_from_cmdline() + if kern_contents: + kerncfg = yaml.load(kern_contents) + + # kernel parameters override system config + combined = mergedict(kerncfg, syscfg) + import pprint; pprint.pprint(combined) + if cfg_builtin: builtin = yaml.load(cfg_builtin) else: - return(syscfg) - return(mergedict(syscfg,builtin)) + return(combined) + return(mergedict(combined,builtin)) def get_cfg_option_bool(yobj, key, default=False): if not yobj.has_key(key): return default @@ -223,3 +235,43 @@ def read_file_with_includes(fname, rel = ".", stack=[], patt = None): stack.pop() return(contents) +def get_cmdline(): + if 'DEBUG_PROC_CMDLINE' in os.environ: + cmdline = os.environ["DEBUG_PROC_CMDLINE"] + else: + try: + cmdfp = open("/proc/cmdline") + cmdline = cmdfp.read().strip() + cmdfp.close() + except: + cmdline = "" + return(cmdline) + +def read_cc_from_cmdline(cmdline=None): + # this should support reading cloud-config information from + # the kernel command line. It is intended to support content of the + # format: + # cc: <yaml content here> [end_cc] + # this would include: + # cc: ssh_import_id: [smoser, kirkland]\\n + # cc: ssh_import_id: [smoser, bob]\\nruncmd: [ [ ls, -l ], echo hi ] end_cc + # cc:ssh_import_id: [smoser] end_cc cc:runcmd: [ [ ls, -l ] ] end_cc + if cmdline is None: + cmdline = get_cmdline() + + tag_begin="cc:" + tag_end="end_cc" + begin_l = len(tag_begin) + end_l = len(tag_end) + clen = len(cmdline) + tokens = [ ] + begin = cmdline.find(tag_begin) + while begin >= 0: + end = cmdline.find(tag_end, begin + begin_l) + if end < 0: + end = clen + tokens.append(cmdline[begin+begin_l:end].lstrip().replace("\\n","\n")) + + begin = cmdline.find(tag_begin, end + end_l) + + return('\n'.join(tokens)) |