Beispiel #1
0
 def transform(self):
     value = self.value
     object_store = helpers.get_object_store()
     if isinstance(self.value, contracts.ObjRef):
         value = self.value.object_id
     if value is None:
         return None
     if isinstance(value, dsl_types.MuranoObject):
         obj = value
     elif isinstance(value, dsl_types.MuranoObjectInterface):
         obj = value.object
     elif isinstance(value, utils.MappingType):
         obj = object_store.load(value,
                                 self.owner,
                                 context=self.root_context,
                                 default_type=self.default_type,
                                 scope_type=self.calling_type)
     elif isinstance(value, str):
         obj = object_store.get(value)
         if obj is None:
             if not object_store.initializing:
                 raise exceptions.NoObjectFoundError(value)
             else:
                 return contracts.ObjRef(value)
     else:
         raise exceptions.ContractViolationException(
             'Value {0} cannot be represented as class {1}'.format(
                 helpers.format_scalar(value), self.type))
     self.value = obj
     return self.validate()
Beispiel #2
0
 def class_(value, name, default_name=None, version_spec=None):
     object_store = None if this is None else this.object_store
     if not default_name:
         default_name = name
     murano_class = name.type
     if value is None:
         return None
     if isinstance(value, dsl_types.MuranoObject):
         obj = value
     elif isinstance(value, dsl_types.MuranoObjectInterface):
         obj = value.object
     elif isinstance(value, utils.MappingType):
         obj = helpers.instantiate(
             value, owner, object_store, root_context,
             calling_type, default_name)
     elif isinstance(value, six.string_types) and object_store:
         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(
                 format_scalar(value), name))
     if not helpers.is_instance_of(
             obj, murano_class.name,
             version_spec or helpers.get_type(root_context)):
         raise exceptions.ContractViolationException(
             'Object of type {0} is not compatible with '
             'requested type {1}'.format(obj.type.name, name))
     return obj
Beispiel #3
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
        def class_(value, name, default_name=None, version_spec=None):
            object_store = this.object_store
            if not default_name:
                default_name = name
            murano_class = name.murano_class
            if value is None:
                return None
            if isinstance(value, dsl_types.MuranoObject):
                obj = value
            elif isinstance(value, dsl_types.MuranoObjectInterface):
                obj = value.object
            elif isinstance(value, utils.MappingType):
                if '?' not in value:
                    new_value = {
                        '?': {
                            'id': uuid.uuid4().hex,
                            'type': default_name.murano_class.name,
                            'classVersion':
                            str(default_name.murano_class.version)
                        }
                    }
                    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(
                        format_scalar(value), name))
            if not helpers.is_instance_of(
                    obj, murano_class.name, version_spec
                    or helpers.get_type(root_context)):
                raise exceptions.ContractViolationException(
                    'Object of type {0} is not compatible with '
                    'requested type {1}'.format(obj.type.name, name))
            return obj