Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
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
Titouan Soulard
slapos
Commits
f9463b47
Commit
f9463b47
authored
Oct 21, 2022
by
Cédric Le Ninivin
Committed by
Titouan Soulard
Mar 11, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
recipes: Move update request transaction file to librecipe
parent
0ef73cf4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
30 deletions
+32
-30
slapos/recipe/librecipe/__init__.py
slapos/recipe/librecipe/__init__.py
+26
-0
slapos/recipe/request.py
slapos/recipe/request.py
+6
-30
No files found.
slapos/recipe/librecipe/__init__.py
View file @
f9463b47
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
##############################################################################
##############################################################################
import
logging
import
logging
from
slapos
import
slap
from
slapos
import
slap
from
slapos.slap.slap
import
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
import
os
import
os
import
zc.buildout
import
zc.buildout
import
zc.recipe.egg
import
zc.recipe.egg
...
@@ -57,6 +58,31 @@ def unwrap(value):
...
@@ -57,6 +58,31 @@ def unwrap(value):
value
=
json
.
loads
(
value
)
value
=
json
.
loads
(
value
)
return
value
return
value
def
updateTransactionFile
(
partition_id
,
name
):
"""
Store reference to all Instances requested by this Computer Parition
"""
# Environ variable set by Slapgrid while processing this partition
instance_root
=
os
.
environ
.
get
(
'SLAPGRID_INSTANCE_ROOT'
,
''
)
if
not
instance_root
or
not
partition_id
:
return
transaction_file_name
=
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
%
partition_id
transaction_file_path
=
os
.
path
.
join
(
instance_root
,
partition_id
,
transaction_file_name
)
try
:
if
os
.
access
(
os
.
path
.
join
(
instance_root
,
partition_id
),
os
.
W_OK
):
if
not
os
.
path
.
exists
(
transaction_file_path
):
transac_file
=
open
(
transaction_file_path
,
'w'
)
transac_file
.
close
()
with
open
(
transaction_file_path
,
'a'
)
as
transac_file
:
transac_file
.
write
(
'%s
\
n
'
%
name
)
except
OSError
:
return
from
.genericjioapi
import
GenericjIOAPIRecipe
class
BaseSlapRecipe
:
class
BaseSlapRecipe
:
"""Base class for all slap.recipe.*"""
"""Base class for all slap.recipe.*"""
...
...
slapos/recipe/request.py
View file @
f9463b47
...
@@ -26,12 +26,12 @@
...
@@ -26,12 +26,12 @@
##############################################################################
##############################################################################
import
logging
import
logging
from
zc.buildout
import
UserError
from
zc.buildout
import
UserError
from
slapos.recipe.librecipe
import
wrap
,
JSON_SERIALISED_MAGIC_KEY
from
slapos.recipe.librecipe
import
wrap
,
JSON_SERIALISED_MAGIC_KEY
,
updateTransactionFile
import
json
import
json
import
os
import
os
from
slapos
import
slap
as
slapmodule
from
slapos
import
slap
as
slapmodule
from
slapos.slap
import
SoftwareProductCollection
from
slapos.slap
import
SoftwareProductCollection
from
slapos.slap.slap
import
json_loads_byteified
,
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
from
slapos.slap.slap
import
json_loads_byteified
import
slapos.recipe.librecipe.generic
as
librecipe
import
slapos.recipe.librecipe.generic
as
librecipe
import
traceback
import
traceback
...
@@ -147,15 +147,15 @@ class Recipe(object):
...
@@ -147,15 +147,15 @@ class Recipe(object):
if
software_url
is
not
None
and
\
if
software_url
is
not
None
and
\
software_url
.
startswith
(
SOFTWARE_PRODUCT_NAMESPACE
):
software_url
.
startswith
(
SOFTWARE_PRODUCT_NAMESPACE
):
product
=
SoftwareProductCollection
(
self
.
logger
,
slap
)
product
=
SoftwareProductCollection
(
self
.
logger
,
slap
)
try
:
try
:
software_url
=
product
.
__getattr__
(
software_url
=
product
.
__getattr__
(
software_url
[
len
(
SOFTWARE_PRODUCT_NAMESPACE
):])
software_url
[
len
(
SOFTWARE_PRODUCT_NAMESPACE
):])
except
AttributeError
as
e
:
except
AttributeError
as
e
:
self
.
logger
.
warning
(
'Error on get software release : %s '
%
e
.
message
)
self
.
logger
.
warning
(
'Error on get software release : %s '
%
e
.
message
)
self
.
_raise_request_exception
=
None
self
.
_raise_request_exception
=
None
self
.
_raise_request_exception_formatted
=
None
self
.
_raise_request_exception_formatted
=
None
...
@@ -179,7 +179,7 @@ class Recipe(object):
...
@@ -179,7 +179,7 @@ class Recipe(object):
if
requested_state
:
if
requested_state
:
request_dict
[
"state"
]
=
requested_state
request_dict
[
"state"
]
=
requested_state
self
.
_
updateTransactionFile
(
options
[
'partition-id'
],
name
)
updateTransactionFile
(
options
[
'partition-id'
],
name
)
partition_dict
=
slap
.
jio_api_connector
.
post
(
request_dict
)
partition_dict
=
slap
.
jio_api_connector
.
post
(
request_dict
)
if
"$schema"
in
partition_dict
and
"error-response-schema.json"
in
partition_dict
[
"$schema"
]:
if
"$schema"
in
partition_dict
and
"error-response-schema.json"
in
partition_dict
[
"$schema"
]:
self
.
logger
.
warning
(
self
.
logger
.
warning
(
...
@@ -309,30 +309,6 @@ class Recipe(object):
...
@@ -309,30 +309,6 @@ class Recipe(object):
update
=
install
update
=
install
def
_updateTransactionFile
(
self
,
partition_id
,
name
):
"""
Store reference to all Instances requested by this Computer Parition
"""
# Environ variable set by Slapgrid while processing this partition
instance_root
=
os
.
environ
.
get
(
'SLAPGRID_INSTANCE_ROOT'
,
''
)
if
not
instance_root
or
not
partition_id
:
return
transaction_file_name
=
COMPUTER_PARTITION_REQUEST_LIST_TEMPLATE_FILENAME
%
partition_id
transaction_file_path
=
os
.
path
.
join
(
instance_root
,
partition_id
,
transaction_file_name
)
try
:
if
os
.
access
(
os
.
path
.
join
(
instance_root
,
partition_id
),
os
.
W_OK
):
if
not
os
.
path
.
exists
(
transaction_file_path
):
transac_file
=
open
(
transaction_file_path
,
'w'
)
transac_file
.
close
()
with
open
(
transaction_file_path
,
'a'
)
as
transac_file
:
transac_file
.
write
(
'%s
\
n
'
%
name
)
except
OSError
:
return
class
RequestOptional
(
Recipe
):
class
RequestOptional
(
Recipe
):
"""
"""
Request a SlapOS instance. Won't fail if request failed or is not ready.
Request a SlapOS instance. Won't fail if request failed or is not ready.
...
...
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