def _read_cfg(self, extra_fns): no_cfg_paths = helpers.Paths({}, self.datasource) merger = helpers.ConfigMerger(paths=no_cfg_paths, datasource=self.datasource, additional_fns=extra_fns, base_cfg=fetch_base_config()) return merger.cfg
def _consume_vendordata(self, vendor_source, frequency=PER_INSTANCE): """ Consume the vendordata and run the part handlers on it """ # User-data should have been consumed first. # So we merge the other available cloud-configs (everything except # vendor provided), and check whether or not we should consume # vendor data at all. That gives user or system a chance to override. if vendor_source == 'vendordata': if not self.datasource.get_vendordata_raw(): LOG.debug("no vendordata from datasource") return cfg_name = 'vendor_data' elif vendor_source == 'vendordata2': if not self.datasource.get_vendordata2_raw(): LOG.debug("no vendordata2 from datasource") return cfg_name = 'vendor_data2' else: raise RuntimeError("vendor_source arg must be either 'vendordata'" " or 'vendordata2'") _cc_merger = helpers.ConfigMerger(paths=self._paths, datasource=self.datasource, additional_fns=[], base_cfg=self.cfg, include_vendor=False) vdcfg = _cc_merger.cfg.get(cfg_name, {}) if not isinstance(vdcfg, dict): vdcfg = {'enabled': False} LOG.warning("invalid %s setting. resetting to: %s", cfg_name, vdcfg) enabled = vdcfg.get('enabled') no_handlers = vdcfg.get('disabled_handlers', None) if not util.is_true(enabled): LOG.debug("%s consumption is disabled.", vendor_source) return LOG.debug("%s will be consumed. disabled_handlers=%s", vendor_source, no_handlers) # Ensure vendordata source fetched before activation (just in case.) # c_handlers_list keeps track of all the active handlers, while # excluding what the users doesn't want run, i.e. boot_hook, # cloud_config, shell_script if vendor_source == 'vendordata': vendor_data_msg = self.datasource.get_vendordata() c_handlers_list = self._default_vendordata_handlers() else: vendor_data_msg = self.datasource.get_vendordata2() c_handlers_list = self._default_vendordata2_handlers() # Run the handlers self._do_handlers(vendor_data_msg, c_handlers_list, frequency, excluded=no_handlers)
def cfg(self): # None check to avoid empty case causing re-reading if self._cached_cfg is None: merger = helpers.ConfigMerger(paths=self.init.paths, datasource=self.init.datasource, additional_fns=self.cfg_files, base_cfg=self.init.cfg) self._cached_cfg = merger.cfg # LOG.debug("Loading 'module' config %s", self._cached_cfg) # Only give out a copy so that others can't modify this... return copy.deepcopy(self._cached_cfg)