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
14 from org.openecomp.sdc.toscaparser.jython import JyCapability
16 class Capability(JyCapability):
17 '''TOSCA built-in capabilities type.'''
19 def __init__(self, name, properties, definition):
21 self._properties = properties
22 self.definition = definition
28 def getJyProperties(self):
29 return self.get_properties_objects()
31 def get_properties_objects(self):
32 '''Return a list of property objects.'''
34 props = self._properties
36 for name, value in props.items():
37 props_def = self.definition.get_properties_def()
38 if props_def and name in props_def:
39 properties.append(Property(name, value,
40 props_def[name].schema))
43 def get_properties(self):
44 '''Return a dictionary of property name-object pairs.'''
45 return {prop.name: prop
46 for prop in self.get_properties_objects()}
48 def get_property_value(self, name):
49 '''Return the value of a given property name.'''
50 props = self.get_properties()
51 if props and name in props:
52 return props[name].value