ea9cbbed62cd61ff1268e90c48fe555d9e20a780
[sdc/sdc-distribution-client.git] /
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
4 #
5 #         http://www.apache.org/licenses/LICENSE-2.0
6 #
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
11 #    under the License.
12
13 from toscaparser.properties import Property
14 from org.openecomp.sdc.toscaparser.jython import JyCapability
15
16 class Capability(JyCapability):
17     '''TOSCA built-in capabilities type.'''
18
19     def __init__(self, name, properties, definition):
20         self.name = name
21         self._properties = properties
22         self.definition = definition
23         
24
25     def getJyName(self):
26         return self.name  
27             
28     def getJyProperties(self):
29         return self.get_properties_objects() 
30
31     def get_properties_objects(self):
32         '''Return a list of property objects.'''
33         properties = []
34         props = self._properties
35         if props:
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))
41         return properties
42
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()}
47
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