From dc5e7116e663d3b5cad165fcac8b3141f8ffbc05 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Wed, 26 Jan 2011 18:43:50 +0000 Subject: 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 and, failing that, DataSource 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. --- cloudinit/DataSourceOVF.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'cloudinit/DataSourceOVF.py') diff --git a/cloudinit/DataSourceOVF.py b/cloudinit/DataSourceOVF.py index 3fba878b..31d0c407 100644 --- a/cloudinit/DataSourceOVF.py +++ b/cloudinit/DataSourceOVF.py @@ -18,7 +18,7 @@ import DataSource -import cloudinit +from cloudinit import seeddir import cloudinit.util as util import sys import os.path @@ -33,16 +33,13 @@ import subprocess class DataSourceOVF(DataSource.DataSource): seed = None - seeddir = cloudinit.seeddir + '/ovf' + seeddir = seeddir + '/ovf' environment = None cfg = { } userdata_raw = None metadata = None supported_seed_starts = ( "/" , "file://" ) - def __init__(self): - pass - def __str__(self): mstr="DataSourceOVF" mstr = mstr + " [seed=%s]" % self.seed @@ -90,12 +87,12 @@ class DataSourceOVF(DataSource.DataSource): seedfound = proto break if not seedfound: - cloudinit.log.debug("seed from %s not supported by %s" % + self.log.debug("seed from %s not supported by %s" % (seedfrom, self.__class__)) return False (md_seed,ud) = util.read_seeded(seedfrom) - cloudinit.log.debug("using seeded cache data from %s" % seedfrom) + self.log.debug("using seeded cache data from %s" % seedfrom) md = util.mergedict(md,md_seed) found.append(seedfrom) @@ -122,7 +119,7 @@ class DataSourceOVF(DataSource.DataSource): return(self.cfg) class DataSourceOVFNet(DataSourceOVF): - seeddir = cloudinit.seeddir + '/ovf-net' + seeddir = seeddir + '/ovf-net' supported_seed_starts = ( "http://", "https://", "ftp://" ) # this will return a dict with some content @@ -283,6 +280,16 @@ def getProperties(environString): return(props) +datasources = ( + ( DataSourceOVF, ( DataSource.DEP_FILESYSTEM, ) ), + ( DataSourceOVFNet, + ( DataSource.DEP_FILESYSTEM, DataSource.DEP_NETWORK ) ), +) + +# return a list of data sources that match this set of dependencies +def get_datasource_list(depends): + return(DataSource.list_from_depends(depends, datasources)) + if __name__ == "__main__": import sys envStr = open(sys.argv[1]).read() -- cgit v1.2.3