summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-16 08:55:39 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-16 08:55:39 -0700
commit95573f9d7aa53d9f4c5ba5e969775f9bc59cb5ae (patch)
tree7fcafefec84ba1717e2333ff8d0f01a3c9deb1bc /cloudinit
parent13e1b680838615d8d54657641f84e6247ef5aea6 (diff)
downloadvyos-cloud-init-95573f9d7aa53d9f4c5ba5e969775f9bc59cb5ae.tar.gz
vyos-cloud-init-95573f9d7aa53d9f4c5ba5e969775f9bc59cb5ae.zip
Adjust how config is extracted in that it now can be extracted via 3 different modes.
1. Restricted - which doesn't give back the system info (used by handlers/transforms/public cfg api) 2. System - which only gives back the system info (used by distro class) 3. Paths - gives back only the system/path info (used by the path class)
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/stages.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/cloudinit/stages.py b/cloudinit/stages.py
index b9076881..63b7cf12 100644
--- a/cloudinit/stages.py
+++ b/cloudinit/stages.py
@@ -76,15 +76,8 @@ class Init(object):
@property
def distro(self):
if not self._distro:
- d_cfg = util.get_cfg_by_path(self.cfg, ('system_info'), {})
- # Ensure its a dictionary
- if not isinstance(d_cfg, (dict)):
- d_cfg = {}
- # Ensure not modified indirectly
- d_cfg = copy.deepcopy(d_cfg)
- # Remove this since its path config, not distro config
- d_cfg.pop('paths', None)
# Try to find the right class to use
+ d_cfg = self._extract_cfg('system')
distro_name = d_cfg.pop('distro', 'ubuntu')
distro_cls = distros.fetch(distro_name)
LOG.debug("Using distro class %s", distro_cls)
@@ -95,19 +88,29 @@ class Init(object):
@property
def cfg(self):
+ return self._extract_cfg('restricted')
+
+ def _extract_cfg(self, restriction):
# None check so that we don't keep on re-loading if empty
if self._cfg is None:
self._cfg = self._read_cfg()
LOG.debug("Loading init config %s", self._cfg)
- return self._cfg
+ # Nobody gets the real config
+ ocfg = copy.deepcopy(self._cfg)
+ if restriction == 'restricted':
+ ocfg.pop('system_info', None)
+ elif restriction == 'system':
+ ocfg = util.get_cfg_by_path(ocfg, ('system_info',), {})
+ elif restriction == 'paths':
+ ocfg = util.get_cfg_by_path(ocfg, ('system_info', 'paths'), {})
+ if not isinstance(ocfg, (dict)):
+ ocfg = {}
+ return ocfg
@property
def paths(self):
if not self._paths:
- path_info = util.get_cfg_by_path(self.cfg,
- ('system_info', 'paths'), {})
- # Ensure not modified indirectly
- path_info = copy.deepcopy(path_info)
+ path_info = self._extract_cfg('paths')
self._paths = helpers.Paths(path_info, self.datasource)
return self._paths