Commit 594335b7 authored by Romain Courteaud's avatar Romain Courteaud

slapos_upgrader: migrate computer network

parent 01550c05
......@@ -3,24 +3,30 @@ portal = context.getPortalObject()
tag = script.id
not_migrated_select_dict={'default_follow_up_uid': None}
############################################
# Delete all object to drop
############################################
packet_kw = {
'activate_kw': {'tag': tag},# 'serialization_tag': tag},
'packet_size': 1, # Separate calls to many transactions (calculation can take time)
'activity_count': 1000,
}
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Upgrade Decision"],
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Regularisation Request"],
**packet_kw
)
if run_count == 1:
############################################
# Delete all object to drop
############################################
packet_kw = {
'activate_kw': {'tag': tag},# 'serialization_tag': tag},
'packet_size': 1, # Separate calls to many transactions (calculation can take time)
'activity_count': 1000,
}
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Upgrade Decision"],
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Regularisation Request"],
**packet_kw
)
############################################
# Migrate existing projects
############################################
portal.project_module.activate(**{'tag': tag, 'priority': 1}).ProjectModule_triggerObjectMigrationToVirtualMaster()
############################################
# Gather compute node informations
......@@ -50,6 +56,24 @@ portal.portal_catalog.searchAndActivate(
**not_migrated_select_dict
)
portal.project_module.activate(**{'tag': tag, 'priority': 1}).ProjectModule_triggerObjectMigrationToVirtualMaster()
############################################
# Gather computer network informations
############################################
portal.portal_catalog.searchAndActivate(
method_id='ComputerNetwork_checkSiteMigrationToVirtualMaster',
activate_kw={'tag': tag, 'priority': 1},
portal_type="Computer Network",
select_dict=not_migrated_select_dict,
left_join_list=not_migrated_select_dict.keys(),
**not_migrated_select_dict
)
context.activate(after_tag=tag).getId()
if run_count < 5:
# Run the migration script multiple times
# Because some object are migrated only after some others are migrated
context.activate(after_tag=tag).Base_triggerFullSiteMigrationToVirtualMasterStep2(run_count=run_count+1)
else:
context.activate(after_tag=tag).getId()
......@@ -50,7 +50,7 @@
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
<value> <string>run_count=1</string> </value>
</item>
<item>
<key> <string>id</string> </key>
......
......@@ -42,6 +42,7 @@ for partition in partition_list:
# XXX check if the instance tree is only hosted on this machine
instance_tree_list = list(set(instance_tree_list))
computer_network = compute_node.getSubordinationValue(portal_type="Computer Network")
# Already migrate unused compute node
if (len(not_migrated_compute_node['instance_list']) == 0) and \
......@@ -57,6 +58,11 @@ elif not_migrated_compute_node['project_relative_url'] is not None:
compute_node.activate().Base_activateObjectMigrationToVirtualMaster(not_migrated_compute_node['project_relative_url'])
not_migrated_compute_node_dict.pop(compute_node_relative_url)
elif (computer_network is not None) and (computer_network.getFollowUp(None) is not None):
# Network is already linked to a project
compute_node.activate().Base_activateObjectMigrationToVirtualMaster(computer_network.getFollowUp())
not_migrated_compute_node_dict.pop(compute_node_relative_url)
else:
# If the related instance are all grouped on this machine, and from the same user
from_same_user_only = True
......
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
computer_network = context.getObject()
computer_network_relative_url = computer_network.getRelativeUrl()
last_affectation_list = computer_network.Item_getAffectationList()
project_relative_url = None
if last_affectation_list and last_affectation_list[0].project_uid:
project_uid = last_affectation_list[0].project_uid
project_relative_url = portal.portal_catalog.getResultValue(uid=project_uid).getRelativeUrl()
not_migrated_computer_network = {
'title': computer_network.getTitle(),
'project_relative_url': project_relative_url,
# Category has been dropped from the Computer Network portal type
'source_administration': ([x[len('source_administration/'):] for x in computer_network.getCategoryList() if x.startswith('source_administration')] or [None])[0],
}
# If network has no compute node, move it to user personal project
compute_node_list = [x.getObject() for x in portal.portal_catalog(
portal_type="Compute Node",
subordination__uid=computer_network.getUid()
)]
project_list = [x.getFollowUp(None) for x in compute_node_list]
project_list = list(set(project_list))
# Node linked to a project
if not_migrated_computer_network['project_relative_url'] is not None:
computer_network.activate().Base_activateObjectMigrationToVirtualMaster(not_migrated_computer_network['project_relative_url'])
elif (len(compute_node_list) == 0) and (not_migrated_computer_network['source_administration'] is not None):
# No compute node. Move it to user personal project
source_administration_value = portal.restrictedTraverse(not_migrated_computer_network['source_administration'])
source_administration_value.Person_checkSiteMigrationCreatePersonalVirtualMaster([computer_network_relative_url])
elif (len(project_list) == 1) and (project_list[0] is not None):
# All nodes are linked to the same project
computer_network.activate().Base_activateObjectMigrationToVirtualMaster(project_list[0])
<?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>REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputerNetwork_checkSiteMigrationToVirtualMaster</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
computer_network = context
project = portal.restrictedTraverse(project_relative_url)
edit_kw = {}
# Check if it has been migrated first
if computer_network.getFollowUpValue() is None:
edit_kw['follow_up_value'] = project
# Migrate
if edit_kw:
computer_network.edit(**edit_kw)
# Drop outdated categories
category_list = computer_network.getCategoryList()
new_category_list = [x for x in category_list if not x.startswith('source_administration')]
if len(category_list) != len(new_category_list):
computer_network.setCategoryList(new_category_list)
<?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>project_relative_url, REQUEST=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputerNetwork_triggerObjectMigrationToVirtualMaster</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