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
Léo-Paul Géneau
slapos.core
Commits
90a7f4a7
Commit
90a7f4a7
authored
Jul 15, 2022
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapos: Update slapgrid to use new API
parent
8652fba3
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
857 additions
and
279 deletions
+857
-279
slapos/grid/SlapObject.py
slapos/grid/SlapObject.py
+20
-14
slapos/grid/slapgrid.py
slapos/grid/slapgrid.py
+279
-102
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
+526
-160
No files found.
slapos/grid/SlapObject.py
View file @
90a7f4a7
...
...
@@ -423,6 +423,7 @@ class Partition(object):
instance_storage_home
=
''
,
ipv4_global_network
=
''
,
buildout_debug
=
False
,
api_backward_compatibility
=
False
,
):
"""Initialisation of class parameters"""
self
.
buildout
=
buildout
...
...
@@ -443,6 +444,7 @@ class Partition(object):
self
.
software_release_url
=
software_release_url
self
.
instance_storage_home
=
instance_storage_home
self
.
ipv4_global_network
=
ipv4_global_network
self
.
api_backward_compatibility
=
api_backward_compatibility
self
.
key_file
=
''
self
.
cert_file
=
''
...
...
@@ -489,16 +491,20 @@ class Partition(object):
# Certificate files are unset, skip.
return
try
:
partition_certificate
=
self
.
computer_partition
.
getCertificate
()
except
NotFoundError
:
raise
NotFoundError
(
'Partition %s is not known by SlapOS Master.'
%
self
.
partition_id
)
if
self
.
api_backward_compatibility
:
try
:
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
)
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
):
old_content
=
open
(
path
).
read
()
...
...
@@ -582,7 +588,7 @@ class Partition(object):
installs the software partition with the help of buildout
"""
self
.
logger
.
info
(
"Installing Computer Partition %s..."
%
self
.
computer_partition
.
get
Id
(
))
%
self
.
computer_partition
.
get
(
"compute_partition_id"
))
self
.
check_free_space
()
...
...
@@ -731,7 +737,7 @@ class Partition(object):
if
os
.
path
.
exists
(
self
.
supervisord_partition_configuration_path
):
os
.
unlink
(
self
.
supervisord_partition_configuration_path
)
else
:
partition_id
=
self
.
computer_partition
.
get
Id
(
)
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
%
{
...
...
@@ -766,22 +772,22 @@ class Partition(object):
"""Asks supervisord to start the instance. If this instance is not
installed, we install it.
"""
partition_id
=
self
.
computer_partition
.
get
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..."
%
self
.
computer_partition
.
get
Id
(
))
self
.
computer_partition
.
get
(
"compute_partition_id"
))
else
:
raise
else
:
self
.
logger
.
info
(
"Requested start of %s..."
%
self
.
computer_partition
.
get
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
.
computer_partition
.
get
Id
(
)
partition_id
=
self
.
computer_partition
.
get
(
"compute_partition_id"
)
try
:
with
self
.
getSupervisorRPC
()
as
supervisor
:
supervisor
.
stopProcessGroup
(
partition_id
,
False
)
...
...
@@ -791,13 +797,13 @@ class Partition(object):
else
:
raise
else
:
self
.
logger
.
info
(
"Requested stop of %s..."
%
self
.
computer_partition
.
get
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
.
computer_partition
.
get
Id
(
))
%
self
.
computer_partition
.
get
(
"compute_partition_id"
))
self
.
createRetentionLockDate
()
if
not
self
.
checkRetentionIsAuthorized
():
...
...
slapos/grid/slapgrid.py
View file @
90a7f4a7
This diff is collapsed.
Click to expand it.
slapos/manager/portredir.py
View file @
90a7f4a7
...
...
@@ -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 @
90a7f4a7
...
...
@@ -741,6 +741,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
):
...
...
@@ -749,7 +779,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 @
90a7f4a7
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