1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
13 from toscaparser.common.exception import ExceptionCollector
14 from toscaparser.common.exception import UnknownFieldError
15 from toscaparser.elements.statefulentitytype import StatefulEntityType
18 class RelationshipType(StatefulEntityType):
19 '''TOSCA built-in relationship type.'''
20 SECTIONS = (DERIVED_FROM, VALID_TARGET_TYPES, INTERFACES,
21 ATTRIBUTES, PROPERTIES, DESCRIPTION, VERSION,
22 CREDENTIAL) = ('derived_from', 'valid_target_types',
23 'interfaces', 'attributes', 'properties',
24 'description', 'version', 'credential')
26 def __init__(self, type, capability_name=None, custom_def=None):
27 super(RelationshipType, self).__init__(type, self.RELATIONSHIP_PREFIX,
29 self.capability_name = capability_name
30 self.custom_def = custom_def
34 def parent_type(self):
35 '''Return a relationship this reletionship is derived from.'''
36 prel = self.derived_from(self.defs)
38 return RelationshipType(prel, self.custom_def)
41 def valid_target_types(self):
42 return self.entity_value(self.defs, 'valid_target_types')
44 def _validate_keys(self):
45 for key in self.defs.keys():
46 if key not in self.SECTIONS:
47 ExceptionCollector.appendException(
48 UnknownFieldError(what='Relationshiptype "%s"' % self.type,