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
Justin
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):
computer
.
updateConfiguration
(
xml_marshaller
.
xml_marshaller
.
dumps
(
slap_config
))
return
True
def
updateInstanceParameter
(
config
,
software_type
=
None
):
"""
Reconfigure Slapproxy to re-deploy current Software Instance with parameters.
...
...
@@ -193,15 +194,18 @@ def updateInstanceParameter(config, software_type=None):
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
,
software_type
)):
return
False
def
startProxy
(
config
):
"""Start Slapproxy server"""
if
not
isRunning
(
'slapproxy'
):
log
=
os
.
path
.
join
(
config
[
'log_dir'
],
'slapproxy.log'
)
Popen
([
config
[
'slapproxy'
],
'--log_file'
,
log
,
config
[
'configuration_file_path'
]],
name
=
'slapproxy'
,
stdout
=
None
)
time
.
sleep
(
4
)
if
isRunning
(
'slapproxy'
):
return
log
=
os
.
path
.
join
(
config
[
'log_dir'
],
'slapproxy.log'
)
Popen
([
config
[
'slapproxy'
],
'--log_file'
,
log
,
config
[
'configuration_file_path'
]],
name
=
'slapproxy'
,
stdout
=
None
)
time
.
sleep
(
4
)
def
stopProxy
(
config
):
...
...
@@ -219,6 +223,7 @@ def isSoftwareRunning(config=None):
"""
Return True if slapgrid-sr is still running and false if slapgrid if not
"""
# XXX-Marco what is 'config' for?
return
isRunning
(
'slapgrid-sr'
)
...
...
@@ -227,29 +232,32 @@ def runSoftwareWithLock(config):
Use Slapgrid to compile current Software Release and wait until
compilation is done
"""
if
isSoftwareRunning
():
return
False
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-sr.pid'
)
if
not
isSoftwareRunning
(
):
if
not
os
.
path
.
exists
(
config
[
'software_root'
]):
os
.
mkdir
(
config
[
'software_root'
]
)
stopProxy
(
config
)
removeProxyDb
(
config
)
startProxy
(
config
)
logfile
=
open
(
config
[
'software_log'
],
'w'
)
if
not
updateProxy
(
config
):
return
False
# Accelerate compilation by setting make -jX
environment
=
os
.
environ
.
copy
()
environment
[
'MAKEFLAGS'
]
=
'-j%r'
%
multiprocessing
.
cpu_count
()
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
,
'--develop'
],
stdout
=
logfile
,
env
=
environment
,
name
=
'slapgrid-sr'
)
slapgrid
.
wait
()
#Saves the current compile software for re-use
config_SR_folder
(
config
)
return
True
return
False
if
not
os
.
path
.
exists
(
config
[
'software_root'
]
):
os
.
mkdir
(
config
[
'software_root'
])
stopProxy
(
config
)
removeProxyDb
(
config
)
startProxy
(
config
)
logfile
=
open
(
config
[
'software_log'
],
'w'
)
if
not
updateProxy
(
config
):
return
False
# 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
[
'MAKEFLAGS'
]
=
'-j%r'
%
multiprocessing
.
cpu_count
()
slapgrid
=
Popen
([
config
[
'slapgrid_sr'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
,
'--develop'
],
stdout
=
logfile
,
env
=
environment
,
name
=
'slapgrid-sr'
)
slapgrid
.
wait
()
#Saves the current compile software for re-use
config_SR_folder
(
config
)
return
True
def
config_SR_folder
(
config
):
"""Create a symbolik link for each folder in software folder. That allow
...
...
@@ -302,8 +310,9 @@ def loadSoftwareRList(config):
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'
)
...
...
@@ -312,19 +321,21 @@ def runInstanceWithLock(config):
Use Slapgrid to deploy current Software Release and wait until
deployment is done.
"""
if
isInstanceRunning
():
return
False
slapgrid_pid
=
os
.
path
.
join
(
config
[
'run_dir'
],
'slapgrid-cp.pid'
)
if
not
isInstanceRunning
():
startProxy
(
config
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
)):
return
False
slapgrid
=
Popen
([
config
[
'slapgrid_cp'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
],
stdout
=
logfile
,
name
=
'slapgrid-cp'
)
slapgrid
.
wait
()
return
True
return
False
startProxy
(
config
)
logfile
=
open
(
config
[
'instance_log'
],
'w'
)
if
not
(
updateProxy
(
config
)
and
requestInstance
(
config
)):
return
False
slapgrid
=
Popen
([
config
[
'slapgrid_cp'
],
'-vc'
,
'--pidfile'
,
slapgrid_pid
,
config
[
'configuration_file_path'
],
'--now'
],
stdout
=
logfile
,
name
=
'slapgrid-cp'
)
slapgrid
.
wait
()
return
True
def
getProfilePath
(
projectDir
,
profile
):
"""
...
...
@@ -431,11 +442,12 @@ def getFolderContent(config, folder):
r = ['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
d = urllib.unquote(folder)
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
')
ldir = []
else:
ldir = sorted(os.listdir(realdir), key=str.lower)
for f in ldir:
if f.startswith('
.
'): #do not displays this file/folder
continue
...
...
slapos/runner/views.py
View file @
17a77af3
...
...
@@ -47,17 +47,20 @@ def login_redirect(*args, **kwargs):
#Access Control: Only static files and login pages are allowed to guest
@
app
.
before_request
def
before_request
():
if
not
request
.
path
.
startswith
(
'/static'
):
account
=
getSession
(
app
.
config
)
if
account
:
user
=
AuthUser
(
username
=
account
[
0
])
user
.
set_and_encrypt_password
(
account
[
1
],
"123400ZYX"
)
session
[
'title'
]
=
getProjectTitle
(
app
.
config
)
g
.
users
=
{
account
[
0
]:
user
}
else
:
session
[
'title'
]
=
"No account is defined"
if
request
.
path
!=
"/setAccount"
and
request
.
path
!=
"/configAccount"
:
return
redirect
(
url_for
(
'setAccount'
))
if
request
.
path
.
startswith
(
'/static'
):
return
account
=
getSession
(
app
.
config
)
if
account
:
user
=
AuthUser
(
username
=
account
[
0
])
user
.
set_and_encrypt_password
(
account
[
1
],
"123400ZYX"
)
session
[
'title'
]
=
getProjectTitle
(
app
.
config
)
g
.
users
=
{
account
[
0
]:
user
}
else
:
session
[
'title'
]
=
"No account is defined"
if
request
.
path
!=
"/setAccount"
and
request
.
path
!=
"/configAccount"
:
return
redirect
(
url_for
(
'setAccount'
))
# general views
@
login_required
()
...
...
@@ -179,7 +182,7 @@ def inspectInstance():
@
login_required
()
def
supervisordStatus
():
result
=
getSvcStatus
(
app
.
config
)
if
not
(
result
)
:
if
not
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>"
for
item
in
result
:
...
...
@@ -521,46 +524,52 @@ def getParameterXml(request):
else
:
return
jsonify
(
code
=
1
,
result
=
parameters
)
#update user account data
@
login_required
()
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
()
recovery_code
=
open
(
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".rcode"
),
"r"
).
read
()
if
code
!=
recovery_code
:
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
)
if
type
(
result
)
==
type
(
""
):
return
jsonify
(
code
=
0
,
result
=
result
)
else
:
return
jsonify
(
code
=
1
,
result
=
""
)
#update user account data
@
app
.
route
(
"/configAccount"
,
methods
=
[
'POST'
])
def
configAccount
():
last_account
=
getSession
(
app
.
config
)
if
not
last_account
:
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
()
recovery_code
=
open
(
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".rcode"
),
"r"
).
read
()
if
code
!=
recovery_code
:
return
jsonify
(
code
=
0
,
result
=
"Your password recovery code is not valid!"
)
result
=
saveSession
(
app
.
config
,
account
)
if
type
(
result
)
==
type
(
""
):
return
jsonify
(
code
=
0
,
result
=
result
)
else
:
return
jsonify
(
code
=
1
,
result
=
""
)
return
jsonify
(
code
=
0
,
result
=
"Unable to respond to your request, permission denied."
)
if
last_account
:
return
jsonify
(
code
=
0
,
result
=
"Unable to respond to your request, permission denied."
)
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
()
recovery_code
=
open
(
os
.
path
.
join
(
app
.
config
[
'etc_dir'
],
".rcode"
),
"r"
).
read
()
if
code
!=
recovery_code
:
return
jsonify
(
code
=
0
,
result
=
"Your password recovery code is not valid!"
)
result
=
saveSession
(
app
.
config
,
account
)
if
type
(
result
)
==
type
(
""
):
return
jsonify
(
code
=
0
,
result
=
result
)
else
:
return
jsonify
(
code
=
1
,
result
=
""
)
#Global File Manager
@
login_required
()
...
...
@@ -576,6 +585,7 @@ def fileBrowser():
opt
=
int
(
request
.
form
[
'opt'
])
else
:
opt
=
int
(
request
.
args
.
get
(
'opt'
))
try
:
if
opt
==
1
:
#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