Пример #1
0
 def __init__(self, name, template, entity_name, custom_def=None):
     self.name = name
     self.entity_tpl = template
     self.custom_def = custom_def
     self._validate_field(self.entity_tpl)
     type = self.entity_tpl.get('type')
     UnsupportedType.validate_type(type)
     if entity_name == 'node_type':
         self.type_definition = NodeType(type, custom_def) \
             if type is not None else None
     if entity_name == 'relationship_type':
         relationship = template.get('relationship')
         type = None
         if relationship and isinstance(relationship, dict):
             type = relationship.get('type')
         elif isinstance(relationship, str):
             type = self.entity_tpl['relationship']
         else:
             type = self.entity_tpl['type']
         UnsupportedType.validate_type(type)
         self.type_definition = RelationshipType(type, None, custom_def)
     if entity_name == 'policy_type':
         if not type:
             msg = (_('Policy definition of "%(pname)s" must have'
                      ' a "type" '
                      'attribute.') % dict(pname=name))
             ExceptionCollector.appendException(ValidationError(msg))
         self.type_definition = PolicyType(type, custom_def)
     if entity_name == 'group_type':
         self.type_definition = GroupType(type, custom_def) \
             if type is not None else None
     self._properties = None
     self._interfaces = None
     self._requirements = None
     self._capabilities = None
Пример #2
0
    def __init__(self, name, template, entity_name, custom_def=None):
        self.name = name
        self.entity_tpl = template
        self.custom_def = custom_def
        self._validate_field(self.entity_tpl)
        type = self.entity_tpl.get('type')
        UnsupportedType.validate_type(type)
        if '__typename' not in template:
            self._validate_fields(template)
        if entity_name == 'node_type':
            self.type_definition = NodeType(type, custom_def) \
                if type is not None else None
            self._validate_directives(self.entity_tpl)
        if entity_name == 'relationship_type':
            self.type_definition = RelationshipType(type, custom_def)
        if entity_name == 'policy_type':
            if not type:
                msg = (_('Policy definition of "%(pname)s" must have'
                         ' a "type" '
                         'attribute.') % dict(pname=name))
                ExceptionCollector.appendException(
                    ValidationError(message=msg))
            self.type_definition = PolicyType(type, custom_def)
        if entity_name == 'group_type':
            self.type_definition = GroupType(type, custom_def) \
                if type is not None else None
        if entity_name == 'artifact_type':
            self.type_definition = ArtifactTypeDef(type, custom_def) \
                if type is not None else None

        self._properties = None
        self._interfaces = None
        self._requirements = None
        self._capabilities = None
        if not self.type_definition:
            msg = "no type found %s for %s" % (entity_name, template)
            ExceptionCollector.appendException(ValidationError(message=msg))
            return
        metadata = self.type_definition.get_definition('metadata')
        if metadata and 'additionalProperties' in metadata:
            self.additionalProperties = metadata['additionalProperties']

        self._properties_tpl = self._validate_properties()
        for prop in self.get_properties_objects():
            prop.validate()
        self._validate_interfaces()
Пример #3
0
    def __init__(self, name, template, entity_name, custom_def=None):
        self.name = name
        self.entity_tpl = template
        self.custom_def = custom_def
        self._validate_field(self.entity_tpl)
        type = self.entity_tpl.get('type')
        UnsupportedType.validate_type(type)
        if entity_name == 'node_type':
            self.type_definition = NodeType(type, custom_def) \
                if type is not None else None
        if entity_name == 'relationship_type':
            relationship = template.get('relationship')
            type = None
            if relationship and isinstance(relationship, dict):
                type = relationship.get('type')
            elif isinstance(relationship, str):
                type = self.entity_tpl['relationship']
            else:
                type = self.entity_tpl['type']
            UnsupportedType.validate_type(type)
            self.type_definition = RelationshipType(type,
                                                    None, custom_def)
        if entity_name == 'policy_type':
            if not type:
                msg = (_('Policy definition of "%(pname)s" must have'
                       ' a "type" ''attribute.') % dict(pname=name))
                ExceptionCollector.appendException(
                    ValidationError(msg))

            self.type_definition = PolicyType(type, custom_def)
        if entity_name == 'group_type':
            self.type_definition = GroupType(type, custom_def) \
                if type is not None else None
        self._properties = None
        self._interfaces = None
        self._requirements = None
        self._capabilities = None
Пример #4
0
 def __init__(self, entitytype, prefix, custom_def=None):
     entire_entitytype = entitytype
     if UnsupportedType.validate_type(entire_entitytype):
         self.defs = None
     else:
         if entitytype.startswith(self.TOSCA + ":"):
             entitytype = entitytype[(len(self.TOSCA) + 1):]
             entire_entitytype = prefix + entitytype
         if not entitytype.startswith(self.TOSCA):
             entire_entitytype = prefix + entitytype
         if custom_def and entitytype in list(custom_def.keys()):
             self.defs = custom_def[entitytype]
         elif entire_entitytype in list(self.TOSCA_DEF.keys()):
             self.defs = self.TOSCA_DEF[entire_entitytype]
             entitytype = entire_entitytype
         else:
             self.defs = None
             ExceptionCollector.appendException(
                 InvalidTypeError(what=entitytype))
     self.type = entitytype
Пример #5
0
 def __init__(self, entitytype, prefix, custom_def=None):
     entire_entitytype = entitytype
     if UnsupportedType.validate_type(entire_entitytype):
         self.defs = None
     else:
         if entitytype.startswith(self.TOSCA + ":"):
             entitytype = entitytype[(len(self.TOSCA) + 1):]
             entire_entitytype = prefix + entitytype
         if not entitytype.startswith(self.TOSCA):
             entire_entitytype = prefix + entitytype
         if entire_entitytype in list(self.TOSCA_DEF.keys()):
             self.defs = self.TOSCA_DEF[entire_entitytype]
             entitytype = entire_entitytype
         elif custom_def and entitytype in list(custom_def.keys()):
             self.defs = custom_def[entitytype]
         else:
             self.defs = None
             ExceptionCollector.appendException(
                 InvalidTypeError(what=entitytype))
     self.type = entitytype
Пример #6
0
 def __init__(self, entitytype, prefix, custom_def=None):
     entire_entitytype = entitytype
     if UnsupportedType.validate_type(entire_entitytype):
         self.defs = None
     else:
         if entitytype.startswith(self.TOSCA + ":"):
             entitytype = entitytype[(len(self.TOSCA) + 1):]
             entire_entitytype = prefix + entitytype
         if not entitytype.startswith(self.TOSCA):
             entire_entitytype = prefix + entitytype
         if custom_def and entitytype in custom_def:
             self.defs = custom_def[entitytype]
         elif entire_entitytype in self.TOSCA_DEF:
             self.defs = self.TOSCA_DEF[entire_entitytype]
             entitytype = entire_entitytype
         elif entitytype in self.TOSCA_DEF:
             self.defs = self.TOSCA_DEF[entitytype]
         else:
             self.defs = None
             ExceptionCollector.appendException(
                 MissingTypeError(what=entitytype))
     self.type = entitytype
     self._source = self.defs and self.defs.get('_source') or None