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/DataSourceEc2.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'cloudinit/DataSourceEc2.py') diff --git a/cloudinit/DataSourceEc2.py b/cloudinit/DataSourceEc2.py index 8ecb28ad..183c57b8 100644 --- a/cloudinit/DataSourceEc2.py +++ b/cloudinit/DataSourceEc2.py @@ -18,7 +18,7 @@ import DataSource -import cloudinit +from cloudinit import seeddir import cloudinit.util as util import socket import urllib2 @@ -30,10 +30,7 @@ import errno class DataSourceEc2(DataSource.DataSource): api_ver = '2009-04-04' - seeddir = cloudinit.seeddir + '/ec2' - - def __init__(self): - pass + seeddir = seeddir + '/ec2' def __str__(self): return("DataSourceEc2") @@ -43,7 +40,7 @@ class DataSourceEc2(DataSource.DataSource): if util.read_optional_seed(seedret,base=self.seeddir+ "/"): self.userdata_raw = seedret['user-data'] self.metadata = seedret['meta-data'] - cloudinit.log.debug("using seeded ec2 data in %s" % self.seeddir) + self.log.debug("using seeded ec2 data in %s" % self.seeddir) return True try: @@ -105,13 +102,13 @@ class DataSourceEc2(DataSource.DataSource): reason = "url error [%s]" % e.reason if x == 0: - cloudinit.log.warning("waiting for metadata service at %s\n" % url) + self.log.warning("waiting for metadata service at %s\n" % url) - cloudinit.log.warning(" %s [%02s/%s]: %s\n" % + self.log.warning(" %s [%02s/%s]: %s\n" % (time.strftime("%H:%M:%S",time.gmtime()), x+1, sleeps, reason)) time.sleep(sleeptime) - cloudinit.log.critical("giving up on md after %i seconds\n" % + self.log.critical("giving up on md after %i seconds\n" % int(time.time()-starttime)) return False @@ -131,7 +128,7 @@ class DataSourceEc2(DataSource.DataSource): if entname == "ephemeral" and name == "ephemeral0": found = device if found == None: - cloudinit.log.warn("unable to convert %s to a device" % name) + self.log.warn("unable to convert %s to a device" % name) return None # LP: #611137 @@ -154,7 +151,7 @@ class DataSourceEc2(DataSource.DataSource): for nto in tlist: cand = "/dev/%s%s" % (nto, short[len(nfrom):]) if os.path.exists(cand): - cloudinit.log.debug("remapped device name %s => %s" % (found,cand)) + self.log.debug("remapped device name %s => %s" % (found,cand)) return(cand) return ofound @@ -165,3 +162,11 @@ class DataSourceEc2(DataSource.DataSource): (p4 not in self.metadata or self.metadata[p4] == "")): return True return False + +datasources = [ + ( DataSourceEc2, ( 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)) -- cgit v1.2.3