summaryrefslogtreecommitdiffstats
path: root/app/toscalib/utils/tosca_operate.py
diff options
context:
space:
mode:
authorStone, Avi (as206k) <as206k@att.com>2018-04-12 16:41:45 +0300
committerStone, Avi (as206k) <as206k@att.com>2018-04-12 16:41:45 +0300
commit879e94b78193798e8b170fca9b924d2c3881f7ba (patch)
tree150de697138a7593869eaae455add025b06a6e04 /app/toscalib/utils/tosca_operate.py
parent7e02c7aaab14828ef8baaef98865f26d98e3b795 (diff)
DCAE-D tosca-lab initial commit
DCAE-D tosca-lab initial commit Change-Id: Ia42934ce7c75abe05fa106585c9334c8b048ee36 Issue-ID: SDC-1218 Signed-off-by: Stone, Avi (as206k) <as206k@att.com>
Diffstat (limited to 'app/toscalib/utils/tosca_operate.py')
-rw-r--r--app/toscalib/utils/tosca_operate.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/app/toscalib/utils/tosca_operate.py b/app/toscalib/utils/tosca_operate.py
new file mode 100644
index 0000000..bc67310
--- /dev/null
+++ b/app/toscalib/utils/tosca_operate.py
@@ -0,0 +1,94 @@
+#Author: Shu Shi
+#emaiL: shushi@research.att.com
+
+
+from toscalib.templates.node import Node
+import copy, logging
+#from __builtin__ import False
+
+def _create_new_node(template, type_name, node_name = None):
+ db = template.db
+# if db.NODE_TYPES.has_key(type_name) is False:
+ if type_name not in db.NODE_TYPES:
+ new_name = 'unknown_'+ str(template.node_index)
+ template.node_index = template.node_index + 1
+ new_node = Node(template, new_name, None)
+ logging.debug( 'New node: '+ new_name+ ' added')
+ return new_node
+
+ if node_name is None:
+ new_name = _get_basename(db.NODE_TYPES[type_name].name) + '_' + str(template.node_index)
+ template.node_index = template.node_index + 1
+ else:
+ new_name = node_name
+
+ new_node = Node(template, new_name, db.NODE_TYPES[type_name])
+
+ template._add_node(new_node)
+
+ logging.debug( 'New node: '+ new_name+ ' added')
+ return new_node
+
+
+def _create_new_template(template, type_name, prefix_name = None):
+ db = template.db
+ if prefix_name is None:
+ prefix = db.TEMPLATES[type_name].name + '_' + str(template.temp_index) + '_'
+ template.temp_index = template.temp_index + 1
+ elif prefix_name == 'NO_PREFIX':
+ prefix = ''
+ else:
+ prefix = prefix_name
+
+ new_temp = copy.deepcopy(db.TEMPLATES[type_name])
+ new_temp._update_prefix(prefix)
+ template.inputs.update(new_temp.inputs)
+ template.outputs.update(new_temp.outputs)
+ template.node_dict.update(new_temp.node_dict)
+ return template
+
+def _assign_property_value(node, property_name, value):
+# if node.properties.has_key(property_name) is False:
+ if property_name not in node.properties:
+ logging.warning( 'No property with name '+ property_name+ ' in the node '+ node.name)
+ return False
+ return node.properties[property_name]._assign(value)
+
+def _assign_capability_property_value(node, cap_name, prop_name, value):
+# if node.capabilities.has_key(cap_name) is False:
+ if cap_name not in node.capabilities:
+ logging.warning( 'No capability with name '+ cap_name+ ' in the node '+ node.name)
+ return False
+ cap_item = node.capabilities[cap_name]
+# if cap_item.properties.has_key(prop_name) is False:
+ if prop_name not in cap_item.properties:
+ logging.warning( 'No propoerty with name'+ prop_name+ ' in the node '+ node.name+ ' capability '+ cap_name)
+ return False
+ return cap_item.properties[prop_name]._assign(value)
+
+def _assign_requirement_value(node, requirement_name, value):
+
+ requirement_found = False
+ for req in node.requirements:
+ if req.name == requirement_name:
+ requirement_found = req
+ break
+ if requirement_found is False:
+ logging.warning( 'No requirement with name '+ requirement_name+ ' in the node '+ node.name)
+ return False
+ if isinstance(value, Node) is False:
+ logging.warning( 'Node value should be passed to requirement assignment')
+ return False
+ else:
+ if requirement_found._verify_node(value):
+ requirement_found._assign(value)
+ else:
+ logging.warning( 'Invalid requirement fulfillment for node '+ node.name+ '->'+ requirement_name)
+
+
+ return True
+
+def _get_basename(name):
+ names = name.split(".")
+ return names[len(names)-1]
+ \ No newline at end of file