Commit 28be25ee authored by Alain Takoudjou's avatar Alain Takoudjou

Allow to load Instance parameters as XML data

parent 3ce5dac2
...@@ -5,6 +5,7 @@ import logging.handlers ...@@ -5,6 +5,7 @@ import logging.handlers
import os import os
import sys import sys
import subprocess import subprocess
import hashlib
class Parser(OptionParser): class Parser(OptionParser):
""" """
...@@ -109,7 +110,6 @@ def run(): ...@@ -109,7 +110,6 @@ def run():
def serve(config): def serve(config):
from views import app from views import app
#import FlaskRealmDigestDB
workdir = os.path.join(config.runner_workdir, 'project') workdir = os.path.join(config.runner_workdir, 'project')
app.config.update(**config.__dict__) app.config.update(**config.__dict__)
app.config.update( app.config.update(
...@@ -122,9 +122,11 @@ def serve(config): ...@@ -122,9 +122,11 @@ def serve(config):
) )
if not os.path.exists(workdir): if not os.path.exists(workdir):
os.mkdir(workdir) os.mkdir(workdir)
#authDB = FlaskRealmDigestDB('SlaposWebRunner') if not os.path.exists(os.path.join(config.runner_workdir, '.users')):
#user_dict = authDB.toDict() #set default user and password
#if not user_dict['db']: salt = "runner81" #to be changed
# authDB.add_user('admin', 'root') 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), app.run(host=config.runner_host, port=int(config.runner_port),
debug=config.debug, threaded=True) debug=config.debug, threaded=True)
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
#tabContaier textarea { #tabContaier textarea {
width:702px; width:702px;
margin-top:4px;
margin-left:4px;
resize: none; 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:125px;} #tabContaier textarea.slap{color: #6F6F6F;width:430px; max-height:120px; height:18px;padding:3px;}
#tabContaier > ul{ #tabContaier > ul{
overflow:hidden; overflow:hidden;
height:34px; height:34px;
......
...@@ -4,7 +4,6 @@ blockquote, q {quotes: none;} ...@@ -4,7 +4,6 @@ blockquote, q {quotes: none;}
blockquote:before, blockquote:after, q:before, q:after {content: none;} blockquote:before, blockquote:after, q:before, q:after {content: none;}
:focus {outline: 0 none;} :focus {outline: 0 none;}
img{border:0} img{border:0}
a{ a{
text-decoration: none; text-decoration: none;
color: #19485C; color: #19485C;
...@@ -15,12 +14,12 @@ a:hover { ...@@ -15,12 +14,12 @@ a:hover {
} }
table { table {
margin: 0; margin: 0;padding:0;
padding:0;
border-right: none; border-right: none;
border-bottom: none; border-bottom: none;
font-size: 14px; font-size: 14px;
background: #fff; background: #fff;
border-spacing:0;
} }
td{ td{
padding: 4px; padding: 4px;
......
...@@ -39,7 +39,7 @@ $(document).ready( function() { ...@@ -39,7 +39,7 @@ $(document).ready( function() {
}); });
$("#add_attribute").click(function(){ $("#add_attribute").click(function(){
var size = Number($("#partitionParameter > tbody > tr").last().attr('id').split('_')[1]) + 1; 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 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>"; "</td><td valign='middle'><span style='margin-left: 10px;' id='btn_"+size+"' class='close'></span></td></tr>";
$("#partitionParameter").append(row); $("#partitionParameter").append(row);
...@@ -54,6 +54,51 @@ $(document).ready( function() { ...@@ -54,6 +54,51 @@ $(document).ready( function() {
updateParameter(); updateParameter();
return false; 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 //Load previous instance parameters
loadParameter(); loadParameter();
...@@ -172,7 +217,7 @@ $(document).ready( function() { ...@@ -172,7 +217,7 @@ $(document).ready( function() {
function loadParameter(){ function loadParameter(){
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: $SCRIPT_ROOT + '/getParameterXml', url: $SCRIPT_ROOT + '/getParameterXml/dict',
success: function(data){ success: function(data){
if(data.code == 1){ if(data.code == 1){
var dict=data.result['instance']; var dict=data.result['instance'];
...@@ -218,7 +263,7 @@ $(document).ready( function() { ...@@ -218,7 +263,7 @@ $(document).ready( function() {
$("#softwareTypeHead").addClass("hide"); $("#softwareTypeHead").addClass("hide");
} }
} }
function setupEditor(){ function setupEditor(editable){
editor = ace.edit("editor"); editor = ace.edit("editor");
editor.setTheme("ace/theme/crimson_editor"); editor.setTheme("ace/theme/crimson_editor");
...@@ -227,7 +272,7 @@ $(document).ready( function() { ...@@ -227,7 +272,7 @@ $(document).ready( function() {
editor.getSession().setTabSize(2); editor.getSession().setTabSize(2);
editor.getSession().setUseSoftTabs(true); editor.getSession().setUseSoftTabs(true);
editor.renderer.setHScrollBarAlwaysVisible(false); editor.renderer.setHScrollBarAlwaysVisible(false);
editor.setReadOnly(true); if(!editable){editor.setReadOnly(true);}
} }
function setupSlappart(){ function setupSlappart(){
for(var i=0; i<partitionAmount; i++){ for(var i=0; i<partitionAmount; i++){
......
...@@ -116,7 +116,11 @@ ...@@ -116,7 +116,11 @@
</table> </table>
</div> </div>
</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><!-- end tab3 -->
<div id="tab4" class="tabContents"> <div id="tab4" class="tabContents">
<h2>File content for all your partitions</h2> <h2>File content for all your partitions</h2>
......
# -*- coding: iso-8859-1 -*-
import slapos.slap import slapos.slap
import time import time
import subprocess import subprocess
...@@ -118,7 +120,6 @@ def writePid(file, pid): ...@@ -118,7 +120,6 @@ def writePid(file, pid):
def updateInstanceParameter(config, software_type=None): def updateInstanceParameter(config, software_type=None):
slap = slapos.slap.slap() slap = slapos.slap.slap()
slap.initializeConnection(config['master_url']) slap.initializeConnection(config['master_url'])
partition_list = []
#Get current software release profile #Get current software release profile
try: try:
software_folder = open(os.path.join(config['runner_workdir'], software_folder = open(os.path.join(config['runner_workdir'],
......
# -*- coding: utf-8 -*-
from flask import Flask, request, redirect, url_for, \ from flask import Flask, request, redirect, url_for, \
render_template, flash, jsonify, session render_template, flash, jsonify, session
from utils import * from utils import *
import os import os
import shutil import shutil
import md5 import md5
import codecs
from gittools import cloneRepo, gitStatus, switchBranch, addBranch, getDiff, \ from gittools import cloneRepo, gitStatus, switchBranch, addBranch, getDiff, \
gitPush, gitPull gitPush, gitPull
...@@ -397,15 +400,18 @@ def saveParameterXml(): ...@@ -397,15 +400,18 @@ def saveParameterXml():
return jsonify(code=0, result="Please first open a Software Release") return jsonify(code=0, result="Please first open a Software Release")
content = request.form['parameter'] content = request.form['parameter']
param_path = os.path.join(app.config['runner_workdir'], ".parameter.xml") param_path = os.path.join(app.config['runner_workdir'], ".parameter.xml")
f = open(param_path, 'w') try:
f.write(content) f = open(param_path, 'w')
f.close() f.write(content)
result = readParameters(param_path) f.close()
result = readParameters(param_path)
except Exception, e:
result = str(e)
software_type = None software_type = None
if(request.form['software_type']): if(request.form['software_type']):
software_type = request.form['software_type'] software_type = request.form['software_type']
if type(result) == type(''): if type(result) == type(''):
return jsonify(code=0, result="XML Error: " + result) return jsonify(code=0, result=result)
else: else:
try: try:
updateInstanceParameter(app.config, software_type) updateInstanceParameter(app.config, software_type)
...@@ -413,11 +419,18 @@ def saveParameterXml(): ...@@ -413,11 +419,18 @@ 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="")
@app.route("/getParameterXml", methods=['GET']) @app.route("/getParameterXml/<request>", methods=['GET'])
def getParameterXml(): 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")
parameters = readParameters(param_path) if not os.path.exists(param_path):
if type(parameters) != type(''): default = '<?xml version="1.0" encoding="utf-8"?>\n'
return jsonify(code=1, result=parameters) 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: else:
return jsonify(code=0, result=parameters) return jsonify(code=1, result=parameters)
\ No newline at end of file \ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment