blob: e96ee4341e7f1af68959d2df270f29694e9348b1 [file] [log] [blame]
Stone, Avi (as206k)879e94b2018-04-12 16:41:45 +03001from toscalib.templates.constant import *
2from toscalib.templates.property_item import PropertyItem
3import logging
4
5class CapabilityItem(object):
6 def __init__(self, definition):
7 self.name = definition.name
8 self.type = definition.type
9 self.definition = definition
10 self.properties = {}
11 self.id = PropertyItem(definition.id)
12 self.sub_pointer = None
13 self.parent_node = None
14 for prop in definition.properties.keys():
15 self.properties[prop] = PropertyItem(definition.properties[prop])
16
17 def _parse_pre_defined_content(self, content):
18 if content is None:
19 return
20# if content.has_key(CAP_PROPERTIES):
21 if CAP_PROPERTIES in content:
22 prop_sec = content[CAP_PROPERTIES]
23 for prop_name in prop_sec.keys():
24 prop_item = self._get_property_item(prop_name)
25 if prop_item is not None:
26 prop_item._assign(prop_sec[prop_name])
27
28 def _propagate_substitution_value(self):
29 converge = True
30 for prop_item in iter(self.properties.values()):
31 converge = converge and prop_item._propagate_substitution_value()
32
33 if self.sub_pointer is None:
34 return converge
35
36 if self.id.value is None:
37 old_val = None
38 else:
39 old_val = self.id.value._get_value()[0]
40
41 if isinstance(self.sub_pointer, PropertyItem):
42 if self.sub_pointer.value is None:
43 logging.warning( 'Something is wrong, the cap id mapping target'+ self.sub_pointer.name+ ' should have a value!')
44 return converge
45 self.id._direct_assign(self.sub_pointer.value)
46 from toscalib.templates.node import Node
47 if isinstance(self.sub_pointer, Node):
48 if self.sub_pointer.id is None or self.sub_pointer.id.value is None:
49 logging.warning( 'Something is wrong, the cap id mapping target'+ self.sub_pointer.name+ ' should have a value!')
50 return converge
51 self.id._direct_assign(self.sub_pointer.id.value)
52
53 if self.id.value is None:
54 new_val = None
55 else:
56 new_val = self.id.value._get_value()[0]
57 return converge and (old_val == new_val)
58
59 def _get_property_item(self, prop_name):
60# if self.properties.has_key(prop_name):
61 if prop_name in self.properties:
62 return self.properties[prop_name]
63 else:
64 logging.warning('Capability: '+ self.name+ ' of type: '+ self.type+ ' has no property: '+ prop_name)
65 return None
66
67 def _validate_capability(self, cap_name):
68 return self.definition._validate_capability(cap_name)
69
70 def _update_parent_node(self, parent):
71 self.parent_node = parent
72 for prop in iter(self.properties.values()):
73 prop._update_parent_node(parent)