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
14 from toscaparser.elements.statefulentitytype import StatefulEntityType
17 class DataType(StatefulEntityType):
18 '''TOSCA built-in and user defined complex data type.'''
20 def __init__(self, datatypename, custom_def=None):
21 super(DataType, self).__init__(datatypename,
22 self.DATATYPE_NETWORK_PREFIX,
24 self.custom_def = custom_def
27 def parent_type(self):
28 '''Return a datatype this datatype is derived from.'''
29 ptype = self.derived_from(self.defs)
31 return DataType(ptype, self.custom_def)
36 '''Return 'type' section in the datatype schema.'''
37 return self.entity_value(self.defs, 'type')
39 def get_all_properties_objects(self):
40 '''Return all properties objects defined in type and parent type.'''
41 props_def = self.get_properties_def_objects()
42 ptype = self.parent_type
44 props_def.extend(ptype.get_properties_def_objects())
45 ptype = ptype.parent_type
48 def get_all_properties(self):
49 '''Return a dictionary of all property definition name-object pairs.'''
50 return {prop.name: prop
51 for prop in self.get_all_properties_objects()}
53 def get_all_property_value(self, name):
54 '''Return the value of a given property name.'''
55 props_def = self.get_all_properties()
56 if props_def and name in props_def.key():
57 return props_def[name].value