summaryrefslogtreecommitdiff
path: root/cloudinit/DataSource.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2011-02-07 13:05:34 -0500
committerScott Moser <smoser@ubuntu.com>2011-02-07 13:05:34 -0500
commit0bb0a6a8fddbce3dafba92ea836e73eea79266d8 (patch)
tree1e6a5e7ff97c117e9e629286b14579e8eda0395a /cloudinit/DataSource.py
parentc0e2f8d39e2581335390561e7d8a4d8deefd7e56 (diff)
downloadvyos-cloud-init-0bb0a6a8fddbce3dafba92ea836e73eea79266d8.tar.gz
vyos-cloud-init-0bb0a6a8fddbce3dafba92ea836e73eea79266d8.zip
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.
Diffstat (limited to 'cloudinit/DataSource.py')
-rw-r--r--cloudinit/DataSource.py22
1 files 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: