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.properties import Property
16 class Capability(object):
17 '''TOSCA built-in capabilities type.'''
19 def __init__(self, name, properties, definition, custom_def):
21 self._properties = properties
22 self.definition = definition
23 self.custom_def = custom_def
25 def get_properties_objects(self):
26 '''Return a list of property objects.'''
28 props = self._properties
30 for name, value in props.items():
31 props_def = self.definition.get_properties_def()
32 if props_def and name in props_def:
33 properties.append(Property(name, value,
34 props_def[name].schema,
38 def get_properties(self):
39 '''Return a dictionary of property name-object pairs.'''
40 return {prop.name: prop
41 for prop in self.get_properties_objects()}
43 def get_property_value(self, name):
44 '''Return the value of a given property name.'''
45 props = self.get_properties()
46 if props and name in props:
47 return props[name].value