Ejemplo n.º 1
0
 def validate_type(self, input_type):
     TOSCAException.set_context("input", self.name)
     if input_type not in Schema.PROPERTY_TYPES and \
         input_type not in self.custom_defs:
         log.error("Invalid type {}: {}, schema: {}".format(
             self.name, input_type, Schema.PROPERTY_TYPES))
         ExceptionCollector.appendException(
             ValueError(_('Invalid type "%s".') % input_type))
     TOSCAException.reset_context()
Ejemplo n.º 2
0
 def _load_status_attr_from_schema(self):
     # IF 'status' keyname exists verify it's a valid value,
     # if so override default
     if self.PROPERTY_KEYNAME_STATUS in self.schema:
         value = self.schema[self.PROPERTY_KEYNAME_STATUS]
         if value in self.VALID_STATUS_VALUES:
             self._status = value
         else:
             valid_values = ", ".join(self.VALID_STATUS_VALUES)
             attr = self.PROPERTY_KEYNAME_STATUS
             TOSCAException.generate_inv_schema_property_error(self, attr, value, valid_values)
Ejemplo n.º 3
0
 def _load_required_attr_from_schema(self):
     # IF 'required' keyname exists verify it's a boolean,
     # if so override default
     if self.PROPERTY_KEYNAME_REQUIRED in self.schema:
         value = self.schema[self.PROPERTY_KEYNAME_REQUIRED]
         if isinstance(value, bool):
             self._required = value
         else:
             valid_values = ", ".join(self.VALID_REQUIRED_VALUES)
             attr = self.PROPERTY_KEYNAME_REQUIRED
             TOSCAException.generate_inv_schema_property_error(self, attr, value, valid_values)
Ejemplo n.º 4
0
 def _validate_capabilities(self):
     type_capabilities = self.type_definition.get_capabilities()
     allowed_caps = \
         type_capabilities.keys() if type_capabilities else []
     capabilities = self.type_definition.get_value(self.CAPABILITIES,
                                                   self.entity_tpl)
     if capabilities:
         TOSCAException.set_context("capabilities", self.name)
         self._common_validate_field(capabilities, allowed_caps,
                                     'capabilities')
         self._validate_capabilities_properties(capabilities)
     TOSCAException.reset_context()
 def _load_status_attr_from_schema(self):
     # IF 'status' keyname exists verify it's a valid value,
     # if so override default
     if self.PROPERTY_KEYNAME_STATUS in self.schema:
         value = self.schema[self.PROPERTY_KEYNAME_STATUS]
         if value in self.VALID_STATUS_VALUES:
             self._status = value
         else:
             valid_values = ', '.join(self.VALID_STATUS_VALUES)
             attr = self.PROPERTY_KEYNAME_STATUS
             TOSCAException.generate_inv_schema_property_error(
                 self, attr, value, valid_values)
 def _load_required_attr_from_schema(self):
     # IF 'required' keyname exists verify it's a boolean,
     # if so override default
     if self.PROPERTY_KEYNAME_REQUIRED in self.schema:
         value = self.schema[self.PROPERTY_KEYNAME_REQUIRED]
         if isinstance(value, bool):
             self._required = value
         else:
             valid_values = ', '.join(self.VALID_REQUIRED_VALUES)
             attr = self.PROPERTY_KEYNAME_REQUIRED
             TOSCAException.generate_inv_schema_property_error(
                 self, attr, value, valid_values)
    def __init__(self, sub_mapping_def, nodetemplates, inputs, outputs,
                 sub_mapped_node_template, custom_defs):
        self.nodetemplates = nodetemplates
        self.sub_mapping_def = sub_mapping_def
        TOSCAException.set_context(self.type, "substitution_mapping")
        self.inputs = inputs or []
        self.outputs = outputs or []
        self.sub_mapped_node_template = sub_mapped_node_template
        self.custom_defs = custom_defs or {}
        self._validate()

        self.type_definition = NodeType(self.type, custom_defs)
        self._properties = None
        self._capabilities = None
        self._requirements = None
        self._interfaces = None
        TOSCAException.reset_context()
Ejemplo n.º 8
0
 def __init__(self, name, template, entity_name, custom_def=None):
     TOSCAException.set_context(entity_name, name)
     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
     self._artifacts = None
     TOSCAException.reset_context()
Ejemplo n.º 9
0
 def _validate_properties(self, template, entitytype):
     TOSCAException.set_context("properties", self.name)
     properties = entitytype.get_value(self.PROPERTIES, template)
     self._common_validate_properties(entitytype, properties)
     TOSCAException.reset_context()
Ejemplo n.º 10
0
 def interfaces(self):
     TOSCAException.set_context("relationship", self.name)
     if self._interfaces is None:
         self._interfaces = self._create_interfaces()
     TOSCAException.reset_context()
     return self._interfaces
Ejemplo n.º 11
0
 def validate(self, value=None):
     if value is not None:
         TOSCAException.set_context("input", self.name)
         self._validate_value(value)
         TOSCAException.reset_context()
Ejemplo n.º 12
0
 def validate(self):
     TOSCAException.set_context("output", self.name)
     self._validate_field()
     TOSCAException.reset_context()