Commit af06f46d authored by Romain Courteaud's avatar Romain Courteaud

slapos_cloud: move instance tree update logic into a python script

parent 4406c739
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
request_instance_tree = context
software_release_url_string = software_release
root_state = state
is_slave = shared
if is_slave not in [True, False]:
raise ValueError("shared should be a boolean")
promise_kw = {
'instance_xml': instance_xml,
'software_type': software_type,
'sla_xml': sla_xml,
'software_release': software_release_url_string,
'shared': is_slave,
}
# Change desired state
if (root_state == "started"):
request_instance_tree.requestStart(**promise_kw)
elif (root_state == "stopped"):
request_instance_tree.requestStop(**promise_kw)
elif (root_state == "destroyed"):
request_instance_tree.requestDestroy(**promise_kw)
context.REQUEST.set('request_instance_tree', None)
else:
raise ValueError("state should be started, stopped or destroyed")
request_instance_tree.requestInstance(
software_release=software_release_url_string,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
sla_xml=sla_xml,
shared=is_slave,
state=root_state,
)
# Change the state at the end to allow to execute updateLocalRoles only once in the transaction
validation_state = request_instance_tree.getValidationState()
slap_state = request_instance_tree.getSlapState()
if validation_state == 'draft':
request_instance_tree.portal_workflow.doActionFor(request_instance_tree,
'validate_action')
if (validation_state != 'archived') and \
(slap_state == 'destroy_requested'):
# XXX TODO do not use validation workflow to filter destroyed subscription
request_instance_tree.archive()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</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, software_release, software_title, software_type, instance_xml, sla_xml, shared, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InstanceTree_updateParameterAndRequest</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -79,43 +79,9 @@ else: ...@@ -79,43 +79,9 @@ else:
activate_kw={'tag': tag}, activate_kw={'tag': tag},
) )
promise_kw = { request_instance_tree.InstanceTree_updateParameterAndRequest(
'instance_xml': instance_xml, root_state, software_release_url_string, software_title, software_type, instance_xml, sla_xml, is_slave
'software_type': software_type, )
'sla_xml': sla_xml,
'software_release': software_release_url_string,
'shared': is_slave,
}
context.REQUEST.set('request_instance_tree', request_instance_tree) context.REQUEST.set('request_instance_tree', request_instance_tree)
# Change desired state if (root_state == "destroyed"):
if (root_state == "started"):
request_instance_tree.requestStart(**promise_kw)
elif (root_state == "stopped"):
request_instance_tree.requestStop(**promise_kw)
elif (root_state == "destroyed"):
request_instance_tree.requestDestroy(**promise_kw)
context.REQUEST.set('request_instance_tree', None) context.REQUEST.set('request_instance_tree', None)
else:
raise ValueError("state should be started, stopped or destroyed")
request_instance_tree.requestInstance(
software_release=software_release_url_string,
software_title=software_title,
software_type=software_type,
instance_xml=instance_xml,
sla_xml=sla_xml,
shared=is_slave,
state=root_state,
)
# Change the state at the end to allow to execute updateLocalRoles only once in the transaction
validation_state = request_instance_tree.getValidationState()
slap_state = request_instance_tree.getSlapState()
if validation_state == 'draft':
request_instance_tree.portal_workflow.doActionFor(request_instance_tree,
'validate_action')
if (validation_state != 'archived') and \
(slap_state == 'destroy_requested'):
# XXX TODO do not use validation workflow to filter destroyed subscription
request_instance_tree.archive()
...@@ -83,6 +83,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template): ...@@ -83,6 +83,7 @@ def makeTestSlapOSCodingStyleTestCase(tested_business_template):
'slapos_cloud/ComputeNode_getUsageReportUrl', 'slapos_cloud/ComputeNode_getUsageReportUrl',
'slapos_cloud/ComputeNode_init', 'slapos_cloud/ComputeNode_init',
'slapos_cloud/InstanceNode_init', 'slapos_cloud/InstanceNode_init',
'slapos_cloud/InstanceTree_updateParameterAndRequest',
'slapos_cloud/RemoteNode_init', 'slapos_cloud/RemoteNode_init',
'slapos_cloud/ComputePartition_getAvailableSoftwareReleaseUrlStringList', 'slapos_cloud/ComputePartition_getAvailableSoftwareReleaseUrlStringList',
'slapos_cloud/ComputePartition_getLastestContactedDate', 'slapos_cloud/ComputePartition_getLastestContactedDate',
......
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