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
733af39c
Commit
733af39c
authored
Jul 15, 2022
by
Cédric Le Ninivin
Committed by
Romain Courteaud
Dec 16, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos: Update slapgrid to use new API
parent
cf60f67b
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
871 additions
and
281 deletions
+871
-281
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+28
-14
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+282
-104
slapos/manager/portredir.py
slapos/manager/portredir.py
+1
-2
slapos/slap/slap.py
slapos/slap/slap.py
+31
-1
slapos/tests/test_slapgrid.py
slapos/tests/test_slapgrid.py
+529
-160
No files found.
slapos/grid/SlapObject.py
View file @
733af39c
...
...
@@ -436,6 +436,7 @@ class Partition(object):
ipv4_global_network
=
''
,
buildout_debug
=
False
,
partition_timeout
=
None
,
api_backward_compatibility
=
False
,
):
"""Initialisation of class parameters"""
self
.
buildout
=
buildout
...
...
@@ -458,6 +459,7 @@ class Partition(object):
self
.
instance_storage_home
=
instance_storage_home
self
.
ipv4_global_network
=
ipv4_global_network
self
.
partition_timeout
=
partition_timeout
self
.
api_backward_compatibility
=
api_backward_compatibility
self
.
key_file
=
''
self
.
cert_file
=
''
...
...
@@ -504,8 +506,12 @@ class Partition(object):
# Certificate files are unset, skip.
return
if
self
.
api_backward_compatibility
:
try
:
partition_certificate
=
self
.
computer_partition
.
getCertificate
()
partition_certificate
=
self
.
computer_partition
[
"slap_partition"
].
getCertificate
()
self
.
computer_partition
[
"X509"
]
=
{}
self
.
computer_partition
[
"X509"
][
"certificate"
]
=
partition_certificate
[
"certificate"
]
self
.
computer_partition
[
"X509"
][
"key"
]
=
partition_certificate
[
"key"
]
except
NotFoundError
:
raise
NotFoundError
(
'Partition %s is not known by SlapOS Master.'
%
self
.
partition_id
)
...
...
@@ -513,7 +519,7 @@ class Partition(object):
uid
,
gid
=
self
.
getUserGroupId
()
for
name
,
path
in
[(
'certificate'
,
self
.
cert_file
),
(
'key'
,
self
.
key_file
)]:
new_content
=
partition_certificate
[
name
]
new_content
=
self
.
computer_partition
[
"X509"
]
[
name
]
old_content
=
None
if
os
.
path
.
exists
(
path
):
with
open
(
path
)
as
f
:
...
...
@@ -569,7 +575,7 @@ class Partition(object):
installs the software partition with the help of buildout
"""
self
.
logger
.
info
(
"Installing Computer Partition %s..."
%
self
.
partition_id
)
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
self
.
check_free_space
()
...
...
@@ -716,6 +722,14 @@ class Partition(object):
self
.
logger
.
warning
(
'No runners nor services found for partition %r'
%
self
.
partition_id
)
else
:
partition_id
=
self
.
computer_partition
.
get
(
"compute_partition_id"
)
group_partition_template
=
bytes2str
(
pkg_resources
.
resource_string
(
__name__
,
'templates/group_partition_supervisord.conf.in'
))
self
.
supervisor_configuration_group
=
group_partition_template
%
{
'instance_id'
:
partition_id
,
'program_list'
:
','
.
join
([
'_'
.
join
([
partition_id
,
runner
])
for
runner
in
runner_list
+
service_list
])
}
# Same method to add to service and run
self
.
addServicesToGroup
(
runner_list
,
self
.
run_path
)
self
.
addServicesToGroup
(
...
...
@@ -788,22 +802,22 @@ class Partition(object):
"""Asks supervisord to start the instance. If this instance is not
installed, we install it.
"""
self
.
updateSupervisorConfiguration
()
partition_id
=
self
.
partition_id
partition_id
=
self
.
computer_partition
.
get
(
"compute_partition_id"
)
try
:
with
self
.
getSupervisorRPC
()
as
supervisor
:
supervisor
.
startProcessGroup
(
partition_id
,
False
)
except
xmlrpclib
.
Fault
as
exc
:
if
exc
.
faultString
.
startswith
(
'BAD_NAME:'
):
self
.
logger
.
info
(
"Nothing to start on %s..."
%
partition_id
)
self
.
logger
.
info
(
"Nothing to start on %s..."
%
self
.
computer_partition
.
get
(
"compute_partition_id"
))
else
:
raise
else
:
self
.
logger
.
info
(
"Requested start of %s..."
%
partition_id
)
self
.
logger
.
info
(
"Requested start of %s..."
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
def
stop
(
self
):
"""Asks supervisord to stop the instance."""
partition_id
=
self
.
partition_id
partition_id
=
self
.
computer_partition
.
get
(
"compute_partition_id"
)
filename
=
partition_id
+
'.conf'
filepath
=
os
.
path
.
join
(
self
.
supervisord_partition_configuration_dir
,
filename
)
...
...
@@ -814,13 +828,13 @@ class Partition(object):
raise
else
:
self
.
updateSupervisor
()
self
.
logger
.
info
(
"Requested stop of %s..."
%
partition_id
)
self
.
logger
.
info
(
"Requested stop of %s..."
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
def
destroy
(
self
):
"""Destroys the partition and makes it available for subsequent use."
"""
self
.
logger
.
info
(
"Destroying Computer Partition %s..."
%
self
.
partition_id
)
%
self
.
computer_partition
.
get
(
"compute_partition_id"
)
)
self
.
createRetentionLockDate
()
if
not
self
.
checkRetentionIsAuthorized
():
...
...
slapos/grid/slapgrid.py
View file @
733af39c
This diff is collapsed.
Click to expand it.
slapos/manager/portredir.py
View file @
733af39c
...
...
@@ -82,9 +82,8 @@ class Manager(object):
# Get partitions IPv6 address
computer_partition
=
partition
.
computer_partition
parameter_dict
=
computer_partition
.
getInstanceParameterDict
()
partition_ip_list
=
parameter_dict
[
'ip_list'
]
+
parameter_dict
.
get
(
partition_ip_list
=
computer_partition
[
'ip_list'
]
+
computer_partition
.
get
(
'full_ip_list'
,
[])
partition_ip_list
=
[
tup
[
1
]
for
tup
in
partition_ip_list
]
...
...
slapos/slap/slap.py
View file @
733af39c
...
...
@@ -762,6 +762,36 @@ class SlapConnectionHelper(ConnectionHelper):
return
loads
(
xml
)
# https://stackoverflow.com/a/33571117
def
_byteify
(
data
,
ignore_dicts
=
False
):
if
isinstance
(
data
,
str
):
return
data
# if this is a list of values, return list of byteified values
if
isinstance
(
data
,
list
):
return
[
_byteify
(
item
,
ignore_dicts
=
True
)
for
item
in
data
]
# if this is a dictionary, return dictionary of byteified keys and values
# but only if we haven't already byteified it
if
isinstance
(
data
,
dict
)
and
not
ignore_dicts
:
return
{
_byteify
(
key
,
ignore_dicts
=
True
):
_byteify
(
value
,
ignore_dicts
=
True
)
for
key
,
value
in
data
.
items
()
# changed to .items() for python 2.7/3
}
# python 3 compatible duck-typing
# if this is a unicode string, return its string representation
if
str
(
type
(
data
))
==
"<type 'unicode'>"
:
return
data
.
encode
(
'utf-8'
)
# if it's anything else, return it in its original form
return
data
def
json_loads_byteified
(
json_text
):
return
_byteify
(
json
.
loads
(
json_text
,
object_hook
=
_byteify
),
ignore_dicts
=
True
)
class
JioAPIConnectionHelper
(
ConnectionHelper
):
def
apiCall
(
self
,
path
,
data
):
...
...
@@ -770,7 +800,7 @@ class JioAPIConnectionHelper(ConnectionHelper):
data
=
json
.
dumps
(
data
),
headers
=
{
'Content-type'
:
'application/json'
},
expect_json_error
=
True
)
return
req
.
json
(
)
return
json_loads_byteified
(
req
.
text
)
def
get
(
self
,
data
):
return
self
.
apiCall
(
path
=
"get/"
,
...
...
slapos/tests/test_slapgrid.py
View file @
733af39c
This diff is collapsed.
Click to expand it.
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