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
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)
......@@ -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:125px;}
#tabContaier textarea.slap{color: #6F6F6F;width:430px; max-height:120px; height:18px;padding:3px;}
#tabContaier > ul{
overflow:hidden;
height:34px;
......
......@@ -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;
......
......@@ -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++){
......
......@@ -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>
......
# -*- 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'],
......
# -*- 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")
f = open(param_path, 'w')
f.write(content)
f.close()
result = readParameters(param_path)
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=0, result=parameters)
\ No newline at end of file
return jsonify(code=1, result=parameters)
\ 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