Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Romain Courteaud
slapos.core
Commits
50073928
Commit
50073928
authored
Nov 28, 2023
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_upgrader: migrate existing subscription requests/projects
parent
7d347f68
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
343 additions
and
76 deletions
+343
-76
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/Base_triggerFullSiteMigrationToVirtualMaster.py
..._upgrader/Base_triggerFullSiteMigrationToVirtualMaster.py
+40
-76
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/Base_triggerFullSiteMigrationToVirtualMasterStep2.py
...ader/Base_triggerFullSiteMigrationToVirtualMasterStep2.py
+55
-0
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/Base_triggerFullSiteMigrationToVirtualMasterStep2.xml
...der/Base_triggerFullSiteMigrationToVirtualMasterStep2.xml
+62
-0
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/ProjectModule_triggerObjectMigrationToVirtualMaster.py
...er/ProjectModule_triggerObjectMigrationToVirtualMaster.py
+124
-0
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/ProjectModule_triggerObjectMigrationToVirtualMaster.xml
...r/ProjectModule_triggerObjectMigrationToVirtualMaster.xml
+62
-0
No files found.
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/Base_triggerFullSiteMigrationToVirtualMaster.py
View file @
50073928
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
)
############################################
# 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
()
### Create the bootstrap Trade Condition
currency
=
portal
.
restrictedTraverse
(
'currency_module/EUR'
)
seller_organisation
=
portal
.
restrictedTraverse
(
'organisation_module/rapidspace'
)
# Sale Trade Condition for Tax
sale_trade_condition
=
portal
.
sale_trade_condition_module
.
newContent
(
portal_type
=
"Sale Trade Condition"
,
reference
=
"Tax/payment for: %s"
%
currency
.
getRelativeUrl
(),
trade_condition_type
=
"default"
,
# XXX hardcoded
specialise
=
"business_process_module/slapos_ultimate_business_process"
,
price_currency_value
=
currency
)
sale_trade_condition
.
newContent
(
portal_type
=
"Trade Model Line"
,
reference
=
"VAT"
,
resource
=
"service_module/slapos_tax"
,
base_application
=
"base_amount/invoicing/taxable"
,
trade_phase
=
"slapos/tax"
,
price
=
0.2
,
quantity
=
1.0
,
membership_criterion_base_category
=
(
'price_currency'
,
'base_contribution'
),
membership_criterion_category
=
(
'price_currency/%s'
%
currency
.
getRelativeUrl
(),
'base_contribution/base_amount/invoicing/taxable'
)
)
sale_trade_condition
.
validate
()
sale_trade_condition
.
reindexObject
(
activate_kw
=
{
'tag'
:
tag
})
# Create Trade Condition to create Project
sale_trade_condition
=
portal
.
sale_trade_condition_module
.
newContent
(
portal_type
=
"Sale Trade Condition"
,
reference
=
"Free Virtual Master (%s)"
%
seller_organisation
.
getTitle
(),
trade_condition_type
=
"virtual_master"
,
specialise_value
=
sale_trade_condition
,
source_value
=
seller_organisation
,
price_currency_value
=
currency
,
)
sale_trade_condition
.
validate
()
sale_trade_condition
.
reindexObject
(
activate_kw
=
{
'tag'
:
tag
})
return
context
.
activate
(
after_tag
=
tag
).
Base_triggerFullSiteMigrationToVirtualMasterStep2
()
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/Base_triggerFullSiteMigrationToVirtualMasterStep2.py
0 → 100644
View file @
50073928
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
)
############################################
# 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
)
############################################
# 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
)
portal
.
project_module
.
activate
(
**
{
'tag'
:
tag
,
'priority'
:
1
}).
ProjectModule_triggerObjectMigrationToVirtualMaster
()
context
.
activate
(
after_tag
=
tag
).
getId
()
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/Base_triggerFullSiteMigrationToVirtualMasterStep2.xml
0 → 100644
View file @
50073928
<?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_triggerFullSiteMigrationToVirtualMasterStep2
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/ProjectModule_triggerObjectMigrationToVirtualMaster.py
0 → 100644
View file @
50073928
from
zExceptions
import
Unauthorized
if
REQUEST
is
not
None
:
raise
Unauthorized
portal
=
context
.
getPortalObject
()
activate_kw
=
None
##########################################################################
## Find the list of all project where instances must be paid
##########################################################################
payable_project_guid_dict
=
{}
for
sql_result
in
portal
.
portal_catalog
(
portal_type
=
"Subscription Request"
,
):
subscription_request
=
sql_result
.
getObject
()
instance_tree
=
subscription_request
.
getAggregateValue
(
portal_type
=
"Instance Tree"
)
if
(
instance_tree
is
not
None
):
context
.
log
(
'COUSCOUS %s'
%
subscription_request
.
getRelativeUrl
())
# Build the list of prices per project/software release
project_guid
=
instance_tree
.
getSuccessorValue
().
getSlaXmlAsDict
().
get
(
'project_guid'
,
None
)
if
project_guid
is
not
None
:
payable_project_guid_dict
[
project_guid
]
=
subscription_request
.
getPriceCurrency
()
# Delete existing subscription request, which must be recreated later
subscription_request
.
getParentValue
().
manage_delObjects
(
ids
=
[
subscription_request
.
getId
()])
##########################################################################
## Migrate all existing projects
##########################################################################
# Copied from Person_addVirtualMaster
project_resource
=
portal
.
restrictedTraverse
(
"service_module/slapos_virtual_master_subscription"
)
for
sql_result
in
portal
.
portal_catalog
(
portal_type
=
"Project"
,
):
project
=
sql_result
.
getObject
()
if
project
.
getDestinationValue
(
None
)
is
None
:
# Project is not migrated
customer
=
project
.
getDestinationDecisionValue
(
None
)
if
(
customer
is
None
)
or
(
project
.
getValidationState
()
!=
'validated'
):
# No idea how to migrate this project
continue
project
.
edit
(
destination_value
=
customer
,
destination_decision_value
=
None
)
is_compute_node_payable
=
False
is_instance_tree_payable
=
False
# XXX hardcoded
price_currency
=
'currency_module/EUR'
if
project
.
getReference
()
in
payable_project_guid_dict
:
is_instance_tree_payable
=
True
price_currency
=
payable_project_guid_dict
[
project
.
getReference
()]
currency_value
=
portal
.
restrictedTraverse
(
price_currency
)
# create the subscription request, which will lead to the Open Order
subscription_request
=
project_resource
.
Resource_createSubscriptionRequest
(
customer
,
[],
project
,
currency_value
=
currency_value
)
subscription_request
.
reindexObject
(
activate_kw
=
activate_kw
)
# XXX How to specify the trade condition containing the currency and trade model lines?
specialise_value
=
subscription_request
.
getSpecialiseValue
(
portal_type
=
"Sale Trade Condition"
)
if
((
specialise_value
is
not
None
)
and
(
len
(
specialise_value
.
contentValues
(
portal_type
=
"Trade Model Line"
))
==
0
)):
specialise_value
=
specialise_value
.
getSpecialiseValue
(
portal_type
=
"Sale Trade Condition"
)
if
((
specialise_value
is
None
)
or
(
len
(
specialise_value
.
contentValues
(
portal_type
=
"Trade Model Line"
))
==
0
)):
raise
ValueError
(
'Could not find a Trade Condition with Trade Model Line'
)
# and create default assignments for the user
# who can manage compute nodes and create instances
customer
.
newContent
(
portal_type
=
'Assignment'
,
destination_project_value
=
project
,
function
=
'production/manager'
,
activate_kw
=
activate_kw
).
open
()
customer
.
newContent
(
portal_type
=
'Assignment'
,
destination_project_value
=
project
,
function
=
'customer'
,
activate_kw
=
activate_kw
).
open
()
for
is_payable
,
portal_type
,
trade_condition_type
in
[
(
is_compute_node_payable
,
'Compute Node'
,
"compute_node"
),
(
is_instance_tree_payable
,
'Instance Tree'
,
"instance_tree"
),
]:
if
is_payable
:
source_section_value
=
subscription_request
.
getSourceSectionValue
(
default
=
subscription_request
.
getSourceValue
(
default
=
None
,
portal_type
=
'Organisation'
),
portal_type
=
'Organisation'
)
if
source_section_value
is
None
:
raise
AssertionError
(
'No source section found to generate the invoices'
)
title
=
'Payable %s for: %s'
%
(
portal_type
,
project
.
getTitle
())
else
:
source_section_value
=
None
title
=
'Free %s for: %s'
%
(
portal_type
,
project
.
getTitle
())
sale_trade_condition
=
portal
.
sale_trade_condition_module
.
newContent
(
portal_type
=
"Sale Trade Condition"
,
reference
=
title
,
trade_condition_type
=
trade_condition_type
,
specialise_value
=
specialise_value
,
source_project_value
=
project
,
source_value
=
subscription_request
.
getSourceValue
(),
source_section_value
=
source_section_value
,
#source_payment_value=seller_bank_account,
price_currency_value
=
currency_value
,
activate_kw
=
activate_kw
)
sale_trade_condition
.
validate
()
master/bt5/slapos_upgrader/SkinTemplateItem/portal_skins/slapos_upgrader/ProjectModule_triggerObjectMigrationToVirtualMaster.xml
0 → 100644
View file @
50073928
<?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>
ProjectModule_triggerObjectMigrationToVirtualMaster
</string>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment