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
0
Merge Requests
0
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
Thomas Leymonerie
slapos.core
Commits
db32d9f0
Commit
db32d9f0
authored
Mar 25, 2022
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos_cloud: Include Mixin for ComputePartition
parent
9e9a2be9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
266 additions
and
72 deletions
+266
-72
master/bt5/slapos_cloud/MixinTemplateItem/portal_components/mixin.erp5.SlapOSComputePartitionMixin.py
...rtal_components/mixin.erp5.SlapOSComputePartitionMixin.py
+127
-0
master/bt5/slapos_cloud/MixinTemplateItem/portal_components/mixin.erp5.SlapOSComputePartitionMixin.xml
...tal_components/mixin.erp5.SlapOSComputePartitionMixin.xml
+133
-0
master/bt5/slapos_cloud/PortalTypeTypeMixinTemplateItem/type_mixin.xml
...apos_cloud/PortalTypeTypeMixinTemplateItem/type_mixin.xml
+1
-0
master/bt5/slapos_cloud/bt/template_mixin_id_list
master/bt5/slapos_cloud/bt/template_mixin_id_list
+2
-1
master/bt5/slapos_cloud/bt/template_portal_type_type_mixin_list
.../bt5/slapos_cloud/bt/template_portal_type_type_mixin_list
+1
-0
master/bt5/slapos_slap_tool/ToolComponentTemplateItem/portal_components/tool.erp5.SlapTool.py
...onentTemplateItem/portal_components/tool.erp5.SlapTool.py
+2
-71
No files found.
master/bt5/slapos_cloud/MixinTemplateItem/portal_components/mixin.erp5.SlapOSComputePartitionMixin.py
0 → 100644
View file @
db32d9f0
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2010-2022 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly advised to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
AccessControl.Permissions
import
access_contents_information
from
AccessControl
import
getSecurityManager
from
AccessControl
import
Unauthorized
try
:
from
slapos.slap.slap
import
(
ComputerPartition
as
SlapComputePartition
,
SoftwareRelease
)
from
slapos.util
import
dumps
,
calculate_dict_hash
except
ImportError
:
# Do no prevent instance from starting
# if libs are not installed
class
SlapComputePartition
:
def
__init__
(
self
):
raise
ImportError
class
SoftwareRelease
:
def
__init__
(
self
):
raise
ImportError
def
dumps
(
*
args
):
raise
ImportError
def
calculate_dict_hash
(
*
args
):
raise
ImportError
def
_assertACI
(
document
):
sm
=
getSecurityManager
()
if
sm
.
checkPermission
(
access_contents_information
,
document
):
return
document
raise
Unauthorized
(
'User %r has no access to %r'
%
(
sm
.
getUser
(),
document
))
class
SlapOSComputePartitionMixin
(
object
):
def
_registerComputerPartition
(
self
):
portal
=
self
.
getPortalObject
()
computer_reference
=
self
.
getParentValue
().
getReference
()
computer_partition_reference
=
self
.
getReference
()
slap_partition
=
SlapComputePartition
(
computer_reference
.
decode
(
"UTF-8"
),
computer_partition_reference
.
decode
(
"UTF-8"
))
slap_partition
.
_software_release_document
=
None
slap_partition
.
_requested_state
=
'destroyed'
slap_partition
.
_need_modification
=
0
software_instance
=
None
if
self
.
getSlapState
()
==
'busy'
:
software_instance_list
=
portal
.
portal_catalog
.
unrestrictedSearchResults
(
portal_type
=
"Software Instance"
,
default_aggregate_uid
=
self
.
getUid
(),
validation_state
=
"validated"
,
limit
=
2
,
)
software_instance_count
=
len
(
software_instance_list
)
if
software_instance_count
==
1
:
software_instance
=
_assertACI
(
software_instance_list
[
0
].
getObject
())
elif
software_instance_count
>
1
:
# XXX do not prevent the system to work if one partition is broken
raise
NotImplementedError
,
"Too many instances %s linked to %s"
%
\
([
x
.
path
for
x
in
software_instance_list
],
self
.
getRelativeUrl
())
if
software_instance
is
not
None
:
# trick client side, that data has been synchronised already for given
# document
slap_partition
.
_synced
=
True
state
=
software_instance
.
getSlapState
()
if
state
==
"stop_requested"
:
slap_partition
.
_requested_state
=
'stopped'
if
state
==
"start_requested"
:
slap_partition
.
_requested_state
=
'started'
slap_partition
.
_software_release_document
=
SoftwareRelease
(
software_release
=
software_instance
.
getUrlString
().
decode
(
"UTF-8"
),
computer_guid
=
computer_reference
.
decode
(
"UTF-8"
))
slap_partition
.
_need_modification
=
1
parameter_dict
=
software_instance
.
_asParameterDict
()
# software instance has to define an xml parameter
slap_partition
.
_parameter_dict
=
software_instance
.
_instanceXmlToDict
(
parameter_dict
.
pop
(
'xml'
))
slap_partition
.
_connection_dict
=
software_instance
.
_instanceXmlToDict
(
parameter_dict
.
pop
(
'connection_xml'
))
slap_partition
.
_filter_dict
=
software_instance
.
_instanceXmlToDict
(
parameter_dict
.
pop
(
'filter_xml'
))
slap_partition
.
_instance_guid
=
parameter_dict
.
pop
(
'instance_guid'
)
for
slave_instance_dict
in
parameter_dict
.
get
(
"slave_instance_list"
,
[]):
if
slave_instance_dict
.
has_key
(
"connection_xml"
):
connection_dict
=
software_instance
.
_instanceXmlToDict
(
slave_instance_dict
.
pop
(
"connection_xml"
))
slave_instance_dict
.
update
(
connection_dict
)
slave_instance_dict
[
'connection-parameter-hash'
]
=
\
calculate_dict_hash
(
connection_dict
)
if
slave_instance_dict
.
has_key
(
"xml"
):
slave_instance_dict
.
update
(
software_instance
.
_instanceXmlToDict
(
slave_instance_dict
.
pop
(
"xml"
)))
slap_partition
.
_parameter_dict
.
update
(
parameter_dict
)
return
dumps
(
slap_partition
)
master/bt5/slapos_cloud/MixinTemplateItem/portal_components/mixin.erp5.SlapOSComputePartitionMixin.xml
0 → 100644
View file @
db32d9f0
<?xml version="1.0"?>
<ZopeData>
<record
id=
"1"
aka=
"AAAAAAAAAAE="
>
<pickle>
<global
name=
"Mixin Component"
module=
"erp5.portal_type"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_recorded_property_dict
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAI=
</string>
</persistent>
</value>
</item>
<item>
<key>
<string>
default_reference
</string>
</key>
<value>
<string>
SlapOSComputePartitionMixin
</string>
</value>
</item>
<item>
<key>
<string>
default_source_reference
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
description
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
id
</string>
</key>
<value>
<string>
mixin.erp5.SlapOSComputePartitionMixin
</string>
</value>
</item>
<item>
<key>
<string>
portal_type
</string>
</key>
<value>
<string>
Mixin Component
</string>
</value>
</item>
<item>
<key>
<string>
sid
</string>
</key>
<value>
<none/>
</value>
</item>
<item>
<key>
<string>
text_content_error_message
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
text_content_warning_message
</string>
</key>
<value>
<tuple/>
</value>
</item>
<item>
<key>
<string>
version
</string>
</key>
<value>
<string>
erp5
</string>
</value>
</item>
<item>
<key>
<string>
workflow_history
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAM=
</string>
</persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"2"
aka=
"AAAAAAAAAAI="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"3"
aka=
"AAAAAAAAAAM="
>
<pickle>
<global
name=
"PersistentMapping"
module=
"Persistence.mapping"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
data
</string>
</key>
<value>
<dictionary>
<item>
<key>
<string>
component_validation_workflow
</string>
</key>
<value>
<persistent>
<string
encoding=
"base64"
>
AAAAAAAAAAQ=
</string>
</persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record
id=
"4"
aka=
"AAAAAAAAAAQ="
>
<pickle>
<global
name=
"WorkflowHistoryList"
module=
"Products.ERP5Type.Workflow"
/>
</pickle>
<pickle>
<dictionary>
<item>
<key>
<string>
_log
</string>
</key>
<value>
<list>
<dictionary>
<item>
<key>
<string>
action
</string>
</key>
<value>
<string>
validate
</string>
</value>
</item>
<item>
<key>
<string>
validation_state
</string>
</key>
<value>
<string>
validated
</string>
</value>
</item>
</dictionary>
</list>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
master/bt5/slapos_cloud/PortalTypeTypeMixinTemplateItem/type_mixin.xml
View file @
db32d9f0
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
</portal_type>
</portal_type>
<portal_type
id=
"Compute Partition"
>
<portal_type
id=
"Compute Partition"
>
<item>
SlapOSCacheMixin
</item>
<item>
SlapOSCacheMixin
</item>
<item>
SlapOSComputePartitionMixin
</item>
</portal_type>
</portal_type>
<portal_type
id=
"Person"
>
<portal_type
id=
"Person"
>
<item>
SlapOSCacheMixin
</item>
<item>
SlapOSCacheMixin
</item>
...
...
master/bt5/slapos_cloud/bt/template_mixin_id_list
View file @
db32d9f0
mixin.erp5.SlapOSCacheMixin
mixin.erp5.SlapOSCacheMixin
mixin.erp5.SlapOSComputeNodeMixin
mixin.erp5.SlapOSComputeNodeMixin
\ No newline at end of file
mixin.erp5.SlapOSComputePartitionMixin
\ No newline at end of file
master/bt5/slapos_cloud/bt/template_portal_type_type_mixin_list
View file @
db32d9f0
Compute Node | SlapOSCacheMixin
Compute Node | SlapOSCacheMixin
Compute Node | SlapOSComputeNodeMixin
Compute Node | SlapOSComputeNodeMixin
Compute Partition | SlapOSCacheMixin
Compute Partition | SlapOSCacheMixin
Compute Partition | SlapOSComputePartitionMixin
Person | SlapOSCacheMixin
Person | SlapOSCacheMixin
\ No newline at end of file
master/bt5/slapos_slap_tool/ToolComponentTemplateItem/portal_components/tool.erp5.SlapTool.py
View file @
db32d9f0
...
@@ -43,9 +43,7 @@ from lxml import etree
...
@@ -43,9 +43,7 @@ from lxml import etree
try
:
try
:
from
slapos.slap.slap
import
(
from
slapos.slap.slap
import
(
Computer
as
ComputeNode
,
Computer
as
ComputeNode
,
ComputerPartition
as
SlapComputePartition
,
SoftwareInstance
)
SoftwareInstance
,
SoftwareRelease
)
from
slapos.util
import
dict2xml
,
calculate_dict_hash
,
loads
,
dumps
from
slapos.util
import
dict2xml
,
calculate_dict_hash
,
loads
,
dumps
except
ImportError
:
except
ImportError
:
# Do no prevent instance from starting
# Do no prevent instance from starting
...
@@ -53,15 +51,9 @@ except ImportError:
...
@@ -53,15 +51,9 @@ except ImportError:
class
ComputeNode
:
class
ComputeNode
:
def
__init__
(
self
):
def
__init__
(
self
):
raise
ImportError
raise
ImportError
class
SlapComputePartition
:
def
__init__
(
self
):
raise
ImportError
class
SoftwareInstance
:
class
SoftwareInstance
:
def
__init__
(
self
):
def
__init__
(
self
):
raise
ImportError
raise
ImportError
class
SoftwareRelease
:
def
__init__
(
self
):
raise
ImportError
def
dict2xml
(
dictionary
):
def
dict2xml
(
dictionary
):
raise
ImportError
raise
ImportError
def
calculate_dict_hash
(
dictionary
):
def
calculate_dict_hash
(
dictionary
):
...
@@ -667,71 +659,10 @@ class SlapTool(BaseTool):
...
@@ -667,71 +659,10 @@ class SlapTool(BaseTool):
"""
"""
# Try to get the compute partition to raise an exception if it doesn't
# Try to get the compute partition to raise an exception if it doesn't
# exist
# exist
portal
=
self
.
getPortalObject
()
compute_partition_document
=
self
.
_getComputePartitionDocument
(
compute_partition_document
=
self
.
_getComputePartitionDocument
(
computer_reference
,
computer_partition_reference
)
computer_reference
,
computer_partition_reference
)
slap_partition
=
SlapComputePartition
(
computer_reference
.
decode
(
"UTF-8"
),
computer_partition_reference
.
decode
(
"UTF-8"
))
slap_partition
.
_software_release_document
=
None
slap_partition
.
_requested_state
=
'destroyed'
slap_partition
.
_need_modification
=
0
software_instance
=
None
if
compute_partition_document
.
getSlapState
()
==
'busy'
:
software_instance_list
=
portal
.
portal_catalog
.
unrestrictedSearchResults
(
portal_type
=
"Software Instance"
,
default_aggregate_uid
=
compute_partition_document
.
getUid
(),
validation_state
=
"validated"
,
limit
=
2
,
)
software_instance_count
=
len
(
software_instance_list
)
if
software_instance_count
==
1
:
software_instance
=
_assertACI
(
software_instance_list
[
0
].
getObject
())
elif
software_instance_count
>
1
:
# XXX do not prevent the system to work if one partition is broken
raise
NotImplementedError
,
"Too many instances %s linked to %s"
%
\
([
x
.
path
for
x
in
software_instance_list
],
compute_partition_document
.
getRelativeUrl
())
if
software_instance
is
not
None
:
result
=
compute_partition_document
.
_registerComputerPartition
()
# trick client side, that data has been synchronised already for given
# document
slap_partition
.
_synced
=
True
state
=
software_instance
.
getSlapState
()
if
state
==
"stop_requested"
:
slap_partition
.
_requested_state
=
'stopped'
if
state
==
"start_requested"
:
slap_partition
.
_requested_state
=
'started'
slap_partition
.
_software_release_document
=
SoftwareRelease
(
software_release
=
software_instance
.
getUrlString
().
decode
(
"UTF-8"
),
computer_guid
=
computer_reference
.
decode
(
"UTF-8"
))
slap_partition
.
_need_modification
=
1
parameter_dict
=
software_instance
.
_asParameterDict
()
# software instance has to define an xml parameter
slap_partition
.
_parameter_dict
=
software_instance
.
_instanceXmlToDict
(
parameter_dict
.
pop
(
'xml'
))
slap_partition
.
_connection_dict
=
software_instance
.
_instanceXmlToDict
(
parameter_dict
.
pop
(
'connection_xml'
))
slap_partition
.
_filter_dict
=
software_instance
.
_instanceXmlToDict
(
parameter_dict
.
pop
(
'filter_xml'
))
slap_partition
.
_instance_guid
=
parameter_dict
.
pop
(
'instance_guid'
)
for
slave_instance_dict
in
parameter_dict
.
get
(
"slave_instance_list"
,
[]):
if
slave_instance_dict
.
has_key
(
"connection_xml"
):
connection_dict
=
software_instance
.
_instanceXmlToDict
(
slave_instance_dict
.
pop
(
"connection_xml"
))
slave_instance_dict
.
update
(
connection_dict
)
slave_instance_dict
[
'connection-parameter-hash'
]
=
\
calculate_dict_hash
(
connection_dict
)
if
slave_instance_dict
.
has_key
(
"xml"
):
slave_instance_dict
.
update
(
software_instance
.
_instanceXmlToDict
(
slave_instance_dict
.
pop
(
"xml"
)))
slap_partition
.
_parameter_dict
.
update
(
parameter_dict
)
result
=
dumps
(
slap_partition
)
# Keep in cache server for 7 days
# Keep in cache server for 7 days
self
.
REQUEST
.
response
.
setStatus
(
200
)
self
.
REQUEST
.
response
.
setStatus
(
200
)
...
...
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