Commit 1bc9e78a authored by Romain Courteaud's avatar Romain Courteaud

slapos_upgrader: WIP migration scripts

parent bd6366c0
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
container = context.getParentValue()
container.manage_delObjects(ids=[context.getId()])
<?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>Base_deleteProcessedDocumentDuringPurge</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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=["Sale Packing List"],
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Upgrade Decision"],
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Applied Rule"],
parent_uid=portal.portal_simulation.getUid(),
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Open Sale Order"],
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Computer Consumption TioXML File"],
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Regularisation Request"],
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Active Process"],
**packet_kw
)
############################################
# Gather compute node informations
############################################
portal.portal_catalog.searchAndActivate(
method_id='ComputeNode_checkSiteMigrationToVirtualMaster',
activate_kw={'tag': tag, 'priority': 1},
portal_type="Compute Node",
select_dict=not_migrated_select_dict,
left_join_list=not_migrated_select_dict.keys(),
**not_migrated_select_dict
)
return 'ok'
############################################
# Gather instance tree informations
############################################
portal.portal_catalog.searchAndActivate(
method_id='InstanceTree_checkSiteMigrationToVirtualMaster',
activate_kw={'tag': tag, 'priority': 1},
portal_type="Instance Tree",
select_dict=not_migrated_select_dict,
left_join_list=not_migrated_select_dict.keys(),
**not_migrated_select_dict
)
context.activate(after_tag=tag).getId()
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_triggerFullSiteMigrationToVirtualMaster</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
not_migrated_compute_node_dict = {}
personal_virtual_master_dict = {}
existing_virtual_master_dict = {}
portal = context.getPortalObject()
compute_node = context.getObject()
compute_node_relative_url = compute_node.getRelativeUrl()
last_affectation_list = compute_node.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_compute_node = {
'title': compute_node.getTitle(),
'allocation_scope': compute_node.getAllocationScope(""),
'project_relative_url': project_relative_url,
# Category has been dropped from the Compute Node portal type
'source_administration': ([x[len('source_administration/'):] for x in compute_node.getCategoryList() if x.startswith('source_administration')] or [None])[0],
'instance_list': []
}
source_administration_value = portal.restrictedTraverse(not_migrated_compute_node['source_administration'])
not_migrated_compute_node_dict[compute_node_relative_url] = not_migrated_compute_node
partition_list = compute_node.contentValues(portal_type='Compute Partition')
instance_tree_list = []
for partition in partition_list:
instance_list = portal.portal_catalog(
portal_type=['Slave Instance', 'Software Instance'],
aggregate__uid=partition.getUid()
)
not_migrated_compute_node['instance_list'].extend([x.getRelativeUrl() for x in instance_list])
for instance in instance_list:
instance_tree_list.append(instance.getSpecialiseValue())
# XXX check if the instance tree is only hosted on this machine
instance_tree_list = list(set(instance_tree_list))
# Already migrate unused compute node
if (len(not_migrated_compute_node['instance_list']) == 0) and \
(not_migrated_compute_node['project_relative_url'] is None) and \
((not not_migrated_compute_node['allocation_scope'].startswith('open')) or (not_migrated_compute_node['allocation_scope'] == 'open/personal')):
# print 'Personal: %s' % compute_node_relative_url
if not_migrated_compute_node['source_administration'] not in personal_virtual_master_dict:
personal_virtual_master_dict[not_migrated_compute_node['source_administration']] = {
'compute_node_list': [],
'instance_tree_list': []
}
personal_virtual_master_dict[not_migrated_compute_node['source_administration']]['compute_node_list'].append(compute_node_relative_url)
not_migrated_compute_node_dict.pop(compute_node_relative_url)
source_administration_value.Person_checkSiteMigrationCreatePersonalVirtualMaster()
# Node linked to a project
elif not_migrated_compute_node['project_relative_url'] is not None:
if not_migrated_compute_node['project_relative_url'] not in existing_virtual_master_dict:
existing_virtual_master_dict[not_migrated_compute_node['project_relative_url']] = {
'compute_node_list': [],
'instance_tree_list': []
}
existing_virtual_master_dict[not_migrated_compute_node['project_relative_url']]['compute_node_list'].append(compute_node_relative_url)
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
for instance_tree in instance_tree_list:
if instance_tree.getDestinationSection() != not_migrated_compute_node['source_administration']:
from_same_user_only = False
else:
for software_instance in instance_tree.getFollowUpRelatedValueList():
partition = software_instance.getAggregate(None)
if (partition is not None) and (partition.startswith(compute_node_relative_url)):
from_same_user_only = False
if from_same_user_only:
not_migrated_compute_node_dict.pop(compute_node_relative_url)
source_administration_value.Person_checkSiteMigrationCreatePersonalVirtualMaster()
# Log
if not_migrated_compute_node_dict:
context.log(not_migrated_compute_node_dict.keys())
<?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>ComputeNode_checkSiteMigrationToVirtualMaster</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
not_migrated_instance_tree_dict = {}
personal_virtual_master_dict = {}
existing_virtual_master_dict = {}
portal = context.getPortalObject()
instance_tree = context.getObject()
instance_tree_relative_url = instance_tree.getRelativeUrl()
last_affectation_list = instance_tree.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_instance_tree_dict[instance_tree_relative_url] = {
'title': instance_tree.getTitle(),
'slap_state': instance_tree.getSlapState(),
'destination_section': instance_tree.getDestinationSection(),
'project_relative_url': project_relative_url,
'alive_instance_list': []
}
for sql_instance in portal.portal_catalog(specialise__uid=instance_tree.getUid()):
if not ((sql_instance.getAggregate(None) is None) and (sql_instance.getValidationState() == 'invalidated')):
not_migrated_instance_tree_dict[instance_tree_relative_url]['alive_instance_list'].append(sql_instance.getRelativeUrl())
# Outdated instance tree will move to the personal project
# as, there is no way to know where it has been allocated previously
if (not_migrated_instance_tree_dict[instance_tree_relative_url]['slap_state'] == 'destroy_requested') and \
(len(not_migrated_instance_tree_dict[instance_tree_relative_url]['alive_instance_list']) == 0) and \
(not_migrated_instance_tree_dict[instance_tree_relative_url]['project_relative_url'] is None):
if not_migrated_instance_tree_dict[instance_tree_relative_url]['destination_section'] not in personal_virtual_master_dict:
personal_virtual_master_dict[not_migrated_instance_tree_dict[instance_tree_relative_url]['destination_section']] = {
'compute_node_list': [],
'instance_tree_list': []
}
personal_virtual_master_dict[not_migrated_instance_tree_dict[instance_tree_relative_url]['destination_section']]['instance_tree_list'].append(instance_tree_relative_url)
not_migrated_instance_tree_dict.pop(instance_tree_relative_url)
<?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>InstanceTree_checkSiteMigrationToVirtualMaster</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
person = context
is_first_call = (tag is None)
tag = "%s_%s" % (person.getUid(), script.id)
activate_kw = {
'tag': tag
}
wait_activate_kw = {
'serialization_tag': tag,
'after_tag': tag
}
# Delay the script to prevent conflict with serialize
# in the caller script
if is_first_call:
return person.activate(**wait_activate_kw).Person_checkSiteMigrationCreatePersonalVirtualMaster(tag=tag, *args, **kw)
# Prevent concurrent activities
person.serialize()
if 0 < portal.portal_activities.countMessageWithTag(tag):
return person.activate(**wait_activate_kw).Person_checkSiteMigrationCreatePersonalVirtualMaster(tag=tag, *args, **kw)
# No concurrent activity.
# Search the existing virtual master
virtual_master_title = 'Migrated personal for %s' % person.getTitle()
project = portal.portal_catalog.getResultValue(
portal_type='Project',
destination__uid=person.getUid(),
title={'query': virtual_master_title, 'key': 'ExactMatch'}
)
# Or create it
if project is None:
context.log('%s 1 %s' % (script.id, person.getRelativeUrl()))
project = person.Person_addVirtualMaster(
title=virtual_master_title,
is_compute_node_payable=False,
is_instance_tree_payable=False,
price_currency='currency_module/EUR',
batch=1,
activate_kw=activate_kw
)
context.log('%s 2 %s' % (script.id, project))
# XXX Then, migrate other documents linked to the virtual master
<?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, tag=None, *args, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_checkSiteMigrationCreatePersonalVirtualMaster</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