diff options
author | Scott Moser <smoser@ubuntu.com> | 2011-01-26 13:54:18 -0500 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2011-01-26 13:54:18 -0500 |
commit | fcbdfd587818c7144193b6c709ec29fda4fb9b00 (patch) | |
tree | b180b671e54b4fb8975b6ba2032c53d4228b39b7 /cloud-init.py | |
parent | 8001d7eadd0af627101254dad2ab22dbd454b7ab (diff) | |
parent | dc5e7116e663d3b5cad165fcac8b3141f8ffbc05 (diff) | |
download | vyos-cloud-init-fcbdfd587818c7144193b6c709ec29fda4fb9b00.tar.gz vyos-cloud-init-fcbdfd587818c7144193b6c709ec29fda4fb9b00.zip |
merge in work form ds-rework
rework of DataSource loading.
The DataSources that are loaded are now controlled entirely via
configuration file of 'datasource_list', like:
datasource_list: [ "NoCloud", "OVF", "Ec2" ]
Each item in that list is a "DataSourceCollection". for each item
in the list, cloudinit will attempt to load:
cloudinit.DataSource<item>
and, failing that,
DataSource<item>
The module is required to have a method named 'get_datasource_list'
in it that takes a single list of "dependencies" and returns
a list of python classes inside the collection that can run needing
only those dependencies.
The dependencies are defines in DataSource.py. Currently:
DEP_FILESYSTEM = "FILESYSTEM"
DEP_NETWORK = "NETWORK"
When 'get_datasource_list' is called for the DataSourceOVF module with
[DEP_FILESYSTEM], then DataSourceOVF returns a single item list with a
reference to the 'DataSourceOVF' class.
When 'get_datasource_list' is called for the DataSourceOVF module with
[DEP_FILESYSTEM, DEP_NETWORK], it will return a single item list
with a reference to 'DataSourceOVFNet'.
cloudinit will then instanciate the class and call its 'get_data' method.
if the get_data method returns 'True', then it selects this class as the
selected Datasource.
Diffstat (limited to 'cloud-init.py')
-rwxr-xr-x | cloud-init.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/cloud-init.py b/cloud-init.py index 92d8a091..0902d966 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -23,6 +23,7 @@ import sys import cloudinit import cloudinit.util as util import cloudinit.CloudConfig as CC +import cloudinit.DataSource as ds import time import logging import errno @@ -32,10 +33,19 @@ def warn(wstr): def main(): cmds = ( "start", "start-local" ) + deps = { "start" : ( ds.DEP_FILESYSTEM, ds.DEP_NETWORK ), + "start-local" : ( ds.DEP_FILESYSTEM, ) } + cmd = "" if len(sys.argv) > 1: cmd = sys.argv[1] + cfg_path = None + if len(sys.argv) > 2: + # this is really for debugging only + # but you can invoke on development system with ./config/cloud.cfg + cfg_path = sys.argv[2] + if not cmd in cmds: sys.stderr.write("bad command %s. use one of %s\n" % (cmd, cmds)) sys.exit(1) @@ -49,12 +59,17 @@ def main(): warn("unable to open /proc/uptime\n") uptime = "na" - source_type = "all" - if cmd == "start-local": - source_type = "local" + try: + cfg = cloudinit.get_base_cfg(cfg_path) + except Exception as e: + warn("Failed to get base config. falling back to builtin: %s\n" % e) + try: + cfg = cloudinit.get_builtin_cfg() + except Exception as e: + warn("Unable to load builtin config\n") + raise try: - cfg = cloudinit.get_base_cfg() (outfmt, errfmt) = CC.get_output_cfg(cfg,"init") CC.redirect_output(outfmt, errfmt) except Exception as e: @@ -80,7 +95,7 @@ def main(): if cmd == "start-local": cloudinit.purge_cache() - cloud = cloudinit.CloudInit(source_type=source_type) + cloud = cloudinit.CloudInit(ds_deps=deps[cmd]) try: cloud.get_data_source() |