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
Lisa Casino
slapos.toolbox
Commits
17a77af3
Commit
17a77af3
authored
Jul 25, 2013
by
Marco Mariani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
runner: reversed 'if not' logic, function guards, typos
parent
0ad53e01
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
80 deletions
+102
-80
slapos/runner/utils.py
slapos/runner/utils.py
+57
-45
slapos/runner/views.py
slapos/runner/views.py
+45
-35
No files found.
slapos/runner/utils.py
View file @
17a77af3
...
@@ -182,6 +182,7 @@ def updateProxy(config):
...
@@ -182,6 +182,7 @@ def updateProxy(config):
computer
.
updateConfiguration
(
xml_marshaller
.
xml_marshaller
.
dumps
(
slap_config
))
computer
.
updateConfiguration
(
xml_marshaller
.
xml_marshaller
.
dumps
(
slap_config
))
return
True
return
True
def
updateInstanceParameter
(
config
,
software_type
=
None
):
def
updateInstanceParameter
(
config
,
software_type
=
None
):
"""
"""
Reconfigure Slapproxy to re-deploy current Software Instance with parameters.
Reconfigure Slapproxy to re-deploy current Software Instance with parameters.
...
@@ -193,15 +194,18 @@ def updateInstanceParameter(config, software_type=None):
...
@@ -193,15 +194,18 @@ def updateInstanceParameter(config, software_type=None):
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
,
software_type
)):
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
,
software_type
)):
return
False
return
False
def
startProxy
(
config
):
def
startProxy
(
config
):
"""Start Slapproxy server"""
"""Start Slapproxy server"""
if
not
isRunning
(
'slapproxy'
):
if
isRunning
(
'slapproxy'
):
log
=
os
.
path
.
join
(
config
[
'log_dir'
],
'slapproxy.log'
)
return
Popen
([
config
[
'slapproxy'
],
'--log_file'
,
log
,
config
[
'configuration_file_path'
]],
log
=
os
.
path
.
join
(
config
[
'log_dir'
],
'slapproxy.log'
)
name
=
'slapproxy'
,
Popen
([
config
[
'slapproxy'
],
'--log_file'
,
log
,
stdout
=
None
)
config
[
'configuration_file_path'
]],
time
.
sleep
(
4
)
name
=
'slapproxy'
,
stdout
=
None
)
time
.
sleep
(
4
)
def
stopProxy
(
config
):
def
stopProxy
(
config
):
...
@@ -219,6 +223,7 @@ def isSoftwareRunning(config=None):
...
@@ -219,6 +223,7 @@ def isSoftwareRunning(config=None):
"""
"""
Return True if slapgrid-sr is still running and false if slapgrid if not
Return True if slapgrid-sr is still running and false if slapgrid if not
"""
"""
# XXX-Marco what is 'config' for?
return
isRunning
(
'slapgrid-sr'
)
return
isRunning
(
'slapgrid-sr'
)
...
@@ -227,29 +232,32 @@ def runSoftwareWithLock(config):
...
@@ -227,29 +232,32 @@ def runSoftwareWithLock(config):
Use Slapgrid to compile current Software Release and wait until
Use Slapgrid to compile current Software Release and wait until
compilation is done
compilation is done
"""
"""
if
isSoftwareRunning
():
return
False
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-sr.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-sr.pid'
)
if
not
isSoftwareRunning
(
):
if
not
os
.
path
.
exists
(
config
[
'software_root'
]
):
if
not
os
.
path
.
exists
(
config
[
'software_root'
]):
os
.
mkdir
(
config
[
'software_root'
])
os
.
mkdir
(
config
[
'software_root'
]
)
stopProxy
(
config
)
stopProxy
(
config
)
removeProxyDb
(
config
)
removeProxyDb
(
config
)
startProxy
(
config
)
startProxy
(
config
)
logfile
=
open
(
config
[
'software_log'
],
'w'
)
logfile
=
open
(
config
[
'software_log'
],
'w'
)
if
not
updateProxy
(
config
):
if
not
updateProxy
(
config
):
return
False
return
False
# Accelerate compilation by setting make -jX
# Accelerate compilation by setting make -jX
# XXX-Marco can have issues with implicit dependencies or recursive makefiles. should be configurable.
environment
=
os
.
environ
.
copy
()
environment
=
os
.
environ
.
copy
()
environment
[
'MAKEFLAGS'
]
=
'-j%r'
%
multiprocessing
.
cpu_count
()
environment
[
'MAKEFLAGS'
]
=
'-j%r'
%
multiprocessing
.
cpu_count
()
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
,
'--develop'
],
config
[
'configuration_file_path'
],
'--now'
,
'--develop'
],
stdout
=
logfile
,
env
=
environment
,
stdout
=
logfile
,
env
=
environment
,
name
=
'slapgrid-sr'
)
name
=
'slapgrid-sr'
)
slapgrid
.
wait
()
slapgrid
.
wait
()
#Saves the current compile software for re-use
#Saves the current compile software for re-use
config_SR_folder
(
config
)
config_SR_folder
(
config
)
return
True
return
True
return
False
def
config_SR_folder
(
config
):
def
config_SR_folder
(
config
):
"""Create a symbolik link for each folder in software folder. That allow
"""Create a symbolik link for each folder in software folder. That allow
...
@@ -302,8 +310,9 @@ def loadSoftwareRList(config):
...
@@ -302,8 +310,9 @@ def loadSoftwareRList(config):
def
isInstanceRunning
(
config
=
None
):
def
isInstanceRunning
(
config
=
None
):
"""
"""
Return True if slapgrid-cp is still running and
false if slapgrid if not
Return True if slapgrid-cp is still running and
False otherwise
"""
"""
# XXX-Marco what is 'config' for?
return
isRunning
(
'slapgrid-cp'
)
return
isRunning
(
'slapgrid-cp'
)
...
@@ -312,19 +321,21 @@ def runInstanceWithLock(config):
...
@@ -312,19 +321,21 @@ def runInstanceWithLock(config):
Use Slapgrid to deploy current Software Release and wait until
Use Slapgrid to deploy current Software Release and wait until
deployment is done.
deployment is done.
"""
"""
if
isInstanceRunning
():
return
False
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-cp.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-cp.pid'
)
if
not
isInstanceRunning
():
startProxy
(
config
)
startProxy
(
config
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
)):
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
)):
return
False
return
False
slapgrid
=
Popen
([
config
[
'slapgrid_cp'
],
'-vc'
,
slapgrid
=
Popen
([
config
[
'slapgrid_cp'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
],
config
[
'configuration_file_path'
],
'--now'
],
stdout
=
logfile
,
name
=
'slapgrid-cp'
)
stdout
=
logfile
,
name
=
'slapgrid-cp'
)
slapgrid
.
wait
()
slapgrid
.
wait
()
return
True
return
True
return
False
def
getProfilePath
(
projectDir
,
profile
):
def
getProfilePath
(
projectDir
,
profile
):
"""
"""
...
@@ -431,11 +442,12 @@ def getFolderContent(config, folder):
...
@@ -431,11 +442,12 @@ def getFolderContent(config, folder):
r = ['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
r = ['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
d = urllib.unquote(folder)
d = urllib.unquote(folder)
realdir = realpath(config, d)
realdir = realpath(config, d)
if not realdir:
if realdir:
ldir = sorted(os.listdir(realdir), key=str.lower)
else:
r.append('
Could
not
load
directory
:
Permission
denied
')
r.append('
Could
not
load
directory
:
Permission
denied
')
ldir = []
ldir = []
else:
ldir = sorted(os.listdir(realdir), key=str.lower)
for f in ldir:
for f in ldir:
if f.startswith('
.
'): #do not displays this file/folder
if f.startswith('
.
'): #do not displays this file/folder
continue
continue
...
...
slapos/runner/views.py
View file @
17a77af3
...
@@ -47,17 +47,20 @@ def login_redirect(*args, **kwargs):
...
@@ -47,17 +47,20 @@ def login_redirect(*args, **kwargs):
#Access Control: Only static files and login pages are allowed to guest
#Access Control: Only static files and login pages are allowed to guest
@
app
.
before_request
@
app
.
before_request
def
before_request
():
def
before_request
():
if
not
request
.
path
.
startswith
(
'/static'
):
if
request
.
path
.
startswith
(
'/static'
):
account
=
getSession
(
app
.
config
)
return
if
account
:
user
=
AuthUser
(
username
=
account
[
0
])
account
=
getSession
(
app
.
config
)
user
.
set_and_encrypt_password
(
account
[
1
],
"123400ZYX"
)
if
account
:
session
[
'title'
]
=
getProjectTitle
(
app
.
config
)
user
=
AuthUser
(
username
=
account
[
0
])
g
.
users
=
{
account
[
0
]:
user
}
user
.
set_and_encrypt_password
(
account
[
1
],
"123400ZYX"
)
else
:
session
[
'title'
]
=
getProjectTitle
(
app
.
config
)
session
[
'title'
]
=
"No account is defined"
g
.
users
=
{
account
[
0
]:
user
}
if
request
.
path
!=
"/setAccount"
and
request
.
path
!=
"/configAccount"
:
else
:
return
redirect
(
url_for
(
'setAccount'
))
session
[
'title'
]
=
"No account is defined"
if
request
.
path
!=
"/setAccount"
and
request
.
path
!=
"/configAccount"
:
return
redirect
(
url_for
(
'setAccount'
))
# general views
# general views
@
login_required
()
@
login_required
()
...
@@ -179,7 +182,7 @@ def inspectInstance():
...
@@ -179,7 +182,7 @@ def inspectInstance():
@
login_required
()
@
login_required
()
def
supervisordStatus
():
def
supervisordStatus
():
result
=
getSvcStatus
(
app
.
config
)
result
=
getSvcStatus
(
app
.
config
)
if
not
(
result
)
:
if
not
result
:
return
jsonify
(
code
=
0
,
result
=
""
)
return
jsonify
(
code
=
0
,
result
=
""
)
html
=
"<tr><th>Partition and Process name</th><th>Status</th><th>Process PID </th><th> UpTime</th><th></th></tr>"
html
=
"<tr><th>Partition and Process name</th><th>Status</th><th>Process PID </th><th> UpTime</th><th></th></tr>"
for
item
in
result
:
for
item
in
result
:
...
@@ -521,46 +524,52 @@ def getParameterXml(request):
...
@@ -521,46 +524,52 @@ def getParameterXml(request):
else
:
else
:
return
jsonify
(
code
=
1
,
result
=
parameters
)
return
jsonify
(
code
=
1
,
result
=
parameters
)
#update user account data
#update user account data
@
login_required
()
@
login_required
()
def
updateAccount
():
def
updateAccount
():
account
=
[]
account
.
append
(
request
.
form
[
'username'
].
strip
())
account
.
append
(
request
.
form
[
'password'
].
strip
())
account
.
append
(
request
.
form
[
'email'
].
strip
())
account
.
append
(
request
.
form
[
'name'
].
strip
())
code
=
request
.
form
[
'rcode'
].
strip
()
code
=
request
.
form
[
'rcode'
].
strip
()
recovery_code
=
open
(
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".rcode"
),
"r"
).
read
()
recovery_code
=
open
(
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".rcode"
),
"r"
).
read
()
if
code
!=
recovery_code
:
if
code
!=
recovery_code
:
return
jsonify
(
code
=
0
,
result
=
"Your password recovery code is not valid!"
)
return
jsonify
(
code
=
0
,
result
=
"Your password recovery code is not valid!"
)
account
=
[
request
.
form
[
'username'
].
strip
(),
request
.
form
[
'password'
].
strip
(),
request
.
form
[
'email'
].
strip
(),
request
.
form
[
'name'
].
strip
()
]
result
=
saveSession
(
app
.
config
,
account
)
result
=
saveSession
(
app
.
config
,
account
)
if
type
(
result
)
==
type
(
""
):
if
type
(
result
)
==
type
(
""
):
return
jsonify
(
code
=
0
,
result
=
result
)
return
jsonify
(
code
=
0
,
result
=
result
)
else
:
else
:
return
jsonify
(
code
=
1
,
result
=
""
)
return
jsonify
(
code
=
1
,
result
=
""
)
#update user account data
#update user account data
@
app
.
route
(
"/configAccount"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/configAccount"
,
methods
=
[
'POST'
])
def
configAccount
():
def
configAccount
():
last_account
=
getSession
(
app
.
config
)
last_account
=
getSession
(
app
.
config
)
if
not
last_account
:
if
last_account
:
account
=
[]
return
jsonify
(
code
=
0
,
account
.
append
(
request
.
form
[
'username'
].
strip
())
result
=
"Unable to respond to your request, permission denied."
)
account
.
append
(
request
.
form
[
'password'
].
strip
())
account
.
append
(
request
.
form
[
'email'
].
strip
())
account
=
[]
account
.
append
(
request
.
form
[
'name'
].
strip
())
account
.
append
(
request
.
form
[
'username'
].
strip
())
code
=
request
.
form
[
'rcode'
].
strip
()
account
.
append
(
request
.
form
[
'password'
].
strip
())
recovery_code
=
open
(
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".rcode"
),
account
.
append
(
request
.
form
[
'email'
].
strip
())
"r"
).
read
()
account
.
append
(
request
.
form
[
'name'
].
strip
())
if
code
!=
recovery_code
:
code
=
request
.
form
[
'rcode'
].
strip
()
return
jsonify
(
code
=
0
,
result
=
"Your password recovery code is not valid!"
)
recovery_code
=
open
(
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".rcode"
),
result
=
saveSession
(
app
.
config
,
account
)
"r"
).
read
()
if
type
(
result
)
==
type
(
""
):
if
code
!=
recovery_code
:
return
jsonify
(
code
=
0
,
result
=
result
)
return
jsonify
(
code
=
0
,
result
=
"Your password recovery code is not valid!"
)
else
:
result
=
saveSession
(
app
.
config
,
account
)
return
jsonify
(
code
=
1
,
result
=
""
)
if
type
(
result
)
==
type
(
""
):
return
jsonify
(
code
=
0
,
return
jsonify
(
code
=
0
,
result
=
result
)
result
=
"Unable to respond to your request, permission denied."
)
else
:
return
jsonify
(
code
=
1
,
result
=
""
)
#Global File Manager
#Global File Manager
@
login_required
()
@
login_required
()
...
@@ -576,6 +585,7 @@ def fileBrowser():
...
@@ -576,6 +585,7 @@ def fileBrowser():
opt
=
int
(
request
.
form
[
'opt'
])
opt
=
int
(
request
.
form
[
'opt'
])
else
:
else
:
opt
=
int
(
request
.
args
.
get
(
'opt'
))
opt
=
int
(
request
.
args
.
get
(
'opt'
))
try
:
try
:
if
opt
==
1
:
if
opt
==
1
:
#list files and directories
#list files and directories
...
...
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