From 0bb0a6a8fddbce3dafba92ea836e73eea79266d8 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Mon, 7 Feb 2011 13:05:34 -0500 Subject: add sys_cfg option to DataSource:__init__ , populate ds_cfg from it In order to be able to configure a DataSource via system config (ie, what is in /etc/cloud/cloud.cfg), we pass this into the DataSource class. The DataSource parent class will set up the 'ds_cfg' member based on the subclass name. So, DataSourceEc2 will get: self.ds_cfg = sys_cfg['datasource']['Ec2'] populated for it. --- cloudinit/DataSource.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/cloudinit/DataSource.py b/cloudinit/DataSource.py index 0bf17b45..350b5015 100644 --- a/cloudinit/DataSource.py +++ b/cloudinit/DataSource.py @@ -21,14 +21,30 @@ DEP_FILESYSTEM = "FILESYSTEM" DEP_NETWORK = "NETWORK" import UserDataHandler as ud +import cloudinit.util as util class DataSource: userdata = None metadata = None userdata_raw = None - - def __init__(self): - pass + cfgname = "" + # system config (passed in from cloudinit, + # cloud-config before input from the DataSource) + sys_cfg = { } + # datasource config, the cloud-config['datasource']['__name__'] + ds_cfg = { } # datasource config + + def __init__(self,sys_cfg=None): + if not self.cfgname: + name = str(self.__class__).split(".")[-1] + if name.startswith("DataSource"): + name = name[len("DataSource"):] + self.cfgname = name + if sys_cfg: + self.sys_cfg = sys_cfg + + self.ds_cfg = util.get_cfg_by_path(self.sys_cfg, + ("datasource",self.cfgname),self.ds_cfg) def get_userdata(self): if self.userdata == None: -- cgit v1.2.3