diff options
author | Scott Moser <smoser@ubuntu.com> | 2010-08-12 01:56:12 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2010-08-12 01:56:12 -0400 |
commit | 54346d35221fd405423dd33a2b06202f10e2aa22 (patch) | |
tree | 71b636d2967abbb53cdb4d3c70061524e2add7ff /cloudinit/util.py | |
parent | a43357425d32b53aa58e226613e7fa2dd0714102 (diff) | |
download | vyos-cloud-init-54346d35221fd405423dd33a2b06202f10e2aa22.tar.gz vyos-cloud-init-54346d35221fd405423dd33a2b06202f10e2aa22.zip |
initial dump of "sans-cloud" code (DataSourceNoCloud)
The new classes 'DataSourceNoCloud' and 'DataSourceNoCloudNet'
implement a way to get data from the filesystem, or (very minimal)
data from the kernel command line. This allows the user to seed data to
these sources.
There are now 2 "cloud-init" jobs, cloud-init-local that runs on
mounted MOUNTPOINT=/
and 'cloud-init' that runs on
start on (mounted MOUNTPOINT=/ and net-device-up IFACE=eth0 and
stopped cloud-init-local )
The idea is that cloud-init-local can actually function without network.
The last thing in this commit is "uncloud-init".
This tool can be invoked as 'init=/usr/lib/cloud-init/uncloud-init'
It will "uncloudify" things in the image, generally making it easier
to use for a simpler environment, and then it will exec /sbin/init.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 7f5c1db4..137921ed 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -21,6 +21,13 @@ import errno import subprocess from Cheetah.Template import Template import cloudinit +import urllib2 +import logging +import traceback + +WARN = logging.WARN +DEBUG = logging.DEBUG +INFO = logging.INFO def read_conf(fname): try: @@ -114,3 +121,29 @@ def render_to_file(template, outfile, searchList): f.write(t.respond()) f.close() +# raise OSError with enoent if not found +def read_seeded(base="", ext=".raw", timeout=2): + if base.startswith("/"): + base="file://%s" % base + + ud_url = "%s%s%s" % (base, "user-data", ext) + md_url = "%s%s%s" % (base, "meta-data", ext) + + try: + md_resp = urllib2.urlopen(urllib2.Request(md_url), timeout=timeout) + ud_resp = urllib2.urlopen(urllib2.Request(ud_url), timeout=timeout) + + md_str = md_resp.read() + ud = ud_resp.read() + md = yaml.load(md_str) + + return(md,ud) + except urllib2.HTTPError: + raise + except urllib2.URLError, e: + if isinstance(e.reason,OSError) and e.reason.errno == errno.ENOENT: + raise e.reason + raise e + +def logexc(log,lvl=logging.DEBUG): + log.log(lvl,traceback.format_exc()) |