summaryrefslogtreecommitdiff
path: root/cloudinit/sources
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2012-06-20 23:40:00 -0700
committerJoshua Harlow <harlowja@yahoo-inc.com>2012-06-20 23:40:00 -0700
commit95e0fa29af3656c1011c41ab0f35dc4e9317269c (patch)
treedd36e2a58478639733d114f452bf36f0af780803 /cloudinit/sources
parentd0ff82b71e315d49f49cbbd8e6a7740036973a4a (diff)
downloadvyos-cloud-init-95e0fa29af3656c1011c41ab0f35dc4e9317269c.tar.gz
vyos-cloud-init-95e0fa29af3656c1011c41ab0f35dc4e9317269c.zip
1. Add an importer function that will search for a given module in a set of search module 'prefixes'
that also has a potential set of required attributes. 2. Use this new importer to find the distro class, the userdata handler modules, the config modules and the datasource modules, if none can be found error out accordingly.
Diffstat (limited to 'cloudinit/sources')
-rw-r--r--cloudinit/sources/__init__.py34
1 files changed, 11 insertions, 23 deletions
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py
index 8ab7cf54..42e924b0 100644
--- a/cloudinit/sources/__init__.py
+++ b/cloudinit/sources/__init__.py
@@ -191,31 +191,19 @@ def list_sources(cfg_list, depends, pkg_list):
LOG.info(("Looking for for data source in: %s,"
" via packages %s that matches dependencies %s"),
cfg_list, pkg_list, depends)
- for ds_coll in cfg_list:
- ds_name = str(ds_coll)
+ for ds_name in cfg_list:
if not ds_name.startswith(DS_PREFIX):
ds_name = '%s%s' % (DS_PREFIX, ds_name)
- for pkg in pkg_list:
- pkg_name = []
- if pkg:
- # Any package name given, this affects
- # the lookup path
- pkg_name.append(str(pkg))
- pkg_name.append(ds_name)
- try:
- mod = importer.import_module(".".join(pkg_name))
- except ImportError:
- continue
- lister = getattr(mod, "get_datasource_list", None)
- if not lister:
- continue
- cls_matches = lister(depends)
- if not cls_matches:
- continue
- src_list.extend(cls_matches)
- LOG.debug(("Found a match"
- " in %s with matches %s"), mod, cls_matches)
- break
+ m_locs = importer.find_module(ds_name,
+ pkg_list,
+ ['get_datasource_list'])
+ for m_loc in m_locs:
+ mod = importer.import_module(m_loc)
+ lister = getattr(mod, "get_datasource_list")
+ matches = lister(depends)
+ if matches:
+ src_list.extend(matches)
+ break
return src_list