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
Łukasz Nowak
slapos.toolbox
Commits
28be25ee
Commit
28be25ee
authored
Jun 18, 2012
by
Alain Takoudjou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to load Instance parameters as XML data
parent
3ce5dac2
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
29 deletions
+93
-29
slapos/runner/__init__.py
slapos/runner/__init__.py
+7
-5
slapos/runner/static/css/jqueryTabs.css
slapos/runner/static/css/jqueryTabs.css
+4
-4
slapos/runner/static/css/styles.css
slapos/runner/static/css/styles.css
+2
-3
slapos/runner/static/js/scripts/inspectInstance.js
slapos/runner/static/js/scripts/inspectInstance.js
+49
-4
slapos/runner/templates/instanceInspect.html
slapos/runner/templates/instanceInspect.html
+5
-1
slapos/runner/utils.py
slapos/runner/utils.py
+2
-1
slapos/runner/views.py
slapos/runner/views.py
+24
-11
No files found.
slapos/runner/__init__.py
View file @
28be25ee
...
...
@@ -5,6 +5,7 @@ import logging.handlers
import
os
import
sys
import
subprocess
import
hashlib
class
Parser
(
OptionParser
):
"""
...
...
@@ -109,7 +110,6 @@ def run():
def
serve
(
config
):
from
views
import
app
#import FlaskRealmDigestDB
workdir
=
os
.
path
.
join
(
config
.
runner_workdir
,
'project'
)
app
.
config
.
update
(
**
config
.
__dict__
)
app
.
config
.
update
(
...
...
@@ -122,9 +122,11 @@ def serve(config):
)
if
not
os
.
path
.
exists
(
workdir
):
os
.
mkdir
(
workdir
)
#authDB = FlaskRealmDigestDB('SlaposWebRunner')
#user_dict = authDB.toDict()
#if not user_dict['db']:
# authDB.add_user('admin', 'root')
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
config
.
runner_workdir
,
'.users'
)):
#set default user and password
salt
=
"runner81"
#to be changed
pwd
=
hashlib
.
md5
(
salt
+
"insecure"
).
hexdigest
()
user
=
"root;"
+
pwd
+
";Slaprunner Administrator;1"
open
(
os
.
path
.
join
(
config
.
runner_workdir
,
'.users'
),
'w'
).
write
(
user
)
app
.
run
(
host
=
config
.
runner_host
,
port
=
int
(
config
.
runner_port
),
debug
=
config
.
debug
,
threaded
=
True
)
slapos/runner/static/css/jqueryTabs.css
View file @
28be25ee
...
...
@@ -9,12 +9,12 @@
#tabContaier
textarea
{
width
:
702px
;
margin-top
:
4px
;
margin-left
:
4px
;
resize
:
none
;
white-space
:
pre-wrap
;
word-wrap
:
break-word
;
}
#tabContaier
textarea
.slap
{
width
:
455px
;
max-height
:
120px
;
height
:
20px
;
padding
:
3px
;
color
:
#6F6F6F
}
#tabContaier
input
[
type
=
'text'
]
{
width
:
125
px
;}
#tabContaier
textarea
.slap
{
color
:
#6F6F6F
;
width
:
430px
;
max-height
:
120px
;
height
:
18px
;
padding
:
3
px
;}
#tabContaier
>
ul
{
overflow
:
hidden
;
height
:
34px
;
...
...
slapos/runner/static/css/styles.css
View file @
28be25ee
...
...
@@ -4,7 +4,6 @@ blockquote, q {quotes: none;}
blockquote
:before
,
blockquote
:after
,
q
:before
,
q
:after
{
content
:
none
;}
:focus
{
outline
:
0
none
;}
img
{
border
:
0
}
a
{
text-decoration
:
none
;
color
:
#19485C
;
...
...
@@ -15,12 +14,12 @@ a:hover {
}
table
{
margin
:
0
;
padding
:
0
;
margin
:
0
;
padding
:
0
;
border-right
:
none
;
border-bottom
:
none
;
font-size
:
14px
;
background
:
#fff
;
border-spacing
:
0
;
}
td
{
padding
:
4px
;
...
...
slapos/runner/static/js/scripts/inspectInstance.js
View file @
28be25ee
...
...
@@ -39,7 +39,7 @@ $(document).ready( function() {
});
$
(
"
#add_attribute
"
).
click
(
function
(){
var
size
=
Number
(
$
(
"
#partitionParameter > tbody > tr
"
).
last
().
attr
(
'
id
'
).
split
(
'
_
'
)[
1
])
+
1
;
var
row
=
"
<tr id='row_
"
+
size
+
"
'><td class='
propertie
first'><input type='text' name='txt_
"
+
size
+
"
' id='txt_
"
+
size
+
"
'></td>
"
+
var
row
=
"
<tr id='row_
"
+
size
+
"
'><td class='first'><input type='text' name='txt_
"
+
size
+
"
' id='txt_
"
+
size
+
"
'></td>
"
+
"
<td style='padding:6px'><textarea class='slap' id='value_
"
+
size
+
"
'></textarea>
"
+
"
</td><td valign='middle'><span style='margin-left: 10px;' id='btn_
"
+
size
+
"
' class='close'></span></td></tr>
"
;
$
(
"
#partitionParameter
"
).
append
(
row
);
...
...
@@ -54,6 +54,51 @@ $(document).ready( function() {
updateParameter
();
return
false
;
});
$
(
"
#xmlview
"
).
click
(
function
(){
var
content
=
'
<h2 style="color: #4c6172; font: 18px
\'
Helvetica Neue
\'
, Helvetica, Arial, sans-serif;">
'
+
'
INSTANCE PARAMETERS: Load XML file</h2><p id="xmllog" class="message"><br/></p>
'
;
content
+=
'
<div class="main_content" style="height:230px"><pre id="editor"></pre></div>
'
+
'
<input type=submit value="Load" id="loadxml" class="button">
'
;
$
.
ajax
({
type
:
"
GET
"
,
url
:
$SCRIPT_ROOT
+
'
/getParameterXml/xml
'
,
success
:
function
(
data
){
if
(
data
.
code
==
1
){
$
(
"
#inline_content
"
).
html
(
content
);
setupEditor
(
true
);
$
(
"
.inline
"
).
colorbox
({
inline
:
true
,
width
:
"
600px
"
,
height
:
"
410px
"
,
onComplete
:
function
(){
editor
.
getSession
().
setValue
(
data
.
result
);
}});
$
(
"
.inline
"
).
click
();
$
(
"
#loadxml
"
).
click
(
function
(){
//Parse XML file
try
{
var
xmlDoc
=
$
.
parseXML
(
editor
.
getSession
().
getValue
()),
$xml
=
$
(
xmlDoc
);
if
(
$xml
.
find
(
"
parsererror
"
).
length
!==
0
){
$
(
"
p#xmllog
"
).
html
(
"
Error: Invalid XML document!<br/>
"
);
return
false
;}
}
catch
(
err
)
{
$
(
"
p#xmllog
"
).
html
(
"
Error: Invalid XML document!<br/>
"
);
return
false
;
}
$
.
ajax
({
type
:
"
POST
"
,
url
:
$SCRIPT_ROOT
+
'
/saveParameterXml
'
,
data
:
{
software_type
:
""
,
parameter
:
editor
.
getSession
().
getValue
()},
success
:
function
(
data
){
if
(
data
.
code
==
1
){
location
.
href
=
$SCRIPT_ROOT
+
'
/inspectInstance#tab3
'
;
location
.
reload
();
}
else
{
$
(
"
p#xmllog
"
).
html
(
data
.
result
);}
}
});
return
false
;
});
}
else
{
$
(
"
#error
"
).
Popup
(
data
.
result
,
{
type
:
'
error
'
,
duration
:
5000
});
}
}
});
});
//Load previous instance parameters
loadParameter
();
...
...
@@ -172,7 +217,7 @@ $(document).ready( function() {
function
loadParameter
(){
$
.
ajax
({
type
:
"
GET
"
,
url
:
$SCRIPT_ROOT
+
'
/getParameterXml
'
,
url
:
$SCRIPT_ROOT
+
'
/getParameterXml
/dict
'
,
success
:
function
(
data
){
if
(
data
.
code
==
1
){
var
dict
=
data
.
result
[
'
instance
'
];
...
...
@@ -218,7 +263,7 @@ $(document).ready( function() {
$
(
"
#softwareTypeHead
"
).
addClass
(
"
hide
"
);
}
}
function
setupEditor
(){
function
setupEditor
(
editable
){
editor
=
ace
.
edit
(
"
editor
"
);
editor
.
setTheme
(
"
ace/theme/crimson_editor
"
);
...
...
@@ -227,7 +272,7 @@ $(document).ready( function() {
editor
.
getSession
().
setTabSize
(
2
);
editor
.
getSession
().
setUseSoftTabs
(
true
);
editor
.
renderer
.
setHScrollBarAlwaysVisible
(
false
);
editor
.
setReadOnly
(
true
);
if
(
!
editable
){
editor
.
setReadOnly
(
true
);}
}
function
setupSlappart
(){
for
(
var
i
=
0
;
i
<
partitionAmount
;
i
++
){
...
...
slapos/runner/templates/instanceInspect.html
View file @
28be25ee
...
...
@@ -116,7 +116,11 @@
</table>
</div>
</div>
<div
style=
"margin-left:10px;"
><a
id=
"updateParameters"
class=
"lshare simple"
>
Update Values
</a></div>
<div
style=
"margin-left:10px;"
>
<a
id=
"updateParameters"
class=
"lshare simple no-right-border"
style=
"float:left"
>
Update Values
</a>
<a
href=
"#"
id=
"xmlview"
class=
"lshare simple"
style=
"float:left"
>
Load XML
</a>
</div>
<div
class=
"clear"
></div>
</div>
<!-- end tab3 -->
<div
id=
"tab4"
class=
"tabContents"
>
<h2>
File content for all your partitions
</h2>
...
...
slapos/runner/utils.py
View file @
28be25ee
# -*- coding: iso-8859-1 -*-
import
slapos.slap
import
time
import
subprocess
...
...
@@ -118,7 +120,6 @@ def writePid(file, pid):
def
updateInstanceParameter
(
config
,
software_type
=
None
):
slap
=
slapos
.
slap
.
slap
()
slap
.
initializeConnection
(
config
[
'master_url'
])
partition_list
=
[]
#Get current software release profile
try
:
software_folder
=
open
(
os
.
path
.
join
(
config
[
'runner_workdir'
],
...
...
slapos/runner/views.py
View file @
28be25ee
# -*- coding: utf-8 -*-
from
flask
import
Flask
,
request
,
redirect
,
url_for
,
\
render_template
,
flash
,
jsonify
,
session
from
utils
import
*
import
os
import
shutil
import
md5
import
codecs
from
gittools
import
cloneRepo
,
gitStatus
,
switchBranch
,
addBranch
,
getDiff
,
\
gitPush
,
gitPull
...
...
@@ -397,15 +400,18 @@ def saveParameterXml():
return
jsonify
(
code
=
0
,
result
=
"Please first open a Software Release"
)
content
=
request
.
form
[
'parameter'
]
param_path
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".parameter.xml"
)
try
:
f
=
open
(
param_path
,
'w'
)
f
.
write
(
content
)
f
.
close
()
result
=
readParameters
(
param_path
)
except
Exception
,
e
:
result
=
str
(
e
)
software_type
=
None
if
(
request
.
form
[
'software_type'
]):
software_type
=
request
.
form
[
'software_type'
]
if
type
(
result
)
==
type
(
''
):
return
jsonify
(
code
=
0
,
result
=
"XML Error: "
+
result
)
return
jsonify
(
code
=
0
,
result
=
result
)
else
:
try
:
updateInstanceParameter
(
app
.
config
,
software_type
)
...
...
@@ -413,11 +419,18 @@ def saveParameterXml():
return
jsonify
(
code
=
0
,
result
=
"An error occurred while applying your settings!<br/>"
+
str
(
e
))
return
jsonify
(
code
=
1
,
result
=
""
)
@
app
.
route
(
"/getParameterXml"
,
methods
=
[
'GET'
])
def
getParameterXml
():
@
app
.
route
(
"/getParameterXml
/<request>
"
,
methods
=
[
'GET'
])
def
getParameterXml
(
request
):
param_path
=
os
.
path
.
join
(
app
.
config
[
'runner_workdir'
],
".parameter.xml"
)
parameters
=
readParameters
(
param_path
)
if
type
(
parameters
)
!=
type
(
''
):
return
jsonify
(
code
=
1
,
result
=
parameters
)
if
not
os
.
path
.
exists
(
param_path
):
default
=
'<?xml version="1.0" encoding="utf-8"?>
\
n
'
default
+=
'<instance>
\
n
</instance>'
return
jsonify
(
code
=
1
,
result
=
default
)
if
request
==
"xml"
:
parameters
=
open
(
param_path
,
'r'
).
read
()
else
:
parameters
=
readParameters
(
param_path
)
if
type
(
parameters
)
==
type
(
''
)
and
request
!=
"xml"
:
return
jsonify
(
code
=
0
,
result
=
parameters
)
else
:
return
jsonify
(
code
=
1
,
result
=
parameters
)
\ No newline at end of file
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