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
Tristan Cavelier
slapos.toolbox
Commits
decbd4b3
Commit
decbd4b3
authored
Jun 29, 2012
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding comments
parent
5d472df2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
205 additions
and
4 deletions
+205
-4
slapos/runner/gittools.py
slapos/runner/gittools.py
+33
-0
slapos/runner/utils.py
slapos/runner/utils.py
+161
-4
slapos/runner/views.py
slapos/runner/views.py
+11
-0
No files found.
slapos/runner/gittools.py
View file @
decbd4b3
...
@@ -23,6 +23,15 @@ class Popen(subprocess.Popen):
...
@@ -23,6 +23,15 @@ class Popen(subprocess.Popen):
self
.
stdin
=
None
self
.
stdin
=
None
def
cloneRepo
(
data
):
def
cloneRepo
(
data
):
"""Clonne a repository
Args:
data: a dictionnary of parameters to use:
data['path'] is the path of the new project
data['repo'] is the url of the repository to be cloned
data['email'] is the user email
data['user'] is the name of the user
Returns:
a jsonify data"""
workDir
=
data
[
'path'
]
workDir
=
data
[
'path'
]
if
not
workDir
:
if
not
workDir
:
return
jsonify
(
code
=
0
,
return
jsonify
(
code
=
0
,
...
@@ -47,6 +56,11 @@ def cloneRepo(data):
...
@@ -47,6 +56,11 @@ def cloneRepo(data):
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
def
gitStatus
(
project
):
def
gitStatus
(
project
):
"""Run git status and return status of specified project folder
Args:
project: path of the projet ti get status
Returns:
a parsed string that contains the result of git status"""
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
...
@@ -61,6 +75,12 @@ def gitStatus(project):
...
@@ -61,6 +75,12 @@ def gitStatus(project):
return
jsonify
(
code
=
code
,
result
=
json
,
branch
=
branch
,
dirty
=
isdirty
)
return
jsonify
(
code
=
code
,
result
=
json
,
branch
=
branch
,
dirty
=
isdirty
)
def
switchBranch
(
project
,
name
):
def
switchBranch
(
project
,
name
):
"""Switch a git branch
Args:
project: directory of the local git repository
name: switch from current branch to `name` branch
Returns:
a jsonify data"""
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
...
@@ -78,6 +98,13 @@ def switchBranch(project, name):
...
@@ -78,6 +98,13 @@ def switchBranch(project, name):
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
def
addBranch
(
project
,
name
,
onlyCheckout
=
False
):
def
addBranch
(
project
,
name
,
onlyCheckout
=
False
):
"""Add new git branch to the repository
Args:
project: directory of the local git repository
name: name of the new branch
onlyCheckout: if True then the branch `name` is created before checkout
Returns:
a jsonify data"""
code
=
0
code
=
0
json
=
""
json
=
""
try
:
try
:
...
@@ -93,6 +120,7 @@ def addBranch(project, name, onlyCheckout=False):
...
@@ -93,6 +120,7 @@ def addBranch(project, name, onlyCheckout=False):
return
jsonify
(
code
=
code
,
result
=
json
)
return
jsonify
(
code
=
code
,
result
=
json
)
def
getDiff
(
project
):
def
getDiff
(
project
):
"""Get git diff for the specified project directory"""
result
=
""
result
=
""
try
:
try
:
repo
=
Repo
(
project
)
repo
=
Repo
(
project
)
...
@@ -104,6 +132,10 @@ def getDiff(project):
...
@@ -104,6 +132,10 @@ def getDiff(project):
return
result
return
result
def
gitPush
(
project
,
msg
):
def
gitPush
(
project
,
msg
):
"""Commit and Push changes for the specified repository
Args:
project: directory of the local repository
msg: commit message"""
code
=
0
code
=
0
json
=
""
json
=
""
undo_commit
=
False
undo_commit
=
False
...
@@ -145,5 +177,6 @@ def gitPull(project):
...
@@ -145,5 +177,6 @@ def gitPull(project):
return
jsonify
(
code
=
code
,
result
=
result
)
return
jsonify
(
code
=
code
,
result
=
result
)
def
safeResult
(
result
):
def
safeResult
(
result
):
"""Parse string and remove credential of the user"""
regex
=
re
.
compile
(
"(https:
\
/
\
/)([
\
w
\
d
\
._-]+:[
\
w
\
d
\
._-]+)
\
@([
\
S]+
\
s)
"
, re.VERBOSE)
regex
=
re
.
compile
(
"(https:
\
/
\
/)([
\
w
\
d
\
._-]+:[
\
w
\
d
\
._-]+)
\
@([
\
S]+
\
s)
"
, re.VERBOSE)
return regex.sub(r'
\
1
\
3
', result)
return regex.sub(r'
\
1
\
3
', result)
\ No newline at end of file
slapos/runner/utils.py
View file @
decbd4b3
...
@@ -41,6 +41,17 @@ def html_escape(text):
...
@@ -41,6 +41,17 @@ def html_escape(text):
return
""
.
join
(
html_escape_table
.
get
(
c
,
c
)
for
c
in
text
)
return
""
.
join
(
html_escape_table
.
get
(
c
,
c
)
for
c
in
text
)
def
checkLogin
(
config
,
login
,
pwd
):
def
checkLogin
(
config
,
login
,
pwd
):
"""
User authentication method
Args:
config: Slaprunner configuration.
login: username of the user.
pwd: password associate to username.
Returns:
a list of user informations or False if authentication fail.
"""
user
=
getSession
(
config
)
user
=
getSession
(
config
)
salt
=
"runner81"
#to be changed
salt
=
"runner81"
#to be changed
current_pwd
=
hashlib
.
md5
(
salt
+
pwd
).
hexdigest
()
current_pwd
=
hashlib
.
md5
(
salt
+
pwd
).
hexdigest
()
...
@@ -49,6 +60,11 @@ def checkLogin(config, login, pwd):
...
@@ -49,6 +60,11 @@ def checkLogin(config, login, pwd):
return
False
return
False
def
getSession
(
config
):
def
getSession
(
config
):
"""
Get the session data of current user.
Returns:
a list of user informations or False if fail to read data.
"""
user_path
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'.users'
)
user_path
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'.users'
)
user
=
""
user
=
""
if
os
.
path
.
exists
(
user_path
):
if
os
.
path
.
exists
(
user_path
):
...
@@ -63,6 +79,17 @@ def getSession(config):
...
@@ -63,6 +79,17 @@ def getSession(config):
return
user
return
user
def
saveSession
(
config
,
session
,
account
):
def
saveSession
(
config
,
session
,
account
):
"""
Save account information for the current user
Args:
config: Slaprunner configuration
session: Flask session
account: New session data to be save
Returns:
True if all goes well or str (error message) if fail
"""
user
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'.users'
)
user
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'.users'
)
backup
=
False
backup
=
False
try
:
try
:
...
@@ -88,6 +115,10 @@ def saveSession(config, session, account):
...
@@ -88,6 +115,10 @@ def saveSession(config, session, account):
return
str
(
e
)
return
str
(
e
)
def
updateProxy
(
config
):
def
updateProxy
(
config
):
"""
Configure Slapos Node computer and partitions.
Send current Software Release to Slapproxy for compilation and deployment.
"""
if
not
os
.
path
.
exists
(
config
[
'instance_root'
]):
if
not
os
.
path
.
exists
(
config
[
'instance_root'
]):
os
.
mkdir
(
config
[
'instance_root'
])
os
.
mkdir
(
config
[
'instance_root'
])
slap
=
slapos
.
slap
.
slap
()
slap
=
slapos
.
slap
.
slap
()
...
@@ -141,6 +172,7 @@ def updateProxy(config):
...
@@ -141,6 +172,7 @@ def updateProxy(config):
return
True
return
True
def
readPid
(
file
):
def
readPid
(
file
):
"""Read process pid from file `file`"""
if
os
.
path
.
exists
(
file
):
if
os
.
path
.
exists
(
file
):
data
=
open
(
file
).
read
().
strip
()
data
=
open
(
file
).
read
().
strip
()
try
:
try
:
...
@@ -151,9 +183,17 @@ def readPid(file):
...
@@ -151,9 +183,17 @@ def readPid(file):
def
writePid
(
file
,
pid
):
def
writePid
(
file
,
pid
):
"""Save process pid into a file `file`"""
open
(
file
,
'w'
).
write
(
str
(
pid
))
open
(
file
,
'w'
).
write
(
str
(
pid
))
def
updateInstanceParameter
(
config
,
software_type
=
None
):
def
updateInstanceParameter
(
config
,
software_type
=
None
):
"""
Reconfigure Slapproxy to re-deploy current Software Instance with parameters.
Args:
config: Slaprunner configuration.
software_type: reconfigure Software Instance with software type.
"""
slap
=
slapos
.
slap
.
slap
()
slap
=
slapos
.
slap
.
slap
()
slap
.
initializeConnection
(
config
[
'master_url'
])
slap
.
initializeConnection
(
config
[
'master_url'
])
#Get current software release profile
#Get current software release profile
...
@@ -163,7 +203,7 @@ def updateInstanceParameter(config, software_type=None):
...
@@ -163,7 +203,7 @@ def updateInstanceParameter(config, software_type=None):
profile
=
realpath
(
config
,
os
.
path
.
join
(
software_folder
,
profile
=
realpath
(
config
,
os
.
path
.
join
(
software_folder
,
config
[
'software_profile'
]))
config
[
'software_profile'
]))
except
:
except
:
r
eturn
False
r
aise
Exception
(
"Software Release profile not found"
)
#get instance parameter
#get instance parameter
param_path
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
".parameter.xml"
)
param_path
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
".parameter.xml"
)
xml_result
=
readParameters
(
param_path
)
xml_result
=
readParameters
(
param_path
)
...
@@ -175,6 +215,7 @@ def updateInstanceParameter(config, software_type=None):
...
@@ -175,6 +215,7 @@ def updateInstanceParameter(config, software_type=None):
filter_kw
=
None
,
state
=
None
,
shared
=
False
)
filter_kw
=
None
,
state
=
None
,
shared
=
False
)
def
startProxy
(
config
):
def
startProxy
(
config
):
"""Start Slapproxy server"""
proxy_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'proxy.pid'
)
proxy_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'proxy.pid'
)
pid
=
readPid
(
proxy_pid
)
pid
=
readPid
(
proxy_pid
)
running
=
False
running
=
False
...
@@ -193,6 +234,7 @@ def startProxy(config):
...
@@ -193,6 +234,7 @@ def startProxy(config):
def
stopProxy
(
config
):
def
stopProxy
(
config
):
"""Stop Slapproxy server"""
pid
=
readPid
(
os
.
path
.
join
(
config
[
'runner_workdir'
],
'proxy.pid'
))
pid
=
readPid
(
os
.
path
.
join
(
config
[
'runner_workdir'
],
'proxy.pid'
))
if
pid
:
if
pid
:
try
:
try
:
...
@@ -202,10 +244,15 @@ def stopProxy(config):
...
@@ -202,10 +244,15 @@ def stopProxy(config):
def
removeProxyDb
(
config
):
def
removeProxyDb
(
config
):
"""Remove Slapproxy database, this is use to initialize proxy for example when
configuring new Software Release"""
if
os
.
path
.
exists
(
config
[
'database_uri'
]):
if
os
.
path
.
exists
(
config
[
'database_uri'
]):
os
.
unlink
(
config
[
'database_uri'
])
os
.
unlink
(
config
[
'database_uri'
])
def
isSoftwareRunning
(
config
):
def
isSoftwareRunning
(
config
):
"""
Return True if slapgrid-sr is still running and false if slapgrid if not
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-sr.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-sr.pid'
)
pid
=
readPid
(
slapgrid_pid
)
pid
=
readPid
(
slapgrid_pid
)
if
pid
:
if
pid
:
...
@@ -221,6 +268,10 @@ def isSoftwareRunning(config):
...
@@ -221,6 +268,10 @@ def isSoftwareRunning(config):
def
runSoftwareWithLock
(
config
):
def
runSoftwareWithLock
(
config
):
"""
Use Slapgrid to compile current Software Release and wait until
compilation is done
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-sr.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-sr.pid'
)
if
not
isSoftwareRunning
(
config
):
if
not
isSoftwareRunning
(
config
):
if
not
os
.
path
.
exists
(
config
[
'software_root'
]):
if
not
os
.
path
.
exists
(
config
[
'software_root'
]):
...
@@ -262,6 +313,9 @@ def runSoftwareWithLock(config):
...
@@ -262,6 +313,9 @@ def runSoftwareWithLock(config):
def
isInstanceRunning
(
config
):
def
isInstanceRunning
(
config
):
"""
Return True if slapgrid-cp is still running and false if slapgrid if not
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-cp.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-cp.pid'
)
pid
=
readPid
(
slapgrid_pid
)
pid
=
readPid
(
slapgrid_pid
)
if
pid
:
if
pid
:
...
@@ -276,6 +330,7 @@ def isInstanceRunning(config):
...
@@ -276,6 +330,7 @@ def isInstanceRunning(config):
return
running
return
running
def
killRunningSlapgrid
(
config
,
ptype
):
def
killRunningSlapgrid
(
config
,
ptype
):
"""Kill slapgrid process and all running children process"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
ptype
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
ptype
)
pid
=
readPid
(
slapgrid_pid
)
pid
=
readPid
(
slapgrid_pid
)
if
pid
:
if
pid
:
...
@@ -304,6 +359,10 @@ def pidppid(pid):
...
@@ -304,6 +359,10 @@ def pidppid(pid):
return
list
(
int
(
p
)
for
p
,
pp
in
ppid
if
int
(
pp
)
==
pid
)
return
list
(
int
(
p
)
for
p
,
pp
in
ppid
if
int
(
pp
)
==
pid
)
def
runInstanceWithLock
(
config
):
def
runInstanceWithLock
(
config
):
"""
Use Slapgrid to deploy current Software Release and wait until
deployment is done.
"""
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-cp.pid'
)
slapgrid_pid
=
os
.
path
.
join
(
config
[
'runner_workdir'
],
'slapgrid-cp.pid'
)
if
not
isInstanceRunning
(
config
):
if
not
isInstanceRunning
(
config
):
startProxy
(
config
)
startProxy
(
config
)
...
@@ -317,13 +376,24 @@ def runInstanceWithLock(config):
...
@@ -317,13 +376,24 @@ def runInstanceWithLock(config):
return
True
return
True
return
False
return
False
def
getProfilePath
(
peojectDir
,
profile
):
def
getProfilePath
(
projectDir
,
profile
):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
peojectDir
,
".project"
)):
"""
Return the path of the current Software Release `profile`
Args:
projectDir: Slaprunner workspace location.
profile: file to search into the workspace.
Returns:
String, path of current Software Release profile
"""
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
projectDir
,
".project"
)):
return
False
return
False
projectFolder
=
open
(
os
.
path
.
join
(
p
e
ojectDir
,
".project"
)).
read
()
projectFolder
=
open
(
os
.
path
.
join
(
p
r
ojectDir
,
".project"
)).
read
()
return
os
.
path
.
join
(
projectFolder
,
profile
)
return
os
.
path
.
join
(
projectFolder
,
profile
)
def
getSlapStatus
(
config
):
def
getSlapStatus
(
config
):
"""Return all Slapos Partitions with associate informations"""
slap
=
slapos
.
slap
.
slap
()
slap
=
slapos
.
slap
.
slap
()
slap
.
initializeConnection
(
config
[
'master_url'
])
slap
.
initializeConnection
(
config
[
'master_url'
])
partition_list
=
[]
partition_list
=
[]
...
@@ -354,10 +424,12 @@ def runBuildoutAnnotate(config):
...
@@ -354,10 +424,12 @@ def runBuildoutAnnotate(config):
return
False
return
False
def
svcStopAll
(
config
):
def
svcStopAll
(
config
):
"""Stop all Instance process on this computer"""
return
Popen
([
config
[
'supervisor'
],
config
[
'configuration_file_path'
],
return
Popen
([
config
[
'supervisor'
],
config
[
'configuration_file_path'
],
'shutdown'
]).
communicate
()[
0
]
'shutdown'
]).
communicate
()[
0
]
def
removeInstanceRoot
(
config
):
def
removeInstanceRoot
(
config
):
"""Clean instance directory and stop all its running process"""
if
os
.
path
.
exists
(
config
[
'instance_root'
]):
if
os
.
path
.
exists
(
config
[
'instance_root'
]):
svcStopAll
(
config
)
svcStopAll
(
config
)
for
root
,
dirs
,
files
in
os
.
walk
(
config
[
'instance_root'
]):
for
root
,
dirs
,
files
in
os
.
walk
(
config
[
'instance_root'
]):
...
@@ -369,6 +441,7 @@ def removeInstanceRoot(config):
...
@@ -369,6 +441,7 @@ def removeInstanceRoot(config):
shutil
.
rmtree
(
config
[
'instance_root'
])
shutil
.
rmtree
(
config
[
'instance_root'
])
def
getSvcStatus
(
config
):
def
getSvcStatus
(
config
):
"""Return all Softwares Instances process Informations"""
result
=
Popen
([
config
[
'supervisor'
],
config
[
'configuration_file_path'
],
result
=
Popen
([
config
[
'supervisor'
],
config
[
'configuration_file_path'
],
'status'
]).
communicate
()[
0
]
'status'
]).
communicate
()[
0
]
regex
=
"(^unix:.+
\
.socke
t
)|(^error:).*$"
regex
=
"(^unix:.+
\
.socke
t
)|(^error:).*$"
...
@@ -382,15 +455,40 @@ def getSvcStatus(config):
...
@@ -382,15 +455,40 @@ def getSvcStatus(config):
return supervisord
return supervisord
def getSvcTailProcess(config, process):
def getSvcTailProcess(config, process):
"""Get log for the specifie process
Args:
config: Slaprunner configuration
process: process name. this value is pass to supervisord.
Returns:
a string that contains the log of the process.
"""
return Popen([config['
supervisor
'], config['
configuration_file_path
'],
return Popen([config['
supervisor
'], config['
configuration_file_path
'],
"tail", process]).communicate()[0]
"tail", process]).communicate()[0]
def svcStartStopProcess(config, process, action):
def svcStartStopProcess(config, process, action):
"""Send start or stop process command to supervisord
Args:
config: Slaprunner configuration.
process: process to start or stop.
action: current state which is used to generate the new process state.
"""
cmd = {"RESTART":"restart", "STOPPED":"start", "RUNNING":"stop", "EXITED":"start", "STOP":"stop"}
cmd = {"RESTART":"restart", "STOPPED":"start", "RUNNING":"stop", "EXITED":"start", "STOP":"stop"}
return Popen([config['
supervisor
'], config['
configuration_file_path
'],
return Popen([config['
supervisor
'], config['
configuration_file_path
'],
cmd[action], process]).communicate()[0]
cmd[action], process]).communicate()[0]
def getFolderContent(config, folder):
def getFolderContent(config, folder):
"""
Read all file and folder into specified directory
Args:
config: Slaprunner configuration.
folder: the directory to read.
Returns:
Html formated string or error message when fail.
"""
r=['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
r=['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
try:
try:
folder = str(folder)
folder = str(folder)
...
@@ -418,6 +516,16 @@ def getFolderContent(config, folder):
...
@@ -418,6 +516,16 @@ def getFolderContent(config, folder):
return jsonify(result=''.join(r))
return jsonify(result=''.join(r))
def getFolder(config, folder):
def getFolder(config, folder):
"""
Read list of folder for the specified directory
Args:
config: Slaprunner configuration.
folder: the directory to read.
Returns:
Html formated string or error message when fail.
"""
r=['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
r=['
<
ul
class
=
"jqueryFileTree"
style
=
"display: none;"
>
']
try:
try:
folder = str(folder)
folder = str(folder)
...
@@ -442,6 +550,13 @@ def getFolder(config, folder):
...
@@ -442,6 +550,13 @@ def getFolder(config, folder):
return jsonify(result=''.join(r))
return jsonify(result=''.join(r))
def getProjectList(folder):
def getProjectList(folder):
"""Return the list of projet (folder) into the workspace
Agrs:
folder: path of the workspace
Returns:
a list that contains each folder name.
"""
project = []
project = []
project_list = sorted(os.listdir(folder), key=str.lower)
project_list = sorted(os.listdir(folder), key=str.lower)
for elt in project_list:
for elt in project_list:
...
@@ -449,6 +564,14 @@ def getProjectList(folder):
...
@@ -449,6 +564,14 @@ def getProjectList(folder):
return project
return project
def configNewSR(config, projectpath):
def configNewSR(config, projectpath):
"""Configure a Software Release as current Software Release
Args:
config: slaprunner configuration
projectpath: path of the directory that contains the software realease to configure
Returns:
True if all is done well, otherwise return false.
"""
folder = realpath(config, projectpath)
folder = realpath(config, projectpath)
if folder:
if folder:
if isInstanceRunning(config):
if isInstanceRunning(config):
...
@@ -465,6 +588,13 @@ def configNewSR(config, projectpath):
...
@@ -465,6 +588,13 @@ def configNewSR(config, projectpath):
return False
return False
def newSoftware(folder, config, session):
def newSoftware(folder, config, session):
"""
Create a new Software Release folder with default profiles
Args:
folder: directory of the new software release
config: slraprunner configuration
session: Flask session directory"""
json = ""
json = ""
code = 0
code = 0
runner_dir = config['
runner_workdir
']
runner_dir = config['
runner_workdir
']
...
@@ -498,12 +628,14 @@ def newSoftware(folder, config, session):
...
@@ -498,12 +628,14 @@ def newSoftware(folder, config, session):
return jsonify(code=code, result=json)
return jsonify(code=code, result=json)
def checkSoftwareFolder(path, config):
def checkSoftwareFolder(path, config):
"""Check id `path` is a valid Software Release folder"""
realdir = realpath(config, path)
realdir = realpath(config, path)
if realdir and os.path.exists(os.path.join(realdir, config['
software_profile
'])):
if realdir and os.path.exists(os.path.join(realdir, config['
software_profile
'])):
return jsonify(result=path)
return jsonify(result=path)
return jsonify(result="")
return jsonify(result="")
def getProjectTitle(config):
def getProjectTitle(config):
"""Generate the name of the current software Release (for slaprunner UI)"""
conf = os.path.join(config['
runner_workdir
'], ".project")
conf = os.path.join(config['
runner_workdir
'], ".project")
if os.path.exists(conf):
if os.path.exists(conf):
project = open(conf, "r").read().split("/")
project = open(conf, "r").read().split("/")
...
@@ -512,6 +644,7 @@ def getProjectTitle(config):
...
@@ -512,6 +644,7 @@ def getProjectTitle(config):
return "No Profile"
return "No Profile"
def getSoftwareReleaseName(config):
def getSoftwareReleaseName(config):
"""Get the name of the current Software Release"""
sr_profile = os.path.join(config['
runner_workdir
'], ".project")
sr_profile = os.path.join(config['
runner_workdir
'], ".project")
if os.path.exists(sr_profile):
if os.path.exists(sr_profile):
project = open(sr_profile, "r").read().split("/")
project = open(sr_profile, "r").read().split("/")
...
@@ -520,6 +653,12 @@ def getSoftwareReleaseName(config):
...
@@ -520,6 +653,12 @@ def getSoftwareReleaseName(config):
return "No_name"
return "No_name"
def loadSoftwareData(runner_dir):
def loadSoftwareData(runner_dir):
"""Get All Compiled Softwares Releases name and directory
Agrs:
runner_dir: base directory of slapos web runner.
Returns:
a dictionnary that contains all compiled Software Release with path"""
import pickle
import pickle
file_path = os.path.join(runner_dir, '
.
softdata
')
file_path = os.path.join(runner_dir, '
.
softdata
')
if not os.path.exists(file_path):
if not os.path.exists(file_path):
...
@@ -530,6 +669,12 @@ def loadSoftwareData(runner_dir):
...
@@ -530,6 +669,12 @@ def loadSoftwareData(runner_dir):
return data
return data
def writeSoftwareData(runner_dir, data):
def writeSoftwareData(runner_dir, data):
"""Save the list of compiled Software Release into a file
Args:
runner_dir: base directory of slapos web runner.
data: dictionnary data about real name and directory of each software release
"""
import pickle
import pickle
file_path = os.path.join(runner_dir, '
.
softdata
')
file_path = os.path.join(runner_dir, '
.
softdata
')
pkl_file = open(file_path, '
wb
')
pkl_file = open(file_path, '
wb
')
...
@@ -538,6 +683,11 @@ def writeSoftwareData(runner_dir, data):
...
@@ -538,6 +683,11 @@ def writeSoftwareData(runner_dir, data):
pkl_file.close()
pkl_file.close()
def removeSoftwareByName(config, folderName):
def removeSoftwareByName(config, folderName):
"""Remove all content of the specified software release
Args:
config: slaprunner configuration
foldername: the name given to the software release"""
if isSoftwareRunning(config) or isInstanceRunning(config):
if isSoftwareRunning(config) or isInstanceRunning(config):
raise Exception("Software installation or instantiation in progress, cannot remove")
raise Exception("Software installation or instantiation in progress, cannot remove")
path = os.path.join(config['
software_root
'], folderName)
path = os.path.join(config['
software_root
'], folderName)
...
@@ -662,6 +812,13 @@ def realpath(config, path, check_exist=True):
...
@@ -662,6 +812,13 @@ def realpath(config, path, check_exist=True):
return False
return False
def readParameters(path):
def readParameters(path):
"""Read Instance parameters stored into a local file.
Agrs:
path: path of the xml file that contains parameters
Return:
a dictionnary of instance parameters."""
if os.path.exists(path):
if os.path.exists(path):
try:
try:
xmldoc = minidom.parse(path)
xmldoc = minidom.parse(path)
...
...
slapos/runner/views.py
View file @
decbd4b3
...
@@ -77,6 +77,7 @@ def inspectSoftware():
...
@@ -77,6 +77,7 @@ def inspectSoftware():
return
render_template
(
'runResult.html'
,
softwareRoot
=
'software_root'
,
return
render_template
(
'runResult.html'
,
softwareRoot
=
'software_root'
,
softwares
=
loadSoftwareData
(
app
.
config
[
'runner_workdir'
]))
softwares
=
loadSoftwareData
(
app
.
config
[
'runner_workdir'
]))
#remove content of compiled software release
@
app
.
route
(
'/removeSoftware'
)
@
app
.
route
(
'/removeSoftware'
)
def
removeSoftware
():
def
removeSoftware
():
file_config
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".softdata"
)
file_config
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".softdata"
)
...
@@ -114,6 +115,7 @@ def editInstanceProfile():
...
@@ -114,6 +115,7 @@ def editInstanceProfile():
return
render_template
(
'updateInstanceProfile.html'
,
workDir
=
'workspace'
,
return
render_template
(
'updateInstanceProfile.html'
,
workDir
=
'workspace'
,
profile
=
profile
,
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
profile
=
profile
,
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
# get status of all computer partitions and process state
@
app
.
route
(
'/inspectInstance'
,
methods
=
[
'GET'
])
@
app
.
route
(
'/inspectInstance'
,
methods
=
[
'GET'
])
def
inspectInstance
():
def
inspectInstance
():
file_content
=
''
file_content
=
''
...
@@ -127,6 +129,7 @@ def inspectInstance():
...
@@ -127,6 +129,7 @@ def inspectInstance():
file_path
=
file_content
,
supervisor
=
result
,
slap_status
=
getSlapStatus
(
app
.
config
),
file_path
=
file_content
,
supervisor
=
result
,
slap_status
=
getSlapStatus
(
app
.
config
),
supervisore
=
result
,
partition_amount
=
app
.
config
[
'partition_amount'
])
supervisore
=
result
,
partition_amount
=
app
.
config
[
'partition_amount'
])
#Reload instance process ans returns new value to ajax
@
app
.
route
(
'/supervisordStatus'
,
methods
=
[
'GET'
])
@
app
.
route
(
'/supervisordStatus'
,
methods
=
[
'GET'
])
def
supervisordStatus
():
def
supervisordStatus
():
result
=
getSvcStatus
(
app
.
config
)
result
=
getSvcStatus
(
app
.
config
)
...
@@ -253,6 +256,7 @@ def getProjectStatus():
...
@@ -253,6 +256,7 @@ def getProjectStatus():
else
:
else
:
return
jsonify
(
code
=
0
,
result
=
"Can not read folder: Permission Denied"
)
return
jsonify
(
code
=
0
,
result
=
"Can not read folder: Permission Denied"
)
#view for current software release files
@
app
.
route
(
"/editCurrentProject"
)
@
app
.
route
(
"/editCurrentProject"
)
def
editCurrentProject
():
def
editCurrentProject
():
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
...
@@ -262,6 +266,7 @@ def editCurrentProject():
...
@@ -262,6 +266,7 @@ def editCurrentProject():
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
projectList
=
getProjectList
(
app
.
config
[
'workspace'
]))
return
redirect
(
url_for
(
'configRepo'
))
return
redirect
(
url_for
(
'configRepo'
))
#create file or directory
@
app
.
route
(
"/createFile"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/createFile"
,
methods
=
[
'POST'
])
def
createFile
():
def
createFile
():
path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
],
False
)
path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
],
False
)
...
@@ -277,6 +282,7 @@ def createFile():
...
@@ -277,6 +282,7 @@ def createFile():
except
Exception
,
e
:
except
Exception
,
e
:
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
#remove file or directory
@
app
.
route
(
"/removeFile"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/removeFile"
,
methods
=
[
'POST'
])
def
removeFile
():
def
removeFile
():
try
:
try
:
...
@@ -296,6 +302,7 @@ def removeSoftwareDir():
...
@@ -296,6 +302,7 @@ def removeSoftwareDir():
except
Exception
,
e
:
except
Exception
,
e
:
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
return
jsonify
(
code
=
0
,
result
=
str
(
e
))
#read file and return content to ajax
@
app
.
route
(
"/getFileContent"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/getFileContent"
,
methods
=
[
'POST'
])
def
getFileContent
():
def
getFileContent
():
file_path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
])
file_path
=
realpath
(
app
.
config
,
request
.
form
[
'file'
])
...
@@ -379,6 +386,7 @@ def getmd5sum():
...
@@ -379,6 +386,7 @@ def getmd5sum():
else
:
else
:
return
jsonify
(
code
=
0
,
result
=
"Can not get md5sum for this file!"
)
return
jsonify
(
code
=
0
,
result
=
"Can not get md5sum for this file!"
)
#return informations about state of slapgrid process
@
app
.
route
(
"/slapgridResult"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/slapgridResult"
,
methods
=
[
'POST'
])
def
slapgridResult
():
def
slapgridResult
():
software_state
=
isSoftwareRunning
(
app
.
config
)
software_state
=
isSoftwareRunning
(
app
.
config
)
...
@@ -415,6 +423,7 @@ def getPath():
...
@@ -415,6 +423,7 @@ def getPath():
else
:
else
:
return
jsonify
(
code
=
1
,
result
=
realfile
)
return
jsonify
(
code
=
1
,
result
=
realfile
)
#update instance parameter into a local xml file
@
app
.
route
(
"/saveParameterXml"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/saveParameterXml"
,
methods
=
[
'POST'
])
def
saveParameterXml
():
def
saveParameterXml
():
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
project
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".project"
)
...
@@ -441,6 +450,7 @@ def saveParameterXml():
...
@@ -441,6 +450,7 @@ def saveParameterXml():
return
jsonify
(
code
=
0
,
result
=
"An error occurred while applying your settings!<br/>"
+
str
(
e
))
return
jsonify
(
code
=
0
,
result
=
"An error occurred while applying your settings!<br/>"
+
str
(
e
))
return
jsonify
(
code
=
1
,
result
=
""
)
return
jsonify
(
code
=
1
,
result
=
""
)
#read instance parameters into the local xml file and return a dict
@
app
.
route
(
"/getParameterXml/<request>"
,
methods
=
[
'GET'
])
@
app
.
route
(
"/getParameterXml/<request>"
,
methods
=
[
'GET'
])
def
getParameterXml
(
request
):
def
getParameterXml
(
request
):
param_path
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".parameter.xml"
)
param_path
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".parameter.xml"
)
...
@@ -457,6 +467,7 @@ def getParameterXml(request):
...
@@ -457,6 +467,7 @@ def getParameterXml(request):
else
:
else
:
return
jsonify
(
code
=
1
,
result
=
parameters
)
return
jsonify
(
code
=
1
,
result
=
parameters
)
#update user account data
@
app
.
route
(
"/updateAccount"
,
methods
=
[
'POST'
])
@
app
.
route
(
"/updateAccount"
,
methods
=
[
'POST'
])
def
updateAccount
():
def
updateAccount
():
account
=
[]
account
=
[]
...
...
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