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

Do not create destroyed software instance.

parent 605ee2ea
......@@ -122,33 +122,38 @@ else:\n
raise ValueError, "Too many instances \'%s\' found: %s" % (software_title, [x.path for x in request_software_instance_list])\n
\n
if (request_software_instance is None):\n
# First time that the software instance is requested\n
if is_slave == True:\n
software_instance_portal_type = "Slave Instance"\n
if (root_state == "destroyed"):\n
instance_found = False\n
else:\n
software_instance_portal_type = "Software Instance"\n
# Create a new one\n
reference = "SOFTINST-%s" % portal.portal_ids.generateNewId(\n
id_group=\'slap_software_instance_reference\',\n
id_generator=\'uid\')\n
certificate_dict = portal.portal_certificate_authority.getNewCertificate(reference)\n
\n
module = portal.getDefaultModule(portal_type="Software Instance")\n
request_software_instance = module.newContent(\n
portal_type=software_instance_portal_type,\n
title=software_title,\n
specialise_value=hosting_subscription,\n
reference=reference,\n
destination_reference=certificate_dict[\'id\'],\n
ssl_key=certificate_dict[\'key\'],\n
ssl_certificate=certificate_dict[\'certificate\'],\n
activate_kw={\'tag\': tag},\n
)\n
# request_software_instance.portal_workflow.doActionFor(request_software_instance, \'validate_action\')\n
request_software_instance.validate()\n
graph[request_software_instance.getUid()] = []\n
instance_found = True\n
# First time that the software instance is requested\n
if is_slave == True:\n
software_instance_portal_type = "Slave Instance"\n
else:\n
software_instance_portal_type = "Software Instance"\n
# Create a new one\n
reference = "SOFTINST-%s" % portal.portal_ids.generateNewId(\n
id_group=\'slap_software_instance_reference\',\n
id_generator=\'uid\')\n
certificate_dict = portal.portal_certificate_authority.getNewCertificate(reference)\n
\n
module = portal.getDefaultModule(portal_type="Software Instance")\n
request_software_instance = module.newContent(\n
portal_type=software_instance_portal_type,\n
title=software_title,\n
specialise_value=hosting_subscription,\n
reference=reference,\n
destination_reference=certificate_dict[\'id\'],\n
ssl_key=certificate_dict[\'key\'],\n
ssl_certificate=certificate_dict[\'certificate\'],\n
activate_kw={\'tag\': tag},\n
)\n
# request_software_instance.portal_workflow.doActionFor(request_software_instance, \'validate_action\')\n
request_software_instance.validate()\n
graph[request_software_instance.getUid()] = []\n
\n
else:\n
instance_found = True\n
# Update the predecessor category of the previous requester\n
predecessor = request_software_instance.getPredecessorRelatedValue(portal_type="Software Instance")\n
if (predecessor is None):\n
......@@ -161,41 +166,46 @@ else:\n
predecessor.edit(predecessor_uid_list=predecessor_uid_list)\n
graph[predecessor.getUid()] = predecessor_uid_list\n
\n
# Change desired state\n
promise_kw = {\n
\'instance_xml\': instance_xml,\n
\'software_type\': software_type,\n
\'sla_xml\': sla_xml,\n
\'software_release\': software_release_url_string,\n
\'shared\': is_slave,\n
}\n
request_software_instance_url = request_software_instance.getRelativeUrl()\n
context.REQUEST.set(\'request_instance\', request_software_instance)\n
if (root_state == "started"):\n
request_software_instance.requestStart(**promise_kw)\n
elif (root_state == "stopped"):\n
request_software_instance.requestStop(**promise_kw)\n
elif (root_state == "destroyed"):\n
request_software_instance.requestDestroy(**promise_kw)\n
context.REQUEST.set(\'request_instance\', None)\n
else:\n
raise ValueError, "state should be started, stopped or destroyed"\n
if instance_found:\n
\n
predecessor_list = requester_instance.getPredecessorList() + [request_software_instance_url]\n
uniq_predecessor_list = list(set(predecessor_list))\n
predecessor_list.sort()\n
uniq_predecessor_list.sort()\n
# Change desired state\n
promise_kw = {\n
\'instance_xml\': instance_xml,\n
\'software_type\': software_type,\n
\'sla_xml\': sla_xml,\n
\'software_release\': software_release_url_string,\n
\'shared\': is_slave,\n
}\n
request_software_instance_url = request_software_instance.getRelativeUrl()\n
context.REQUEST.set(\'request_instance\', request_software_instance)\n
if (root_state == "started"):\n
request_software_instance.requestStart(**promise_kw)\n
elif (root_state == "stopped"):\n
request_software_instance.requestStop(**promise_kw)\n
elif (root_state == "destroyed"):\n
request_software_instance.requestDestroy(**promise_kw)\n
context.REQUEST.set(\'request_instance\', None)\n
else:\n
raise ValueError, "state should be started, stopped or destroyed"\n
\n
assert predecessor_list == uniq_predecessor_list, "%s != %s" % (predecessor_list, uniq_predecessor_list)\n
predecessor_list = requester_instance.getPredecessorList() + [request_software_instance_url]\n
uniq_predecessor_list = list(set(predecessor_list))\n
predecessor_list.sort()\n
uniq_predecessor_list.sort()\n
\n
# update graph to reflect requested operation\n
graph[requester_instance.getUid()] = requester_instance.getPredecessorUidList() + [request_software_instance.getUid()]\n
assert predecessor_list == uniq_predecessor_list, "%s != %s" % (predecessor_list, uniq_predecessor_list)\n
\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.checkNotCyclic(graph)\n
# update graph to reflect requested operation\n
graph[requester_instance.getUid()] = requester_instance.getPredecessorUidList() + [request_software_instance.getUid()]\n
\n
requester_instance.edit(predecessor_list=predecessor_list)\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.checkNotCyclic(graph)\n
\n
requester_instance.edit(predecessor_list=predecessor_list)\n
\n
else:\n
context.REQUEST.set(\'request_instance\', None)\n
]]></string> </value>
......
39
\ No newline at end of file
40
\ 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