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 /cloud-init.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 'cloud-init.py')
-rwxr-xr-x | cloud-init.py | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/cloud-init.py b/cloud-init.py index ff70017f..11bf89af 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -30,6 +30,15 @@ def warn(str): sys.stderr.write(str) def main(): + cmds = ( "start", "start-local" ) + cmd = "" + if len(sys.argv) > 1: + cmd = sys.argv[1] + + if not cmd in cmds: + sys.stderr.write("bad command %s. use one of %s\n" % (cmd, cmds)) + sys.exit(1) + now = time.strftime("%a, %d %b %Y %H:%M:%S %z") try: uptimef=open("/proc/uptime") @@ -39,29 +48,39 @@ def main(): warn("unable to open /proc/uptime\n") uptime = "na" - msg = "cloud-init running: %s. up %s seconds" % (now, uptime) + msg = "cloud-init %s running: %s. up %s seconds" % (cmd, now, uptime) sys.stderr.write(msg + "\n") sys.stderr.flush() + source_type = "all" + if cmd == "start-local": + source_type = "local" + cloudinit.logging_set_from_cfg_file() log = logging.getLogger() log.info(msg) # cache is not instance specific, so it has to be purged - cloudinit.purge_cache() + # but we want 'start' to benefit from a cache if + # a previous start-local populated one + if cmd == "start-local": + cloudinit.purge_cache() - cloud = cloudinit.CloudInit() + cloud = cloudinit.CloudInit(source_type=source_type) try: cloud.get_data_source() - except Exception as e: - print e - sys.stderr.write("Failed to get instance data\n") + except cloudinit.DataSourceNotFoundException as e: + sys.stderr.write("no instance data found in %s\n" % cmd) sys.exit(1) # store the metadata cloud.update_cache() + msg = "found data source: %s" % cloud.datasource + sys.stderr.write(msg + "\n") + log.debug(msg) + # parse the user data (ec2-run-userdata.py) try: cloud.sem_and_run("consume_userdata", "once-per-instance", |