Commit 491e37fd authored by Łukasz Nowak's avatar Łukasz Nowak

Switch software releases for already instantiated instances.

parent a27d3d9c
<?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># try to find, if needed create and publish\n
portal = context.getPortalObject()\n
software_release_document = portal.portal_catalog.getResultValue(portal_type=\'Software Release\',\n
url_string=software_release_url)\n
if software_release_document is None:\n
digest = context.Base_getSha512Hexdiest(software_release_url)\n
tag = \'%s_inProgress\' % digest\n
if portal.portal_activities.countMessageWithTag(tag) == 0:\n
# can create new one\n
software_release_document = portal.software_release_module.newContent(\n
portal_type=\'Software Release\',\n
reference=digest,\n
version=digest,\n
url_string=software_release_url,\n
language=\'en\',\n
activate_kw={\'tag\': tag}\n
)\n
software_release_document.publish(comment=\'Automatically created.\')\n
return software_release_document\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>software_release_url</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getSoftwareReleaseDocument</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -57,27 +57,6 @@ from zExceptions import Unauthorized\n
def markHistory(document, comment):\n
document.portal_workflow.doActionFor(document, action=\'edit_action\', comment=comment)\n
\n
def getSoftwareRelease(software_release_url):\n
# try to find, if needed create and publish\n
portal = context.getPortalObject()\n
software_release_document = portal.portal_catalog.getResultValue(portal_type=\'Software Release\',\n
url_string=software_release_url)\n
if software_release_document is None:\n
digest = context.Base_getSha512Hexdiest(software_release_url)\n
tag = \'%s_inProgress\' % digest\n
if portal.portal_activities.countMessageWithTag(tag) == 0:\n
# can create new one\n
software_release_document = portal.software_release_module.newContent(\n
portal_type=\'Software Release\',\n
reference=digest,\n
version=digest,\n
url_string=software_release_url,\n
language=\'en\',\n
activate_kw={\'tag\': tag}\n
)\n
software_release_document.publish()\n
return software_release_document\n
\n
state = context.getSimulationState()\n
portal = context.getPortalObject()\n
order = context.getParentValue()\n
......@@ -89,7 +68,7 @@ if state in [\'planned\', \'ordered\']:\n
if line_software_release_document is not None:\n
line_software_release_url = line_software_release_document.getUrlString()\n
\n
software_release_document = getSoftwareRelease(instance_software_release_url)\n
software_release_document = context.Base_getSoftwareReleaseDocument(instance_software_release_url)\n
\n
if line_software_release_url == \'\' or \\\n
line_software_release_url != instance_software_release_url:\n
......
806
\ No newline at end of file
807
\ No newline at end of file
......@@ -51,7 +51,6 @@
<item>
<key> <string>_body</string> </key>
<value> <string>instance = state_change[\'object\']\n
\n
# Get latest workflow transition\n
state = instance.getSlapState()\n
started = "start_requested"\n
......@@ -64,12 +63,18 @@ if (state in (started, stopped)):\n
delivery = instance.getCausalityValue(portal_type=["Sale Packing List"])\n
update_service_relative_url = portal.portal_preferences.getPreferredInstanceUpdateResource()\n
\n
software_release_document = instance.Base_getSoftwareReleaseDocument(instance.getRootSoftwareReleaseUrl())\n
if software_release_document is None:\n
raise NotImplemnetedError(\'Software Release %r not ready yet\' % instance.getRootSoftwareReleaseUrl())\n
if delivery is None:\n
new_delivery = context.Instance_createSalePackingList(state_change, portal.restrictedTraverse(update_service_relative_url))\n
new_delivery = context.Instance_createSalePackingList(state_change, portal.restrictedTraverse(update_service_relative_url), software_release_document)\n
else:\n
new_delivery = delivery.Base_createCloneDocument(batch_mode=1)\n
new_delivery.edit(start_date=DateTime(), stop_date=DateTime(), causality_value=None)\n
new_delivery.contentValues(portal_type="Sale Packing List Line")[0].edit(resource=update_service_relative_url)\n
delivery_line = new_delivery.contentValues(portal_type="Sale Packing List Line")[0]\n
aggregate_list = delivery_line.getAggregateList(portal_type=[\'Slave Instance\', \'Software Instance\', \'Hosting Subscription\', \'Computer Partition\'])\n
aggregate_list.append(software_release_document.getRelativeUrl())\n
delivery_line.edit(resource=update_service_relative_url, aggregate_list=aggregate_list)\n
new_delivery.confirm()\n
new_delivery.start()\n
new_delivery.stop()\n
......
......@@ -122,6 +122,9 @@ else:\n
if (packing_list is not None):\n
instance.edit(causality_value=packing_list)\n
else:\n
software_release_document = instance.Base_getSoftwareReleaseDocument(instance.getRootSoftwareReleaseUrl())\n
if software_release_document is None:\n
raise NotImplemnetedError(\'Software Release %r not ready yet\' % instance.getRootSoftwareReleaseUrl())\n
# Create a new packing list from scratch\n
if (state == started):\n
service_relative_url = hosting_service_relative_url\n
......@@ -130,7 +133,7 @@ else:\n
service_relative_url = cleanup_service_relative_url\n
service = cleanup_service\n
\n
packing_list = context.Instance_createSalePackingList(state_change, service)\n
packing_list = context.Instance_createSalePackingList(state_change, service, software_release_document)\n
instance.edit(causality_value=packing_list)\n
\n
if (state == started):\n
......@@ -146,9 +149,15 @@ else:\n
service_relative_url = line.getResource()\n
\n
def letsclone(service_relative_url):\n
software_release_document = instance.Base_getSoftwareReleaseDocument(instance.getRootSoftwareReleaseUrl())\n
if software_release_document is None:\n
raise NotImplementedError(\'Software Release %r not ready yet\' % instance.getRootSoftwareReleaseUrl())\n
new_delivery = delivery.Base_createCloneDocument(batch_mode=1)\n
new_delivery.edit(start_date=DateTime(), stop_date=DateTime(), causality_value=None)\n
new_delivery.contentValues(portal_type="Sale Packing List Line")[0].edit(resource=service_relative_url)\n
delivery_line = new_delivery.contentValues(portal_type="Sale Packing List Line")[0]\n
aggregate_list = delivery_line.getAggregateList(portal_type=[\'Slave Instance\', \'Software Instance\', \'Hosting Subscription\', \'Computer Partition\'])\n
aggregate_list.append(software_release_document.getRelativeUrl())\n
delivery_line.edit(resource=service_relative_url, aggregate_list=aggregate_list)\n
return new_delivery\n
\n
new_delivery = None\n
......
......@@ -70,12 +70,14 @@ packing_list = packing_list_module.newContent(\n
price_currency=delivery.getPriceCurrency(),\n
start_date=DateTime())\n
\n
aggregate_list = sale_order_line.getAggregateList(portal_type=[\'Slave Instance\', \'Software Instance\', \'Hosting Subscription\', \'Computer Partition\'])\n
aggregate_list.append(software_release_document.getRelativeUrl())\n
packing_list_line = packing_list.newContent(\n
portal_type=\'Sale Packing List Line\',\n
resource=service.getRelativeUrl(),\n
quantity_unit="unit/piece",\n
quantity=1,\n
aggregate_list=sale_order_line.getAggregateList(),\n
aggregate_list=aggregate_list,\n
# XXX Hardcode price on service\n
price=service.getSaleSupplyLineBasePrice(),\n
)\n
......@@ -86,7 +88,7 @@ return packing_list\n
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change, service</string> </value>
<value> <string>state_change, service, software_release_document</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
28
\ No newline at end of file
29
\ 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