Commit 0293d863 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_cloud: Introduce requestTransfer on compute_node_slap_interface_workflow

   This aims to transform *_createMovement into an proper API to handle location/project/owners transfers between Sites/Project/Organisations.
parent fbf0046a
"""
Create an internal Packing List and attach the compute_node
"""
from DateTime import DateTime
from zExceptions import Unauthorized
user = context.getPortalObject().portal_membership.getAuthenticatedMember().getUserValue()
if user is None or user.getRelativeUrl() != context.getSourceAdministration():
raise Unauthorized("Only the compute_node owner can Transfer compute_node from one location to another.")
portal_type = "Internal Packing List"
source = context.Item_getCurrentSiteValue()
source_project = context.Item_getCurrentProjectValue()
source_section = context.Item_getCurrentOwnerValue()
resource_value = context.Item_getResourceValue()
if destination_project is None and source_project is not None:
destination_project = source_project.getRelativeUrl()
if destination_section is None:
destination_section = context.getSourceAdministration()
if destination is None and source is not None:
# We do not change location of the machine
destination = source.getRelativeUrl()
if source is None and destination is None:
raise ValueError("Sorry, destination is required for the initial set.")
if source_section is None:
source_section = context.getSourceAdministration()
resource_value = context.product_module.compute_node
module = context.getDefaultModule(portal_type=portal_type)
line_portal_type = '%s Line' % portal_type
delivery = module.newContent(title="Transfer %s to %s" % (context.getTitle(), destination),
source_value=source,
source_section_value=source_section,
source_project_value=source_project,
destination=destination,
destination_section=destination_section,
source_decision=destination_section,
destination_decision=destination_section,
destination_project_value=destination_project,
start_date=DateTime(),
stop_date=DateTime(),
portal_type=portal_type)
delivery_line = delivery.newContent(
portal_type=line_portal_type,
title=context.getReference(),
quantity_unit=context.getQuantityUnit(),
resource_value=resource_value)
delivery_line.edit(
price=0.0,
quantity=1.0,
aggregate_value=context)
delivery.confirm()
delivery.stop()
delivery.deliver()
context.requestTransfer(
destination=destination,
destination_project=destination_project,
destination_section=destination_section
)
......@@ -52,15 +52,6 @@
<key> <string>_params</string> </key>
<value> <string>destination=None, destination_project=None, destination_section=None</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputeNode_createMovement</string> </value>
......
compute_node = state_change['object']
portal = compute_node.getPortalObject()
from zExceptions import Unauthorized
from DateTime import DateTime
# Get required arguments
kwargs = state_change.kwargs
# Required args
# Raise TypeError if all parameters are not provided
try:
# destination=None, destination_project=None, destination_section=None
destination = kwargs['destination']
destination_project = kwargs["destination_project"]
destination_section = kwargs["destination_section"]
except KeyError:
raise TypeError("ComputeNode_requestTransfer takes exactly 3 arguments")
user = portal.portal_membership.getAuthenticatedMember().getUserValue()
if user is None or user.getRelativeUrl() != compute_node.getSourceAdministration():
raise Unauthorized("Only the compute_node owner can Transfer compute_node from one location to another.")
tag = "%s_%s_%s_%s_inProgress" % (compute_node.getUid(), destination, destination_project, destination_section)
if (portal.portal_activities.countMessageWithTag(tag) > 0):
# The software instance is already under creation but can not be fetched from catalog
# As it is not possible to fetch informations, it is better to raise an error
raise NotImplementedError(tag)
movement_portal_type = "Internal Packing List"
source = compute_node.Item_getCurrentSiteValue()
source_project = compute_node.Item_getCurrentProjectValue()
source_section = compute_node.Item_getCurrentOwnerValue()
resource_value = compute_node.Item_getResourceValue()
if destination_project is None and source_project is not None:
destination_project = source_project.getRelativeUrl()
if destination_section is None:
destination_section = compute_node.getSourceAdministration()
if destination is None and source is not None:
# We do not change location of the machine
destination = source.getRelativeUrl()
if source is None and destination is None:
raise ValueError("Sorry, destination is required for the initial set.")
if source_section is None:
source_section = compute_node.getSourceAdministration()
resource_value = portal.product_module.compute_node
module = portal.getDefaultModule(portal_type=movement_portal_type)
line_portal_type = '%s Line' % movement_portal_type
delivery = module.newContent(title="Transfer %s to %s" % (compute_node.getTitle(), destination),
source_value=source,
source_section_value=source_section,
source_project_value=source_project,
destination=destination,
destination_section=destination_section,
source_decision=destination_section,
destination_decision=destination_section,
destination_project_value=destination_project,
start_date=DateTime(),
stop_date=DateTime(),
portal_type=movement_portal_type)
delivery_line = delivery.newContent(
portal_type=line_portal_type,
title=compute_node.getReference(),
quantity_unit=compute_node.getQuantityUnit(),
resource_value=resource_value)
delivery_line.edit(
price=0.0,
quantity=1.0,
aggregate_value=compute_node)
delivery.confirm()
delivery.stop()
delivery.deliver()
delivery.reindexObject(activate_kw=dict(tag=tag))
delivery_line.reindexObject(activate_kw=dict(tag=tag))
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Script" module="erp5.portal_type"/>
</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>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>_proxy_roles</string> </key>
<value>
<tuple>
<string>Manager</string>
<string>Owner</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>script_ComputeNode_requestTransfer</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Script</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -21,10 +21,17 @@
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_report_compute_node_bang</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_compute_node_registration</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_software_release</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_request_transfer</string>
<string>destination/portal_workflow/compute_node_slap_interface_workflow/transition_revoke_certificate</string>
</tuple>
</value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Workflow Transition" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>action_name</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>categories</string> </key>
<value>
<tuple>
<string>action_type/workflow</string>
<string>after_script/portal_workflow/compute_node_slap_interface_workflow/script_ComputeNode_requestTransfer</string>
</tuple>
</value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>guard_permission</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>icon</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>transition_request_transfer</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Workflow Transition</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Request Transfer</string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </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