Commit fca1e652 authored by Nicolas Wavrant's avatar Nicolas Wavrant

runner: allow user to change the software release of the instance on "Inspect Instance" page

parent c36742f3
...@@ -81,6 +81,7 @@ $(document).ready(function () { ...@@ -81,6 +81,7 @@ $(document).ready(function () {
var xml = '<?xml version="1.0" encoding="utf-8"?>\n', var xml = '<?xml version="1.0" encoding="utf-8"?>\n',
software_type = '', software_type = '',
software_type_input_value = $('input#software_type').val(), software_type_input_value = $('input#software_type').val(),
software_release = $('#software_release').val(),
size = $('#partitionParameter > tbody > tr').length, size = $('#partitionParameter > tbody > tr').length,
i; i;
...@@ -102,7 +103,11 @@ $(document).ready(function () { ...@@ -102,7 +103,11 @@ $(document).ready(function () {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: $SCRIPT_ROOT + '/saveParameterXml', url: $SCRIPT_ROOT + '/saveParameterXml',
data: {software_type: software_type, parameter: xml}, data: {
software_type: software_type,
software_release: software_release,
parameter: xml
},
success: function (data) { success: function (data) {
if (data.code === 1) { if (data.code === 1) {
$('#error').Popup('Instance parameters has been updated, please run your instance now!', {type: 'confirm', duration: 5000}); $('#error').Popup('Instance parameters has been updated, please run your instance now!', {type: 'confirm', duration: 5000});
......
...@@ -94,6 +94,16 @@ ...@@ -94,6 +94,16 @@
{%endif%} {%endif%}
</div><!-- end tab2 --> </div><!-- end tab2 -->
<div id="tab3" class="tabContents"> <div id="tab3" class="tabContents">
<div id="softwareRelease">
<h2 class='title'>Software Release of main instance</h2>
<select style="margin-top:5px;" name="software_release", id="software_release">
<option value="{{ current_software_release_uri }}">{{ current_software_release_uri }}</option>
{% for sr_uri in software_release_uri_list %}
<option value="{{ sr_uri }}">{{ sr_uri }}</option>
{% endfor %}
</select>
</div>
<br/>
<div id="softwareType"> <div id="softwareType">
<h2 class='title'>Software Type of main instance</h2> <h2 class='title'>Software Type of main instance</h2>
<input style="margin-top:5px;" type="text" name="software_type" id="software_type" size="35" value="Software Type here..." /> <input style="margin-top:5px;" type="text" name="software_type" id="software_type" size="35" value="Software Type here..." />
......
...@@ -122,6 +122,16 @@ def createNewUser(config, name, passwd): ...@@ -122,6 +122,16 @@ def createNewUser(config, name, passwd):
return False return False
return True return True
def getAvailableSoftwareReleaseURIList(config):
slap = slapos.slap.slap()
slap.initializeConnection(config['master_url'])
return [
x.getURI() for x in \
slap.registerComputer(config['computer_id']).getSoftwareReleaseList()
]
def getCurrentSoftwareReleaseProfile(config): def getCurrentSoftwareReleaseProfile(config):
""" """
Returns used Software Release profile as a string. Returns used Software Release profile as a string.
...@@ -856,6 +866,21 @@ def realpath(config, path, check_exist=True): ...@@ -856,6 +866,21 @@ def realpath(config, path, check_exist=True):
return path return path
def relativepath(config, path):
# Sorted by less generic to more generic
path = os.path.realpath(path)
virtual_path_list = (
'software_root',
'instance_root',
'workspace',
'software_link',
'runner_workdir',
)
for virtual_path in virtual_path_list:
if path.startswith(config[virtual_path]):
return path.replace(os.path.realpath(config[virtual_path]), virtual_path)
return ''
def readParameters(path): def readParameters(path):
"""Read Instance parameters stored into a local file. """Read Instance parameters stored into a local file.
......
...@@ -184,6 +184,10 @@ def inspectInstance(): ...@@ -184,6 +184,10 @@ def inspectInstance():
else: else:
file_path = '' file_path = ''
supervisor = [] supervisor = []
current_sr = utils.relativepath(app.config, utils.getCurrentSoftwareReleaseProfile(app.config))
available_sr_list = [utils.relativepath(app.config, x) for x in utils.getAvailableSoftwareReleaseURIList(app.config)]
if current_sr in available_sr_list:
available_sr_list.remove(current_sr)
if "application/json" in request.accept_mimetypes.best: if "application/json" in request.accept_mimetypes.best:
result_list = [] result_list = []
for service in supervisor: for service in supervisor:
...@@ -192,11 +196,15 @@ def inspectInstance(): ...@@ -192,11 +196,15 @@ def inspectInstance():
'status': service[1], 'status': service[1],
}) })
return jsonify(result_list) return jsonify(result_list)
return render_template('instanceInspect.html', return render_template(
'instanceInspect.html',
file_path=file_path, file_path=file_path,
supervisor=supervisor, supervisor=supervisor,
slap_status=getSlapStatus(app.config), slap_status=getSlapStatus(app.config),
partition_amount=app.config['partition_amount']) partition_amount=app.config['partition_amount'],
current_software_release_uri=current_sr,
software_release_uri_list=available_sr_list
)
def getConnectionParameter(partition_reference): def getConnectionParameter(partition_reference):
""" """
...@@ -558,8 +566,13 @@ def saveParameterXml(): ...@@ -558,8 +566,13 @@ def saveParameterXml():
Update instance parameter into a local xml file. Update instance parameter into a local xml file.
""" """
project = os.path.join(app.config['etc_dir'], ".project") project = os.path.join(app.config['etc_dir'], ".project")
if not os.path.exists(project): current_software_release = utils.getCurrentSoftwareReleaseProfile(config)
if not current_software_release:
return jsonify(code=0, result="Please first open a Software Release") return jsonify(code=0, result="Please first open a Software Release")
software_release = request.form['software_release']
if current_software_release != software_release:
utils.setCurrentSoftwareRelease(app.config, software_release)
content = request.form['parameter'].encode("utf-8") content = request.form['parameter'].encode("utf-8")
param_path = os.path.join(app.config['etc_dir'], ".parameter.xml") param_path = os.path.join(app.config['etc_dir'], ".parameter.xml")
try: try:
......
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