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
16 from toscaparser.entity_template import EntityTemplate
17 from toscaparser.properties import Property
19 SECTIONS = (DERIVED_FROM, PROPERTIES, REQUIREMENTS,
20 INTERFACES, CAPABILITIES, TYPE) = \
21 ('derived_from', 'properties', 'requirements', 'interfaces',
22 'capabilities', 'type')
24 log = logging.getLogger('tosca')
27 class RelationshipTemplate(EntityTemplate):
28 '''Relationship template.'''
29 def __init__(self, relationship_template, name, custom_def=None,
30 target=None, source=None):
31 super(RelationshipTemplate, self).__init__(name,
32 relationship_template,
35 self.name = name.lower()
39 def get_properties_objects(self):
40 '''Return properties objects for this template.'''
41 if self._properties is None:
42 self._properties = self._create_relationship_properties()
43 return self._properties
45 def _create_relationship_properties(self):
48 relationship = self.entity_tpl.get('relationship')
51 for value in self.entity_tpl.values():
52 if isinstance(value, dict):
53 relationship = value.get('relationship')
57 properties = self.type_definition.get_value(self.PROPERTIES,
60 properties = self.entity_tpl.get(self.PROPERTIES) or {}
63 for name, value in properties.items():
64 props_def = self.type_definition.get_properties_def()
65 if props_def and name in props_def:
66 if name in properties.keys():
67 value = properties.get(name)
68 prop = Property(name, value,
69 props_def[name].schema, self.custom_def)
71 for p in self.type_definition.get_properties_def_objects():
72 if p.default is not None and p.name not in properties.keys():
73 prop = Property(p.name, p.default, p.schema, self.custom_def)
78 self._validate_properties(self.entity_tpl, self.type_definition)