Commit 952b0676 authored by Romain Courteaud's avatar Romain Courteaud

slapos_upgrader: create Software Product (and its variations)

parent 155fc19a
......@@ -17,6 +17,14 @@ portal.portal_catalog.searchAndActivate(
**packet_kw
)
# Delete existing old product only
if portal.portal_catalog.getResultValue(portal_type="Software Release") is not None:
portal.portal_catalog.searchAndActivate(
method_id='Base_deleteProcessedDocumentDuringPurge',
portal_type=["Software Product", "Software Release"],
**packet_kw
)
############################################
# Gather compute node informations
############################################
......@@ -46,4 +54,4 @@ if (run_count == 10):
context.activate(after_tag=tag).Base_triggerFullSiteMigrationToVirtualMasterStep2(run_count=run_count+1)
else:
context.activate(after_tag=tag).getId()
context.activate(after_tag=tag).Base_triggerFullSiteMigrationToVirtualMasterStep4()
# create the software products
################################################
portal = context.getPortalObject()
tag = script.id
############################################
# Create products per project
############################################
portal.portal_catalog.searchAndActivate(
method_id='Project_checkSoftwareProductToVirtualMaster',
method_kw={'activate_kw': {'tag': tag}},
activate_kw={'tag': tag, 'priority': 1},
portal_type="Project",
)
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_triggerFullSiteMigrationToVirtualMasterStep4</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from zExceptions import Unauthorized
if REQUEST is not None:
raise Unauthorized
portal = context.getPortalObject()
project = context
def calculateSoftwareProductTitle(software_release_url):
if not software_release_url.startswith('http'):
return software_release_url
try:
result = software_release_url.split('/')[-2]
except IndexError:
result = software_release_url
if not software_release_url.endswith('software.cfg'):
result += ' %s' % software_release_url.split('/')[-1]
return result
soft_dict = {}
###########################################################
# First, calculate the list of product by checking the instances
###########################################################
group_by_list = ["url_string", "follow_up__uid", "source_reference"]
sql_result_list = portal.portal_catalog(
portal_type=["Software Instance", "Slave Instance"],
slap_state=["start_requested", "stop_requested"],
follow_up__uid=project.getUid()
)
for sql_result in sql_result_list:
software_release_url = sql_result.getUrlString()
software_product_title = calculateSoftwareProductTitle(software_release_url)
if software_product_title not in soft_dict:
soft_dict[software_product_title] = {
'release_list': [],
'type_list': []
}
soft_dict[software_product_title]['release_list'].append(software_release_url)
soft_dict[software_product_title]['type_list'].append(sql_result.getSourceReference())
###########################################################
# Second, get info from all installed softwares
###########################################################
group_by_list = ["url_string", "follow_up__uid"]
sql_result_list = portal.portal_catalog(
select_list=group_by_list,
portal_type="Software Installation",
slap_state=["start_requested"],
follow_up__uid=project.getUid(),
group_by=group_by_list,
)
for sql_result in sql_result_list:
compute_node = sql_result.getAggregateValue()
if (compute_node is not None) and (compute_node.getAllocationScope() == 'open'):
software_release_url = sql_result['url_string']
software_product_title = calculateSoftwareProductTitle(software_release_url)
if software_product_title not in soft_dict:
soft_dict[software_product_title] = {
'release_list': [],
'type_list': []
}
soft_dict[software_product_title]['release_list'].append(software_release_url)
###########################################################
# Create needed Software Product
###########################################################
for soft, variation_dict in soft_dict.items():
software_product = portal.portal_catalog.getResultValue(
portal_type="Software Product",
follow_up__uid=project.getUid()
)
if software_product is None:
software_product = portal.software_product_module.newContent(
portal_type="Software Product",
title=soft,
follow_up_value=project,
activate_kw=activate_kw
)
software_product.validate()
for software_type in list(set(variation_dict['type_list'])):
type_variation = portal.portal_catalog.getResultValue(
portal_type="Software Product Type Variation",
title=software_type,
parent_uid=software_product.getUid()
)
if type_variation is None:
software_product.newContent(
portal_type="Software Product Type Variation",
title=software_type,
activate_kw=activate_kw
)
release_list = list(set(variation_dict['release_list']))
release_list.sort()
for software_release in release_list:
software_release_variation = portal.portal_catalog.getResultValue(
portal_type="Software Product Release Variation",
url_string=software_release,
parent_uid=software_product.getUid()
)
if software_release_variation is None:
software_product.newContent(
portal_type="Software Product Release Variation",
title=software_release,
url_string=software_release,
activate_kw=activate_kw
)
<?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>Project_checkSoftwareProductToVirtualMaster</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