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 super(RelationshipTemplate, self).__init__(name,
31 relationship_template,
34 self.name = name.lower()
36 def get_properties_objects(self):
37 '''Return properties objects for this template.'''
38 if self._properties is None:
39 self._properties = self._create_relationship_properties()
40 return self._properties
42 def _create_relationship_properties(self):
45 relationship = self.entity_tpl.get('relationship')
47 properties = self.type_definition.get_value(self.PROPERTIES,
50 properties = self.entity_tpl.get(self.PROPERTIES) or {}
53 for name, value in properties.items():
54 props_def = self.type_definition.get_properties_def()
55 if props_def and name in props_def:
56 if name in properties.keys():
57 value = properties.get(name)
58 prop = Property(name, value,
59 props_def[name].schema, self.custom_def)
61 for p in self.type_definition.get_properties_def_objects():
62 if p.default is not None and p.name not in properties.keys():
63 prop = Property(p.name, p.default, p.schema, self.custom_def)
68 self._validate_properties(self.entity_tpl, self.type_definition)