summaryrefslogtreecommitdiff
path: root/cloudinit/sources
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-07-31 15:23:04 +0000
committerScott Moser <smoser@ubuntu.com>2015-07-31 15:23:04 +0000
commitcc923ca255f4ce8c23819e263066e34133f3dd31 (patch)
tree0ce69f535f7224a9fd0e1c570884b481bbbb33f0 /cloudinit/sources
parentb22302d8e2b539f61faede7efb3a163966bf170a (diff)
downloadvyos-cloud-init-cc923ca255f4ce8c23819e263066e34133f3dd31.tar.gz
vyos-cloud-init-cc923ca255f4ce8c23819e263066e34133f3dd31.zip
add nicer formating and messages for datasource searching
Diffstat (limited to 'cloudinit/sources')
-rw-r--r--cloudinit/sources/__init__.py33
1 files changed, 27 insertions, 6 deletions
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index f585c3e4..c174a58f 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -247,22 +247,43 @@ def normalize_pubkey_data(pubkey_data):
return keys
+class SearchReportStack(reporting.ReportStack):
+ def __init__(self, source, ds_deps, parent):
+ self.source = source.replace("DataSource", "")
+ name = "check-%s" % self.source
+ self.found = False
+ self.mode = "network" if DEP_NETWORK in ds_deps else "local"
+ description = "searching for %s data from %s" % (
+ self.mode, self.source)
+ super(SearchReportStack, self).__init__(
+ name=name, description=description, parent=parent,
+ exc_result=reporting.status.WARN)
+
+ def finish_info(self, exc):
+ # return tuple of description, and value
+ if exc:
+ # by default, exceptions are fatal
+ return (self.exc_result, self.description)
+ if self.found:
+ description = "found %s data from %s" % (self.mode, self.source)
+ else:
+ description = "no %s data found from %s" % (self.mode, self.source)
+ return self.childrens_finish_info(description=description)
+
+
def find_source(sys_cfg, distro, paths, ds_deps, cfg_list, pkg_list, reporter):
ds_list = list_sources(cfg_list, ds_deps, pkg_list)
ds_names = [type_utils.obj_name(f) for f in ds_list]
LOG.debug("Searching for data source in: %s", ds_names)
for i, cls in enumerate(ds_list):
- name=ds_names[i].replace("DataSource", "")
- myreporter = reporting.ReportStack(
- "check-%s" % name, "searching for %s" % name,
- parent=reporter, exc_result=reporting.status.WARN)
-
+ srcname=ds_names[i]
try:
- with myreporter:
+ with SearchReportStack(srcname, ds_deps, reporter) as rep:
LOG.debug("Seeing if we can get any data from %s", cls)
s = cls(sys_cfg, distro, paths)
if s.get_data():
+ rep.found = True
return (s, type_utils.obj_name(cls))
except Exception:
util.logexc(LOG, "Getting data from %s failed", cls)