Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.toolbox
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
Iliya Manolov
slapos.toolbox
Commits
b33bd1f2
Commit
b33bd1f2
authored
Jan 16, 2014
by
Nicolas Wavrant
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slaprunner: Build&Run params new saved in json file
instead of hardcode
parent
8a3987fa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
27 deletions
+29
-27
slapos/runner/__init__.py
slapos/runner/__init__.py
+14
-0
slapos/runner/utils.py
slapos/runner/utils.py
+13
-25
slapos/runner/views.py
slapos/runner/views.py
+2
-2
No files found.
slapos/runner/__init__.py
View file @
b33bd1f2
...
...
@@ -78,6 +78,19 @@ def checkHtpasswd(config):
else
:
return
def
checkJSONConfig
(
config
):
"""create a default json file with some parameters inside
if the file has never been created"""
json_file
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'config.json'
)
if
not
os
.
path
.
exists
(
json_file
):
params
=
{
'run_instance'
:
True
,
'run_software'
:
True
,
'max_run_instance'
:
3
,
'max_run_software'
:
2
}
open
(
json_file
,
"w"
).
write
(
json
.
dumps
(
params
))
def
run
():
"Run default configuration."
...
...
@@ -107,6 +120,7 @@ def serve(config):
PERMANENT_SESSION_LIFETIME
=
datetime
.
timedelta
(
days
=
31
),
)
checkHtpasswd
(
app
.
config
)
checkJSONConfig
(
app
.
config
)
if
not
os
.
path
.
exists
(
workdir
):
os
.
mkdir
(
workdir
)
if
not
os
.
path
.
exists
(
software_link
):
...
...
slapos/runner/utils.py
View file @
b33bd1f2
...
...
@@ -2,6 +2,7 @@
# vim: set et sts=2:
# pylint: disable-msg=W0311,C0301,C0103,C0111,W0141,W0142
import
json
import
logging
import
md5
import
multiprocessing
...
...
@@ -26,11 +27,6 @@ import slapos.slap
logger
=
logging
.
getLogger
(
'werkzeug'
)
RUN_INSTANCE
=
True
RUN_SOFTWARE
=
True
MAX_RUN_INSTANCE
=
3
MAX_RUN_SOFTWARE
=
2
TRUE_VALUES
=
(
1
,
'1'
,
True
,
'true'
,
'True'
)
html_escape_table
=
{
...
...
@@ -41,28 +37,19 @@ html_escape_table = {
"<"
:
"<"
,
}
def
getBuildAndRunParams
():
dict_params
=
{
'run_instance'
:
RUN_INSTANCE
,
'run_software'
:
RUN_SOFTWARE
,
'max_run_instance'
:
MAX_RUN_INSTANCE
,
'max_run_software'
:
MAX_RUN_SOFTWARE
}
return
dict_params
def
getBuildAndRunParams
(
config
):
json_file
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'config.json'
)
json_params
=
json
.
load
(
open
(
json_file
))
return
json_params
def
saveBuildAndRunParams
(
params
):
def
saveBuildAndRunParams
(
config
,
params
):
"""XXX-Nico parameters have to be correct.
Works like that because this function do not care
about how you got the parameters"""
global
RUN_INSTANCE
global
RUN_SOFTWARE
global
MAX_RUN_INSTANCE
global
MAX_RUN_SOFTWARE
RUN_INSTANCE
=
params
[
'run_instance'
]
RUN_SOFTWARE
=
params
[
'run_software'
]
MAX_RUN_INSTANCE
=
params
[
'max_run_instance'
]
MAX_RUN_SOFTWARE
=
params
[
'max_run_software'
]
json_file
=
os
.
path
.
join
(
config
[
'etc_dir'
],
'config.json'
)
open
(
json_file
,
"w"
).
write
(
json
.
dumps
(
params
))
def
html_escape
(
text
):
"""Produce entities within text."""
...
...
@@ -820,11 +807,12 @@ def buildAndRun(config):
def runSlapgridUntilSuccess(config, step):
"""Run slapgrid-sr or slapgrid-cp several times,
in the maximum of the constant MAX_RUN_~~~~"""
params = getBuildAndRunParams(config)
if step == "instance":
max_tries = (
MAX_RUN_INSTANCE if RUN_INSTANCE
else 0)
max_tries = (
params['
max_run_instance
'] if params['
run_instance
']
else 0)
runSlapgridWithLock = runInstanceWithLock
elif step == "software":
max_tries = (
MAX_RUN_SOFTWARE if RUN_SOFTWARE
else 0)
max_tries = (
params['
max_run_software
'] if params['
run_software
']
else 0)
runSlapgridWithLock = runSoftwareWithLock
else:
return -1
...
...
@@ -839,7 +827,7 @@ def runSlapgridUntilSuccess(config, step):
max_tries -= counter
# run instance only if we are deploying the software release,
# if it is defined so, and sr is correctly deployed
if step == "software" and
RUN_INSTANCE
and slapgrid:
if step == "software" and
params['
run_instance
']
and slapgrid:
return (max_tries, runSlapgridUntilSuccess(config, "instance"))
else:
return max_tries
...
...
slapos/runner/views.py
View file @
b33bd1f2
...
...
@@ -88,7 +88,7 @@ def myAccount():
account
=
getSession
(
app
.
config
)
return
render_template
(
'account.html'
,
username
=
account
[
0
],
email
=
account
[
2
],
name
=
account
[
3
].
decode
(
'utf-8'
),
params
=
getBuildAndRunParams
())
params
=
getBuildAndRunParams
(
app
.
config
))
@
app
.
route
(
"/dologout"
)
...
...
@@ -550,7 +550,7 @@ def updateBuildAndRun():
params
[
'run_software'
]
=
run_software
params
[
'max_run_instance'
]
=
max_run_instance
params
[
'max_run_software'
]
=
max_run_software
saveBuildAndRunParams
(
params
)
saveBuildAndRunParams
(
app
.
config
,
params
)
result
=
"Your parameters have correctly been updated"
return
jsonify
(
code
=
code
,
result
=
result
)
...
...
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