diff options
author | Scott Moser <smoser@brickies.net> | 2017-03-01 15:50:40 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-03-03 01:30:15 -0500 |
commit | 79db2e2436d91510aceb8c036c4a945362c85a52 (patch) | |
tree | f26de3248c4d43d5935dd7c42750a08a7f43f804 /cloudinit/cmd/main.py | |
parent | 51a24555e5e7af709caa8dab1a5e6c7e7f317b17 (diff) | |
download | vyos-cloud-init-79db2e2436d91510aceb8c036c4a945362c85a52.tar.gz vyos-cloud-init-79db2e2436d91510aceb8c036c4a945362c85a52.zip |
Support warning if the used datasource is not in ds-identify's list.
If ds-identify is in report mode, and the datasource that is found
is not in the list, then warn the user of this situation.
Diffstat (limited to 'cloudinit/cmd/main.py')
-rw-r--r-- | cloudinit/cmd/main.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/cloudinit/cmd/main.py b/cloudinit/cmd/main.py index 7c652574..6ff4e1c0 100644 --- a/cloudinit/cmd/main.py +++ b/cloudinit/cmd/main.py @@ -29,6 +29,7 @@ from cloudinit import templater from cloudinit import url_helper from cloudinit import util from cloudinit import version +from cloudinit import warnings from cloudinit import reporting from cloudinit.reporting import events @@ -413,10 +414,48 @@ def main_init(name, args): # give the activated datasource a chance to adjust init.activate_datasource() + di_report_warn(datasource=init.datasource, cfg=init.cfg) + # Stage 10 return (init.datasource, run_module_section(mods, name, name)) +def di_report_warn(datasource, cfg): + if 'di_report' not in cfg: + LOG.debug("no di_report found in config.") + return + + dicfg = cfg.get('di_report', {}) + if not isinstance(dicfg, dict): + LOG.warn("di_report config not a dictionary: %s", dicfg) + return + + dslist = dicfg.get('datasource_list') + if dslist is None: + LOG.warn("no 'datasource_list' found in di_report.") + return + elif not isinstance(dslist, list): + LOG.warn("di_report/datasource_list not a list: %s", dslist) + return + + # ds.__module__ is like cloudinit.sources.DataSourceName + # where Name is the thing that shows up in datasource_list. + modname = datasource.__module__.rpartition(".")[2] + if modname.startswith(sources.DS_PREFIX): + modname = modname[len(sources.DS_PREFIX):] + else: + LOG.warn("Datasource '%s' came from unexpected module '%s'.", + datasource, modname) + + if modname in dslist: + LOG.debug("used datasource '%s' from '%s' was in di_report's list: %s", + datasource, modname, dslist) + return + + warnings.show_warning('dsid_missing_source', cfg, + source=modname, dslist=str(dslist)) + + def main_modules(action_name, args): name = args.mode # Cloud-init 'modules' stages are broken up into the following sub-stages |