Commit ae8e6c24 authored by Gabriel Monnerat's avatar Gabriel Monnerat

clean up scripts, remove not useless scripts and remove part of code that is...

clean up scripts, remove not useless scripts and remove part of code that is used to find Slave Partitions
parent a038b7e2
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>software_instance = state_change[\'object\']\n <value> <string>software_instance = state_change[\'object\']\n
instance_setup_sale_packing_list_line = \\\n instance_setup_sale_packing_list_line = \\\n
context.SoftwareInstance_getInstancePackingListLine(\n context.SlaveInstance_getInstancePackingListLine(\n
state_change, \n state_change, \n
service_relative_url=software_instance.portal_preferences.\\\n service_relative_url=software_instance.portal_preferences.\\\n
getPreferredInstanceSetupResource())\n getPreferredInstanceSetupResource())\n
...@@ -81,7 +81,7 @@ return sale_packing_list\n ...@@ -81,7 +81,7 @@ return sale_packing_list\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>state_change, service_relative_url</string> </value> <value> <string>state_change, service_relative_url, tag=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<value> <string>software_instance = state_change[\'object\']\n <value> <string>software_instance = state_change[\'object\']\n
service_relative_url = software_instance.portal_preferences.\\\n service_relative_url = software_instance.portal_preferences.\\\n
getPreferredInstanceHostingResource()\n getPreferredInstanceHostingResource()\n
return context.SoftwareInstance_getInstancePackingListLine(\n return context.SlaveInstance_getInstancePackingListLine(\n
state_change, \n state_change, \n
service_relative_url=service_relative_url)\n service_relative_url=service_relative_url)\n
</string> </value> </string> </value>
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<value> <string>software_instance = state_change[\'object\']\n <value> <string>software_instance = state_change[\'object\']\n
service_relative_url = software_instance.portal_preferences.\\\n service_relative_url = software_instance.portal_preferences.\\\n
getPreferredInstanceSetupResource()\n getPreferredInstanceSetupResource()\n
return context.SoftwareInstance_getInstancePackingListLine(\n return context.SlaveInstance_getInstancePackingListLine(\n
state_change, \n state_change, \n
service_relative_url=service_relative_url)\n service_relative_url=service_relative_url)\n
</string> </value> </string> </value>
......
...@@ -84,66 +84,27 @@ if "computer_guid" in filter_kw:\n ...@@ -84,66 +84,27 @@ if "computer_guid" in filter_kw:\n
\n \n
# fetch at mot 50 random Computer Partitions, and check if they are ok\n # fetch at mot 50 random Computer Partitions, and check if they are ok\n
isTransitionPossible = software_instance.getPortalObject().portal_workflow.isTransitionPossible\n isTransitionPossible = software_instance.getPortalObject().portal_workflow.isTransitionPossible\n
if shared:\n query_kw.update(free_for_request=1) # is free\n
query_kw.update(\n result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
software_type=software_type,\n offset = max(0, result_count-1)\n
available_slave=1, # has slave\n if offset >= SQL_WINDOW_SIZE:\n
free_for_request=0, # is not available for normal request\n limit = (random.randint(0, offset), SQL_WINDOW_SIZE)\n
)\n
result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
\n
offset = max(0, result_count-1)\n
if offset >= SQL_WINDOW_SIZE:\n
limit = (random.randint(0, offset), SQL_WINDOW_SIZE)\n
else:\n
limit = (0, SQL_WINDOW_SIZE)\n
for computer_partition_candidate in software_instance.portal_catalog(\n
limit=limit, **query_kw):\n
computer_partition_candidate = computer_partition_candidate.getObject()\n
# Check if the computer partition can be marked as busy (done by an interaction workflow on sale packing list level)\n
if computer_partition_candidate.getSlapState() == \'busy\' and computer_partition_candidate.ComputerPartition_isSlaveAvailable():\n
computer_partition = computer_partition_candidate\n
break\n
\n
if computer_partition is None:\n
raise ValueError(\'It was not possible to find Computer Partition with free slave\')\n
\n
# find free slave\n
slave_partition = None\n
for slave_partition_candidate in computer_partition.contentValues(portal_type=\'Slave Partition\'):\n
if isTransitionPossible(slave_partition_candidate, \'mark_busy\'):\n
slave_partition = slave_partition_candidate\n
slave_partition.serialize()\n
break\n
\n
if slave_partition is None:\n
slave_partition = computer_partition.newContent(portal_type="Slave Partition")\n
slave_partition.markFree()\n
computer_partition = slave_partition\n
else:\n else:\n
query_kw.update(free_for_request=1) # is free\n limit = (0, SQL_WINDOW_SIZE)\n
result_count = software_instance.portal_catalog.countResults(**query_kw)[0][0]\n
\n
offset = max(0, result_count-1)\n
if offset >= SQL_WINDOW_SIZE:\n
limit = (random.randint(0, offset), SQL_WINDOW_SIZE)\n
else:\n
limit = (0, SQL_WINDOW_SIZE)\n
\n
for computer_partition_candidate in software_instance.portal_catalog(\n
limit=limit, **query_kw):\n
computer_partition_candidate = computer_partition_candidate.getObject()\n
# Check if the computer partition can be marked as busy (done by an interaction workflow on sale packing list level)\n
if isTransitionPossible(computer_partition_candidate, \'mark_busy\'):\n
computer_partition = computer_partition_candidate\n
break\n
\n \n
if computer_partition is None:\n for computer_partition_candidate in software_instance.portal_catalog(\n
raise ValueError(\'It was not possible to find free Computer Partition\')\n limit=limit, **query_kw):\n
computer_partition_candidate = computer_partition_candidate.getObject()\n
# Check if the computer partition can be marked as busy (done by an interaction workflow on sale packing list level)\n
if isTransitionPossible(computer_partition_candidate, \'mark_busy\'):\n
computer_partition = computer_partition_candidate\n
break\n
\n \n
# lock computer partition\n if computer_partition is None:\n
computer_partition.serialize()\n raise ValueError(\'It was not possible to find free Computer Partition\')\n
\n \n
# lock computer partition\n
computer_partition.serialize()\n
software_release_document = context.portal_catalog.getResultValue(\n software_release_document = context.portal_catalog.getResultValue(\n
portal_type=\'Software Release\',\n portal_type=\'Software Release\',\n
url_string=software_release_url_string)\n url_string=software_release_url_string)\n
...@@ -154,7 +115,7 @@ portal = context.getPortalObject()\n ...@@ -154,7 +115,7 @@ portal = context.getPortalObject()\n
hosting_subscription = software_instance.portal_catalog.getResultValue(uid=hosting_subscription_uid)\n hosting_subscription = software_instance.portal_catalog.getResultValue(uid=hosting_subscription_uid)\n
sale_packing_list_line = context.HostingSubscription_getInstancePackingListLine(state_change)\n sale_packing_list_line = context.HostingSubscription_getInstancePackingListLine(state_change)\n
base_sale_packing_list = sale_packing_list_line.getParentValue()\n base_sale_packing_list = sale_packing_list_line.getParentValue()\n
# XXX: SoftwareInstance_createSalePackingList shall be used to create new Sale Packing List\n # XXX: SlaveInstance_createSalePackingList shall be used to create new Sale Packing List\n
sale_packing_list_module = portal.getDefaultModule(portal_type=\'Sale Packing List\')\n sale_packing_list_module = portal.getDefaultModule(portal_type=\'Sale Packing List\')\n
\n \n
specialise = base_sale_packing_list.getSpecialise()\n specialise = base_sale_packing_list.getSpecialise()\n
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
software_instance = state_change[\'object\']\n
portal = software_instance.getPortalObject()\n
# Get required arguments\n
kwargs = state_change.kwargs\n
software_release_url_string = state_change.kwargs[\'software_release\']\n
requested_partition_reference = kwargs["partition_reference"]\n
shared = kwargs["shared"]\n
software_type = kwargs["software_type"]\n
instance_xml = kwargs["instance_xml"]\n
filter_kw = kwargs["filter_kw"]\n
\n
# Get root software instance\n
predecessor_software_instance = software_instance\n
while (predecessor_software_instance is not None):\n
root_software_instance = predecessor_software_instance\n
predecessor_software_instance = predecessor_software_instance.getPredecessorRelatedValue(\n
portal_type="Software Instance")\n
\n
tag = "%s_%s_%s_inProgress" % (root_software_instance.getUid(), software_type,\n
requested_partition_reference)\n
\n
# Check if it already exists\n
request_software_instance = software_instance.portal_catalog.getResultValue(\n
portal_type=\'Software Instance\',\n
# XXX: User based property is used in non manual operation\n
# XXX-2: Do we really need to use root_uid?\n
title=requested_partition_reference,\n
source_reference=software_type,\n
root_uid=root_software_instance.getUid(),\n
)\n
\n
if (request_software_instance is None):\n
if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
# The software instance is already under creation but can not be fetched from catalog\n
# As it is not possible to fetch informations, it is better to raise an error\n
raise NotImplementedError(tag)\n
else:\n
# First time that the software instance is requested\n
# Create a new one\n
module = software_instance.getDefaultModule(portal_type="Software Instance")\n
request_software_instance = module.newContent(\n
portal_type="Software Instance",\n
title=requested_partition_reference,\n
source_reference=software_type,\n
text_content=instance_xml,\n
activate_kw={\'tag\': tag},\n
**portal.Base_getNewSoftwareInstanceCoordinate()\n
)\n
request_software_instance.portal_workflow.doActionFor(request_software_instance, \'validate_action\')\n
sale_packing_list_line = context.SoftwareInstance_getInstanceSetupPackingListLine(state_change)\n
hosting_subscription_uid = sale_packing_list_line.getAggregateValue(portal_type=\'Hosting Subscription\').getUid()\n
request_software_instance.requestComputerPartition(\n
software_release=software_release_url_string,\n
hosting_subscription_uid=hosting_subscription_uid,\n
shared=shared,\n
software_type=software_type,\n
tag=tag,\n
filter_kw=filter_kw)\n
else:\n
# Update existing software instance\n
# Sale Packing List interaction has to be requested automatically with an interaction workflow\n
request_software_instance.edit(\n
text_content=instance_xml,\n
activate_kw={\'tag\': tag},\n
)\n
# Update the predecessor category of the original caller\n
predecessor_software_instance = request_software_instance.getPredecessorRelatedValue(\n
portal_type="Software Instance")\n
if predecessor_software_instance is None:\n
raise ValueError(\'Requested Software Instance %s should have a predecessor\' % request_software_instance.getRelativeUrl())\n
else:\n
predecessor_uid_list = predecessor_software_instance.getPredecessorUidList()\n
predecessor_uid_list.remove(request_software_instance.getUid())\n
predecessor_software_instance.edit(\n
predecessor_uid_list=predecessor_uid_list,\n
activate_kw={\'tag\': tag},)\n
\n
predecessor_list = software_instance.getPredecessorList() + [request_software_instance.getRelativeUrl()]\n
software_instance.edit(\n
predecessor_list=predecessor_list,\n
activate_kw={\'tag\': tag},)\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SlaveInstance_requestSoftwareInstance</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>software_instance = state_change[\'object\']\n
slave_partition_count = state_change.kwargs[\'slave_partition_count\']\n
\n
packing_list_line = context.SoftwareInstance_getInstanceHostingPackingListLine(state_change)\n
computer_partition = packing_list_line.getAggregateValue(portal_type="Computer Partition")\n
\n
# Update number of slave partitions\n
computer_partition.edit(quantity=slave_partition_count)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SlaveInstance_updateSlavePartitionList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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