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):
21 self._properties = properties
22 self.definition = definition
24 def get_properties_objects(self):
25 '''Return a list of property objects.'''
27 props = self._properties
29 for name, value in props.items():
30 props_def = self.definition.get_properties_def()
31 if props_def and name in props_def:
32 properties.append(Property(name, value,
33 props_def[name].schema))
36 def get_properties(self):
37 '''Return a dictionary of property name-object pairs.'''
38 return {prop.name: prop
39 for prop in self.get_properties_objects()}
41 def get_property_value(self, name):
42 '''Return the value of a given property name.'''
43 props = self.get_properties()
44 if props and name in props:
45 return props[name].value