From 5ad93361294a3502a9c13b1384b371cd8eb3ae94 Mon Sep 17 00:00:00 2001 From: Alain Takoudjou <talino@tiolive.com> Date: Sun, 11 Mar 2012 19:23:38 +0100 Subject: [PATCH] Update md5sum of instance for slaprunner SR --- .../static/js/scripts/inspectInstance.js | 3 +++ slapos/runner/templates/instanceInspect.html | 4 ++-- slapos/runner/utils.py | 20 ++++++++++++++++ slapos/runner/views.py | 24 ++++++++++++++++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/slapos/runner/static/js/scripts/inspectInstance.js b/slapos/runner/static/js/scripts/inspectInstance.js index 1291d2c..8b24903 100644 --- a/slapos/runner/static/js/scripts/inspectInstance.js +++ b/slapos/runner/static/js/scripts/inspectInstance.js @@ -18,6 +18,9 @@ $(document).ready( function() { //User have double click on file in to the fileTree loadFileContent(file); } + $("#update").click(function(){ + alert($("#parameter").val()); + }); function loadFileContent(file){ $.ajax({ diff --git a/slapos/runner/templates/instanceInspect.html b/slapos/runner/templates/instanceInspect.html index 3f7d295..de76c1e 100644 --- a/slapos/runner/templates/instanceInspect.html +++ b/slapos/runner/templates/instanceInspect.html @@ -23,9 +23,9 @@ <li><a href="#tab4">Partitions Content</a></li> </ul><!-- //Tab buttons --> <div class="tabDetails"> - <div id="tab1" class="tabContents"> + <div id="tab1" class="tabContents"> <p>Add your instance parameters here and click on the update button</p> - <textarea class="parameter"><?xml version='1.0' encoding='utf-8'?></textarea> + <textarea class="parameter" id="parameter"><?xml version='1.0' encoding='utf-8'?></textarea> <input type="submit" name="update" id ="update" value="Update" class="button"/> </div><!-- end tab1 --> <div id="tab2" class="tabContents"> diff --git a/slapos/runner/utils.py b/slapos/runner/utils.py index 73a50b5..ac0430b 100755 --- a/slapos/runner/utils.py +++ b/slapos/runner/utils.py @@ -3,6 +3,7 @@ import time import subprocess import os from xml_marshaller import xml_marshaller +from xml.dom import minidom import re import urllib from flask import jsonify @@ -12,6 +13,7 @@ import hashlib import signal + class Popen(subprocess.Popen): def __init__(self, *args, **kwargs): kwargs['stdin'] = subprocess.PIPE @@ -549,3 +551,21 @@ def realpath(config, path, check_exist=True): else: return path return False + +def readParameters(path): + if os.path.exists(path): + try: + xmldoc = minidom.parse(path) + object = {} + for elt in xmldoc.childNodes: + sub_object = {} + for subnode in elt.childNodes: + if subnode.nodeType != subnode.TEXT_NODE: + sub_object[str(subnode.getAttribute('id'))] = str(subnode. + childNodes[0].data) + object[str(elt.tagName)] = sub_object + return object + except Exception, e: + return str(e) + else: + return "No such file or directory: " + path \ No newline at end of file diff --git a/slapos/runner/views.py b/slapos/runner/views.py index 46c24d3..285b1aa 100755 --- a/slapos/runner/views.py +++ b/slapos/runner/views.py @@ -357,4 +357,26 @@ def getPath(): if not realfile: return jsonify(code=0, result="Can not access to this file: Permission Denied!") else: - return jsonify(code=1, result=realfile) \ No newline at end of file + return jsonify(code=1, result=realfile) + +@app.route("/loadParameterXml", methods=['POST']) +def redParameterXml(): + 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) + if type(result) == type(''): + return jsonify(code=0, result="XML Error: " + result) + else: + return jsonify(code=1, result="") + +@app.route("/getParameterXml", methods=['GET']) +def getParameterXml(): + param_path = os.path.join(app.config['runner_workdir'], ".parameter.xml") + if os.path.exists(param_path): + content = open(param_path, 'w').read() + return jsonify(code=1, result=content) + else: + return jsonify(code=0, result="Error: Can not load default instance parameters") \ No newline at end of file -- 2.30.9