Commit 676f082a authored by Romain Courteaud's avatar Romain Courteaud

Do not create destroyed software instance.

parent 605ee2ea
...@@ -122,6 +122,10 @@ else:\n ...@@ -122,6 +122,10 @@ else:\n
raise ValueError, "Too many instances \'%s\' found: %s" % (software_title, [x.path for x in request_software_instance_list])\n raise ValueError, "Too many instances \'%s\' found: %s" % (software_title, [x.path for x in request_software_instance_list])\n
\n \n
if (request_software_instance is None):\n if (request_software_instance is None):\n
if (root_state == "destroyed"):\n
instance_found = False\n
else:\n
instance_found = True\n
# First time that the software instance is requested\n # First time that the software instance is requested\n
if is_slave == True:\n if is_slave == True:\n
software_instance_portal_type = "Slave Instance"\n software_instance_portal_type = "Slave Instance"\n
...@@ -149,6 +153,7 @@ if (request_software_instance is None):\n ...@@ -149,6 +153,7 @@ if (request_software_instance is None):\n
graph[request_software_instance.getUid()] = []\n graph[request_software_instance.getUid()] = []\n
\n \n
else:\n else:\n
instance_found = True\n
# Update the predecessor category of the previous requester\n # Update the predecessor category of the previous requester\n
predecessor = request_software_instance.getPredecessorRelatedValue(portal_type="Software Instance")\n predecessor = request_software_instance.getPredecessorRelatedValue(portal_type="Software Instance")\n
if (predecessor is None):\n if (predecessor is None):\n
...@@ -161,41 +166,46 @@ else:\n ...@@ -161,41 +166,46 @@ else:\n
predecessor.edit(predecessor_uid_list=predecessor_uid_list)\n predecessor.edit(predecessor_uid_list=predecessor_uid_list)\n
graph[predecessor.getUid()] = predecessor_uid_list\n graph[predecessor.getUid()] = predecessor_uid_list\n
\n \n
# Change desired state\n if instance_found:\n
promise_kw = {\n \n
# Change desired state\n
promise_kw = {\n
\'instance_xml\': instance_xml,\n \'instance_xml\': instance_xml,\n
\'software_type\': software_type,\n \'software_type\': software_type,\n
\'sla_xml\': sla_xml,\n \'sla_xml\': sla_xml,\n
\'software_release\': software_release_url_string,\n \'software_release\': software_release_url_string,\n
\'shared\': is_slave,\n \'shared\': is_slave,\n
}\n }\n
request_software_instance_url = request_software_instance.getRelativeUrl()\n request_software_instance_url = request_software_instance.getRelativeUrl()\n
context.REQUEST.set(\'request_instance\', request_software_instance)\n context.REQUEST.set(\'request_instance\', request_software_instance)\n
if (root_state == "started"):\n if (root_state == "started"):\n
request_software_instance.requestStart(**promise_kw)\n request_software_instance.requestStart(**promise_kw)\n
elif (root_state == "stopped"):\n elif (root_state == "stopped"):\n
request_software_instance.requestStop(**promise_kw)\n request_software_instance.requestStop(**promise_kw)\n
elif (root_state == "destroyed"):\n elif (root_state == "destroyed"):\n
request_software_instance.requestDestroy(**promise_kw)\n request_software_instance.requestDestroy(**promise_kw)\n
context.REQUEST.set(\'request_instance\', None)\n context.REQUEST.set(\'request_instance\', None)\n
else:\n else:\n
raise ValueError, "state should be started, stopped or destroyed"\n raise ValueError, "state should be started, stopped or destroyed"\n
\n \n
predecessor_list = requester_instance.getPredecessorList() + [request_software_instance_url]\n predecessor_list = requester_instance.getPredecessorList() + [request_software_instance_url]\n
uniq_predecessor_list = list(set(predecessor_list))\n uniq_predecessor_list = list(set(predecessor_list))\n
predecessor_list.sort()\n predecessor_list.sort()\n
uniq_predecessor_list.sort()\n uniq_predecessor_list.sort()\n
\n \n
assert predecessor_list == uniq_predecessor_list, "%s != %s" % (predecessor_list, uniq_predecessor_list)\n assert predecessor_list == uniq_predecessor_list, "%s != %s" % (predecessor_list, uniq_predecessor_list)\n
\n \n
# update graph to reflect requested operation\n # update graph to reflect requested operation\n
graph[requester_instance.getUid()] = requester_instance.getPredecessorUidList() + [request_software_instance.getUid()]\n graph[requester_instance.getUid()] = requester_instance.getPredecessorUidList() + [request_software_instance.getUid()]\n
\n \n
# check if all elements are still connected and if there is no cycle\n # check if all elements are still connected and if there is no cycle\n
request_software_instance.checkConnected(graph, hosting_subscription.getUid())\n request_software_instance.checkConnected(graph, hosting_subscription.getUid())\n
request_software_instance.checkNotCyclic(graph)\n request_software_instance.checkNotCyclic(graph)\n
\n \n
requester_instance.edit(predecessor_list=predecessor_list)\n requester_instance.edit(predecessor_list=predecessor_list)\n
\n
else:\n
context.REQUEST.set(\'request_instance\', None)\n
]]></string> </value> ]]></string> </value>
......
39 40
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment