Commit 31c71dec authored by Romain Courteaud's avatar Romain Courteaud

slapos_upgrader: create allocation supplies

parent de33c59b
......@@ -26,4 +26,4 @@ portal.portal_catalog.searchAndActivate(
portal_type="Project",
)
context.activate(after_tag=tag).getId()
context.activate(after_tag=tag).Base_triggerFullSiteMigrationToVirtualMasterStep5()
# create the software products
################################################
portal = context.getPortalObject()
tag = script.id
############################################
# Create allocation supply
############################################
packet_kw = {
'method_kw': {'activate_kw': {'tag': tag}},
'activate_kw': {'tag': tag, 'priority': 1},
'packet_size': 1, # Separate calls to many transactions (calculation can take time)
'activity_count': 1000,
}
portal.portal_catalog.searchAndActivate(
method_id='ComputeNode_checkAllocationSupplyToVirtualMaster',
portal_type="Compute Node",
allocation_scope__uid=portal.portal_categories.allocation_scope.open.getUid(),
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='RemoteNode_checkAllocationSupplyToVirtualMaster',
portal_type="Remote Node",
allocation_scope__uid=portal.portal_categories.allocation_scope.open.getUid(),
**packet_kw
)
portal.portal_catalog.searchAndActivate(
method_id='InstanceNode_checkAllocationSupplyToVirtualMaster',
portal_type="Instance Node",
**packet_kw
)
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_triggerFullSiteMigrationToVirtualMasterStep5</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
compute_node = context
# If there is already a related allocation supply, do nothing
if portal.portal_catalog.getResultValue(portal_type="Allocation Supply",
aggregate__uid=compute_node.getUid()) is not None:
return
slave_on_same_instance_tree_allocable_product_dict = {}
not_slave_on_same_instance_tree_allocable_product_dict = {}
# will contains:
# {node_relative_url: {product_list: xxx, slave_on_same_instance_tree_allocable: boolean}}
for sql_partition_result in compute_node.contentValues(
portal_type=["Compute Partition"]
):
partition = sql_partition_result.getObject()
if partition.getSlapState() == 'busy':
for sql_instance_result in portal.portal_catalog(
portal_type="Software Instance",
aggregate__uid=partition.getUid(),
slap_state=['start_requested', 'stop_requested']
):
software_instance = sql_instance_result.getObject()
software_instance_node = portal.portal_catalog.getResultValue(portal_type="Instance Node", specialise__uid=software_instance.getUid())
software_product, release_variation, type_variation = software_instance.InstanceTree_getSoftwareProduct()
if software_product is None:
raise NotImplementedError(software_instance.getRelativeUrl())
slave_on_same_instance_tree_allocable = (software_instance_node is None) and \
(portal.portal_catalog.getResultValue(
portal_type="Slave Instance",
aggregate__uid=partition.getUid()
) is not None)
if slave_on_same_instance_tree_allocable:
product_dict = slave_on_same_instance_tree_allocable_product_dict
else:
product_dict = not_slave_on_same_instance_tree_allocable_product_dict
if software_product.getRelativeUrl() not in product_dict:
product_dict[software_product.getRelativeUrl()] = {}
if type_variation.getRelativeUrl() not in product_dict[software_product.getRelativeUrl()]:
product_dict[software_product.getRelativeUrl()][type_variation.getRelativeUrl()] = set()
product_dict[software_product.getRelativeUrl()][type_variation.getRelativeUrl()].add(release_variation.getRelativeUrl())
for slave_on_same_instance_tree_allocable, product_dict in [
(True, slave_on_same_instance_tree_allocable_product_dict),
(False, not_slave_on_same_instance_tree_allocable_product_dict)
]:
if product_dict:
# Time to create the allocation supply
#print product_dict
allocation_supply = portal.allocation_supply_module.newContent(
title="%s %s" % (compute_node.getReference(), DateTime().rfc822()),
portal_type="Allocation Supply",
slave_on_same_instance_tree_allocable=slave_on_same_instance_tree_allocable,
destination_project_value=compute_node.getFollowUpValue(),
start_date_range_min=DateTime(),
aggregate_value=compute_node,
activate_kw=activate_kw
)
for software_product_relative_url in product_dict:
software_product = portal.restrictedTraverse(software_product_relative_url)
allocation_supply_line = allocation_supply.newContent(
portal_type="Allocation Supply Line",
title=software_product.getTitle(),
resource_value=software_product,
activate_kw=activate_kw
)
allocation_supply_line.edit(
p_variation_base_category_list=allocation_supply_line.getVariationRangeBaseCategoryList(),
activate_kw=activate_kw
)
base_id = 'path'
allocation_supply_line.setCellRange(
base_id=base_id,
*allocation_supply_line.SupplyLine_asCellRange(base_id=base_id)
)
for type_variation_relative_url in product_dict[software_product_relative_url]:
for release_variation_relative_url in product_dict[software_product_relative_url][type_variation_relative_url]:
# create cells
resource_vcl = [
'software_release/%s' % release_variation_relative_url,
'software_type/%s' % type_variation_relative_url
]
resource_vcl.sort()
cell_key = resource_vcl
allocation_supply_cell = allocation_supply_line.newCell(
base_id=base_id,
portal_type='Allocation Supply Cell',
*cell_key
)
allocation_supply_cell.edit(
mapped_value_property_list=['allocable'],
allocable=True,
predicate_category_list=cell_key,
variation_category_list=cell_key,
activate_kw=activate_kw
)
allocation_supply.validate()
<?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, activate_kw=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ComputeNode_checkAllocationSupplyToVirtualMaster</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
instance_node = context
# If there is already a related allocation supply, do nothing
if portal.portal_catalog.getResultValue(portal_type="Allocation Supply",
aggregate__uid=instance_node.getUid()) is not None:
return
product_dict = {}
software_instance = instance_node.getSpecialiseValue()
partition = software_instance.getAggregateValue()
if (partition is None) or (software_instance.getSlapState() != 'start_requested'):
return
for sql_instance_result in portal.portal_catalog(
portal_type=["Slave Instance"],
aggregate__uid=partition.getUid(),
):
slave_instance = sql_instance_result.getObject()
if slave_instance.getSlapState() in ["start_requested", "stop_requested"]:
software_product, release_variation, type_variation = slave_instance.InstanceTree_getSoftwareProduct()
if software_product is None:
raise NotImplementedError(slave_instance.getRelativeUrl())
if software_product.getRelativeUrl() not in product_dict:
product_dict[software_product.getRelativeUrl()] = {}
if type_variation.getRelativeUrl() not in product_dict[software_product.getRelativeUrl()]:
product_dict[software_product.getRelativeUrl()][type_variation.getRelativeUrl()] = set()
product_dict[software_product.getRelativeUrl()][type_variation.getRelativeUrl()].add(release_variation.getRelativeUrl())
for slave_on_same_instance_tree_allocable, product_dict in [
(False, product_dict)
]:
if product_dict:
# Time to create the allocation supply
#print product_dict
allocation_supply = portal.allocation_supply_module.newContent(
title="%s %s" % (instance_node.getReference(), DateTime().rfc822()),
portal_type="Allocation Supply",
slave_on_same_instance_tree_allocable=slave_on_same_instance_tree_allocable,
destination_project_value=instance_node.getFollowUpValue(),
start_date_range_min=DateTime(),
aggregate_value=instance_node,
activate_kw=activate_kw
)
for software_product_relative_url in product_dict:
software_product = portal.restrictedTraverse(software_product_relative_url)
allocation_supply_line = allocation_supply.newContent(
portal_type="Allocation Supply Line",
title=software_product.getTitle(),
resource_value=software_product,
activate_kw=activate_kw
)
allocation_supply_line.edit(
p_variation_base_category_list=allocation_supply_line.getVariationRangeBaseCategoryList(),
activate_kw=activate_kw
)
base_id = 'path'
allocation_supply_line.setCellRange(
base_id=base_id,
*allocation_supply_line.SupplyLine_asCellRange(base_id=base_id)
)
for type_variation_relative_url in product_dict[software_product_relative_url]:
for release_variation_relative_url in product_dict[software_product_relative_url][type_variation_relative_url]:
# create cells
resource_vcl = [
'software_release/%s' % release_variation_relative_url,
'software_type/%s' % type_variation_relative_url
]
resource_vcl.sort()
cell_key = resource_vcl
allocation_supply_cell = allocation_supply_line.newCell(
base_id=base_id,
portal_type='Allocation Supply Cell',
*cell_key
)
allocation_supply_cell.edit(
mapped_value_property_list=['allocable'],
allocable=True,
predicate_category_list=cell_key,
variation_category_list=cell_key,
activate_kw=activate_kw
)
allocation_supply.validate()
<?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, activate_kw=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>InstanceNode_checkAllocationSupplyToVirtualMaster</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
remote_node = context
# If there is already a related allocation supply, do nothing
if portal.portal_catalog.getResultValue(portal_type="Allocation Supply",
aggregate__uid=remote_node.getUid()) is not None:
return
product_dict = {}
for sql_partition_result in remote_node.contentValues(
portal_type=["Compute Partition"]
):
partition = sql_partition_result.getObject()
if partition.getSlapState() == 'busy':
for sql_instance_result in portal.portal_catalog(
portal_type=["Slave Instance", "Software Instance"],
aggregate__uid=partition.getUid(),
):
software_instance = sql_instance_result.getObject()
if software_instance.getSlapState() in ["start_requested", "stop_requested"]:
software_product, release_variation, type_variation = software_instance.InstanceTree_getSoftwareProduct()
if software_product is None:
raise NotImplementedError(software_instance.getRelativeUrl())
if software_product.getRelativeUrl() not in product_dict:
product_dict[software_product.getRelativeUrl()] = {}
if type_variation.getRelativeUrl() not in product_dict[software_product.getRelativeUrl()]:
product_dict[software_product.getRelativeUrl()][type_variation.getRelativeUrl()] = set()
product_dict[software_product.getRelativeUrl()][type_variation.getRelativeUrl()].add(release_variation.getRelativeUrl())
for slave_on_same_instance_tree_allocable, product_dict in [
(False, product_dict)
]:
if product_dict:
# Time to create the allocation supply
#print product_dict
allocation_supply = portal.allocation_supply_module.newContent(
title="%s %s" % (remote_node.getReference(), DateTime().rfc822()),
portal_type="Allocation Supply",
slave_on_same_instance_tree_allocable=slave_on_same_instance_tree_allocable,
destination_project_value=remote_node.getFollowUpValue(),
start_date_range_min=DateTime(),
aggregate_value=remote_node,
activate_kw=activate_kw
)
for software_product_relative_url in product_dict:
software_product = portal.restrictedTraverse(software_product_relative_url)
allocation_supply_line = allocation_supply.newContent(
portal_type="Allocation Supply Line",
title=software_product.getTitle(),
resource_value=software_product,
activate_kw=activate_kw
)
allocation_supply_line.edit(
p_variation_base_category_list=allocation_supply_line.getVariationRangeBaseCategoryList(),
activate_kw=activate_kw
)
base_id = 'path'
allocation_supply_line.setCellRange(
base_id=base_id,
*allocation_supply_line.SupplyLine_asCellRange(base_id=base_id)
)
for type_variation_relative_url in product_dict[software_product_relative_url]:
for release_variation_relative_url in product_dict[software_product_relative_url][type_variation_relative_url]:
# create cells
resource_vcl = [
'software_release/%s' % release_variation_relative_url,
'software_type/%s' % type_variation_relative_url
]
resource_vcl.sort()
cell_key = resource_vcl
allocation_supply_cell = allocation_supply_line.newCell(
base_id=base_id,
portal_type='Allocation Supply Cell',
*cell_key
)
allocation_supply_cell.edit(
mapped_value_property_list=['allocable'],
allocable=True,
predicate_category_list=cell_key,
variation_category_list=cell_key,
activate_kw=activate_kw
)
allocation_supply.validate()
<?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, activate_kw=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>RemoteNode_checkAllocationSupplyToVirtualMaster</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