Exemplo n.º 1
0
    def find_class(self, name, search_requirements=True):
        payload = self._native_load_queue.pop(name, None)
        if payload is not None:
            return self._register_native_class(payload, name)

        payload = self._load_queue.pop(name, None)
        if payload is not None:
            result = self._register_mpl_classes(payload, name)
            if result:
                return result

        result = self._classes.get(name)
        if result:
            return result
        if search_requirements:
            pkgs_for_search = []
            for package_name, version_spec in six.iteritems(
                    self._requirements):
                if package_name == self.name:
                    continue
                referenced_package = self._package_loader.load_package(
                    package_name, version_spec)
                try:
                    return referenced_package.find_class(name, False)
                except exceptions.NoClassFound:
                    pkgs_for_search.append(referenced_package)
                    continue
            raise exceptions.NoClassFound(name,
                                          packages=pkgs_for_search + [self])

        raise exceptions.NoClassFound(name, packages=[self])
Exemplo n.º 2
0
    def find_class(self, name, search_requirements=True):
        payload = self._native_load_queue.pop(name, None)
        if payload is not None:
            return self._register_native_class(payload, name)

        payload = self._load_queue.pop(name, None)
        if payload is not None:
            result = self._register_mpl_classes(payload, name)
            if result:
                return result

        result = self._classes.get(name)
        if result:
            return result
        if search_requirements:
            pkgs_for_search = []
            for package_name, version_spec in six.iteritems(
                    self._requirements):
                if package_name == self.name:
                    continue
                referenced_package = self._package_loader.load_package(
                    package_name, version_spec)
                try:
                    return referenced_package.find_class(name, False)
                except exceptions.NoClassFound:
                    if name.startswith('io.murano.extensions'):
                        try:
                            short_name = name.replace('io.murano.extensions.',
                                                      '', 1)
                            result = referenced_package.find_class(
                                short_name, False)
                            warnings.simplefilter("once")
                            msg = ("Plugin %(name)s was not found, but a "
                                   "%(shorter_name)s was found instead and "
                                   "will be used. This could be caused by "
                                   "recent change in plugin naming scheme. If "
                                   "you are developing applications targeting "
                                   "this plugin consider changing its name" % {
                                       'name': name,
                                       'shorter_name': short_name
                                   })
                            debtcollector.deprecate(msg)
                            return result
                        except exceptions.NoClassFound:
                            pass
                    pkgs_for_search.append(referenced_package)
                    continue
            raise exceptions.NoClassFound(name,
                                          packages=pkgs_for_search + [self])

        raise exceptions.NoClassFound(name, packages=[self])
Exemplo n.º 3
0
 def load_definition(self, name):
     try:
         return self._classes[name]
     except KeyError:
         if self._parent:
             return self._parent.load_definition(name)
         raise exceptions.NoClassFound(name)
Exemplo n.º 4
0
    def find_class(self, name, search_requirements=True):
        payload = self._native_load_queue.pop(name, None)
        if payload is not None:
            return self._register_native_class(payload, name)

        payload = self._load_queue.pop(name, None)
        if payload is not None:
            if callable(payload):
                payload = payload()
            return self._register_mpl_class(payload, name)

        result = self._classes.get(name)
        if result:
            return result

        if search_requirements:
            for package_name, version_spec in self._requirements.iteritems():
                if package_name == self.name:
                    continue
                referenced_package = self._package_loader.load_package(
                    package_name, version_spec)
                try:
                    return referenced_package.find_class(name, False)
                except exceptions.NoClassFound:
                    continue
        raise exceptions.NoClassFound(name)
Exemplo n.º 5
0
        def _class2(value, name, default_name):
            name = namespace_resolver.resolve_name(name)
            if not default_name:
                default_name = name
            else:
                default_name = namespace_resolver.resolve_name(default_name)
            value = value()
            class_loader = murano.dsl.helpers.get_class_loader(root_context)
            murano_class = class_loader.get_class(name)
            if not murano_class:
                raise exceptions.NoClassFound(
                    'Class {0} cannot be found'.format(name))
            if value is None:
                return None
            if isinstance(value, murano.dsl.murano_object.MuranoObject):
                obj = value
            elif isinstance(value, types.DictionaryType):
                if '?' not in value:
                    new_value = {
                        '?': {
                            'id': uuid.uuid4().hex,
                            'type': default_name
                        }
                    }
                    new_value.update(value)
                    value = new_value

                obj = object_store.load(value,
                                        owner,
                                        root_context,
                                        defaults=default)
            elif isinstance(value, types.StringTypes):
                obj = object_store.get(value)
                if obj is None:
                    if not object_store.initializing:
                        raise exceptions.NoObjectFoundError(value)
                    else:
                        return TypeScheme.ObjRef(value)
            else:
                raise exceptions.ContractViolationException(
                    'Value {0} cannot be represented as class {1}'.format(
                        value, name))
            if not murano_class.is_compatible(obj):
                raise exceptions.ContractViolationException(
                    'Object of type {0} is not compatible with '
                    'requested type {1}'.format(obj.type.name, name))
            return obj