def get_class_by_endpoint(self, name, version=None): if version is None: classlist = self._get_plugins(name, spec="by_endpoint") if not classlist: raise exception.ArtifactPluginNotFound(name=name) return self._find_class_in_collection(classlist, name) return self._find_class_in_collection( self._get_plugins(name, spec="by_endpoint"), name, version)
def _find_class_in_collection(self, collection, name, version=None): try: def _cmp_version(plugin, version): ver = semantic_version.Version.coerce return (ver(plugin.metadata.type_version) == ver(version)) if version: return next((p for p in collection if _cmp_version(p, version))) return next((p for p in collection)) except StopIteration: raise exception.ArtifactPluginNotFound( name="%s %s" % (name, "v %s" % version if version else ""))