diff options
author | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-18 21:07:17 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@yahoo-inc.com> | 2012-06-18 21:07:17 -0700 |
commit | 8c9148fda19a83bb6fe9476dff34788ccfc9f639 (patch) | |
tree | c93ec2b7c1f6bc056ae70107332b1af974276de4 /cloudinit/sources | |
parent | dd3b1ffcfb11527b3be0972d668c3de37b872b72 (diff) | |
download | vyos-cloud-init-8c9148fda19a83bb6fe9476dff34788ccfc9f639.tar.gz vyos-cloud-init-8c9148fda19a83bb6fe9476dff34788ccfc9f639.zip |
1. Fixed datasource construction (switched param order)
2. Fixed up importing of modules to handle the failure case better
a. Also realized that using the import class we don't have to reimport a module via getattr, so removed that.
Diffstat (limited to 'cloudinit/sources')
-rw-r--r-- | cloudinit/sources/__init__.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/cloudinit/sources/__init__.py b/cloudinit/sources/__init__.py index 5842d41b..831f97ea 100644 --- a/cloudinit/sources/__init__.py +++ b/cloudinit/sources/__init__.py @@ -51,7 +51,7 @@ class DataSource(object): self.userdata_raw = None name = util.obj_name(self) if name.startswith(DS_PREFIX): - name = name[DS_PREFIX:] + name = name[len(DS_PREFIX):] self.ds_cfg = util.get_cfg_by_path(self.sys_cfg, ("datasource", name), {}) if not ud_proc: @@ -171,7 +171,7 @@ def find_source(sys_cfg, distro, paths, ds_deps, cfg_list, pkg_list): for cls in ds_list: ds = util.obj_name(cls) try: - s = cls(distro, sys_cfg, paths) + s = cls(sys_cfg, distro, paths) if s.get_data(): return (s, ds) except Exception: @@ -198,15 +198,13 @@ def list_sources(cfg_list, depends, pkg_list): if pkg: pkg_name.append(str(pkg)) pkg_name.append(ds_name) - mod = importer.import_module(".".join(pkg_name)) - if pkg: - mod = getattr(mod, ds_name, None) - if not mod: + try: + mod = importer.import_module(".".join(pkg_name)) + except RuntimeError: continue lister = getattr(mod, "get_datasource_list", None) if not lister: continue - LOG.debug("Seeing if %s matches using function %s", mod, lister) cls_matches = lister(depends) if not cls_matches: continue |