def get(cls, name, platform=None, allow_hidden=False): """Return plugin by its name for specified platform. :param name: Plugin's name or fullname :param platform: Plugin's platform :param allow_hidden: if False and found plugin is hidden then PluginNotFound is raised """ if "@" in name: name, platform = name.split("@", 1) results = cls.get_all(name=name, platform=platform, allow_hidden=allow_hidden) if not results: raise exceptions.PluginNotFound(name=name, platform=platform or "in any") if len(results) == 1: return results[0] if platform is None: # try to use default platform default = [p for p in results if p.get_platform() == "default"] if default: return default[0] raise exceptions.MultiplePluginsFound( name=name, plugins=", ".join(p.get_fullname() for p in results))
def validate(cls, config, non_hidden=False): # TODO(boris-42): This is going to be replaced with common validation # mechanism (generalization of scenario validation) if non_hidden and cls._meta_get("hidden"): raise exceptions.PluginNotFound(name=cls.get_name(), namespace="context") jsonschema.validate(config, cls.CONFIG_SCHEMA)
def get(cls, name, namespace=None): """Return plugin by its name from specified namespace. This method iterates over all subclasses of cls and returns plugin by name from specified namespace. If namespace is not specified it will return first found plugin from any of namespaces. :param name: Plugin's name :param namespace: Namespace where to search for plugins """ potential_result = [] for p in cls.get_all(namespace=namespace): if p.get_name() == name: potential_result.append(p) if len(potential_result) == 1: return potential_result[0] elif potential_result: hint = _LE("Try to choose the correct Plugin base or namespace to " "search in.") if namespace: needle = "%s at %s namespace" % (name, namespace) else: needle = "%s at any of namespaces" % name raise exceptions.MultipleMatchesFound( needle=needle, haystack=", ".join(p.get_name() for p in potential_result), hint=hint) raise exceptions.PluginNotFound( name=name, namespace=namespace or "any of")
def _get_sorted_context_lst(self): context_list = [] for ctx_name in self.context_obj["config"].keys(): # TODO(andreykurilin): move this logic to some "find" method if "@" in ctx_name: ctx_name, ctx_namespace = ctx_name.split("@", 1) context_list.append(Context.get(ctx_name, platform=ctx_namespace, fallback_to_default=False, allow_hidden=True)) else: potential_result = Context.get_all(name=ctx_name, allow_hidden=True) if len(potential_result) == 1: context_list.append(potential_result[0]) continue elif len(potential_result) > 1: scen_namespace = self.context_obj["scenario_namespace"] another_attempt = [c for c in potential_result if c.get_platform() == scen_namespace] if another_attempt: context_list.append(another_attempt[0]) continue another_attempt = [c for c in potential_result if c.get_platform() == "default"] if another_attempt: context_list.append(another_attempt[0]) continue raise exceptions.PluginNotFound(name=ctx_name, platform="any of") return sorted([ctx(self.context_obj) for ctx in context_list])
def get_engine(name, deployment): """Returns instance of a deploy engine with corresponding name.""" try: engine_cls = EngineFactory.get(name) return engine_cls(deployment) except exceptions.PluginNotFound: LOG.error(_("Deployment %(uuid)s: Deploy engine for %(name)s " "does not exist.") % {"uuid": deployment["uuid"], "name": name}) deployment.update_status(consts.DeployStatus.DEPLOY_FAILED) raise exceptions.PluginNotFound(engine_name=name)
def get(cls, name, namespace=None, allow_hidden=False, fallback_to_default=True): """Return plugin by its name from specified namespace. This method iterates over all subclasses of cls and returns plugin by name from specified namespace. If namespace is not specified, it will return first found plugin from any of namespaces. :param name: Plugin's name :param namespace: Namespace where to search for plugins :param allow_hidden: if False and found plugin is hidden then PluginNotFound will be raised :param fallback_to_default: if True, then it tries to find plugin within "default" namespace """ potential_result = cls.get_all(name=name, namespace=namespace, allow_hidden=True) if fallback_to_default and len(potential_result) == 0: # try to find in default namespace potential_result = cls.get_all(name=name, namespace="default", allow_hidden=True) if len(potential_result) == 1: plugin = potential_result[0] if allow_hidden or not plugin.is_hidden(): return plugin elif potential_result: hint = _LE("Try to choose the correct Plugin base or namespace to " "search in.") if namespace: needle = "%s at %s namespace" % (name, namespace) else: needle = "%s at any of namespaces" % name raise exceptions.MultipleMatchesFound( needle=needle, haystack=", ".join(p.get_name() for p in potential_result), hint=hint) raise exceptions.PluginNotFound(name=name, namespace=namespace or "any of")
def get(cls, name, namespace=None): """Return plugin by it's name from specified namespace. This method iterates over all subclasses of cls and returns plugin by name from specified namespace. If namespace is not specified it will return first found plugin from any of namespaces. :param name: Plugin's name :param namespace: Namespace where to search for plugins """ for p in cls.get_all(namespace=namespace): if p.get_name() == name: return p raise exceptions.PluginNotFound(name=name, namespace=namespace)