diff options
author | Scott Moser <smoser@ubuntu.com> | 2012-04-05 00:49:11 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2012-04-05 00:49:11 -0400 |
commit | c2a4447527d5e8b2e2999b6f1832577203a64f2a (patch) | |
tree | aa58108146e35f5ab5d93500c1116bcad12d6ce8 /cloudinit | |
parent | b39abf5bbe51d62d1ef1dd1e813720eafc1ddc85 (diff) | |
parent | 6d62fe860f55faf2d7b0b6216c11305e114c5214 (diff) | |
download | vyos-cloud-init-c2a4447527d5e8b2e2999b6f1832577203a64f2a.tar.gz vyos-cloud-init-c2a4447527d5e8b2e2999b6f1832577203a64f2a.zip |
Allow a url to cloud-config data to be specified on kernel config line
In order to allow an ephemeral, or otherwise pristine image to
receive some configuration, cloud-init will read a url directed by
the kernel command line and proceed as if its data had previously existed.
For more information, see doc/kernel-cmdline.txt
Diffstat (limited to 'cloudinit')
-rw-r--r-- | cloudinit/DataSourceNoCloud.py | 7 | ||||
-rw-r--r-- | cloudinit/__init__.py | 26 | ||||
-rw-r--r-- | cloudinit/util.py | 13 |
3 files changed, 46 insertions, 0 deletions
diff --git a/cloudinit/DataSourceNoCloud.py b/cloudinit/DataSourceNoCloud.py index 62ecc088..e8c56b8f 100644 --- a/cloudinit/DataSourceNoCloud.py +++ b/cloudinit/DataSourceNoCloud.py @@ -67,6 +67,13 @@ class DataSourceNoCloud(DataSource.DataSource): found.append(self.seeddir) log.debug("using seeded cache data in %s" % self.seeddir) + # if the datasource config had a 'seedfrom' entry, then that takes + # precedence over a 'seedfrom' that was found in a filesystem + # but not over external medi + if 'seedfrom' in self.ds_cfg and self.ds_cfg['seedfrom']: + found.append("ds_config") + md["seedfrom"] = self.ds_cfg['seedfrom'] + fslist = util.find_devs_with("TYPE=vfat") fslist.extend(util.find_devs_with("TYPE=iso9660")) diff --git a/cloudinit/__init__.py b/cloudinit/__init__.py index 6d276d84..85c6fd1b 100644 --- a/cloudinit/__init__.py +++ b/cloudinit/__init__.py @@ -137,7 +137,9 @@ class CloudInit: if ds_deps != None: self.ds_deps = ds_deps + self.sysconfig = sysconfig + self.cfg = self.read_cfg() def read_cfg(self): @@ -639,3 +641,27 @@ class InternalPartHandler: def handle_part(self, data, ctype, filename, payload, frequency): return(self.handler(data, ctype, filename, payload, frequency)) + + +def get_cmdline_url(names=('cloud-config-url', 'url'), + starts="#cloud-config", cmdline=None): + + if cmdline == None: + cmdline = util.get_cmdline() + + data = util.keyval_str_to_dict(cmdline) + url = None + key = None + for key in names: + if key in data: + url = data[key] + break + if url == None: + return (None, None, None) + + contents = util.readurl(url) + + if contents.startswith(starts): + return (key, url, contents) + + return (key, url, None) diff --git a/cloudinit/util.py b/cloudinit/util.py index 9133426c..47397418 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -840,3 +840,16 @@ def wait_for_url(urls, max_wait=None, timeout=None, time.sleep(sleeptime) return False + + +def keyval_str_to_dict(kvstring): + ret = {} + for tok in kvstring.split(): + try: + (key, val) = tok.split("=", 1) + except ValueError: + key = tok + val = True + ret[key] = val + + return(ret) |