1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 15:15:22 +00:00

Added XML edit

This commit is contained in:
Retspen 2015-03-13 14:06:51 +02:00
parent 64b43f1385
commit ee1983b656
3 changed files with 48 additions and 5 deletions

View file

@ -178,22 +178,28 @@ def instance(request, compute_id, vname):
try:
if request.method == 'POST':
if 'poweron' in request.POST:
conn.start()
return HttpResponseRedirect(request.get_full_path() + '#poweron')
if 'powercycle' in request.POST:
conn.force_shutdown()
conn.start()
return HttpResponseRedirect(request.get_full_path() + '#powercycle')
if 'poweroff' == request.POST.get('power', ''):
conn.shutdown()
return HttpResponseRedirect(request.get_full_path() + '#poweroff')
if 'suspend' in request.POST:
conn.suspend()
return HttpResponseRedirect(request.get_full_path() + '#resume')
if 'resume' in request.POST:
conn.resume()
return HttpResponseRedirect(request.get_full_path() + '#suspend')
if 'delete' in request.POST:
if conn.get_status() == 1:
conn.force_shutdown()
@ -205,26 +211,32 @@ def instance(request, compute_id, vname):
finally:
conn.delete()
return HttpResponseRedirect(reverse('instances', args=[compute_id]))
if 'snapshot' in request.POST:
name = request.POST.get('name', '')
conn.create_snapshot(name)
return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts')
if 'umount_iso' in request.POST:
image = request.POST.get('path', '')
dev = request.POST.get('umount_iso', '')
conn.umount_iso(dev, image)
return HttpResponseRedirect(request.get_full_path() + '#instancemedia')
if 'mount_iso' in request.POST:
image = request.POST.get('media', '')
dev = request.POST.get('mount_iso', '')
conn.mount_iso(dev, image)
return HttpResponseRedirect(request.get_full_path() + '#instancemedia')
if 'set_autostart' in request.POST:
conn.set_autostart(1)
return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
if 'unset_autostart' in request.POST:
conn.set_autostart(0)
return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
if 'resize' in request.POST:
description = request.POST.get('description', '')
vcpu = request.POST.get('vcpu', '')
@ -239,11 +251,13 @@ def instance(request, compute_id, vname):
cur_memory = cur_memory_custom
conn.resize(cur_memory, memory, cur_vcpu, vcpu)
return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
if 'change_xml' in request.POST:
xml = request.POST.get('inst_xml', '')
if xml:
conn._defineXML(xml)
exit_xml = request.POST.get('inst_xml', '')
if exit_xml:
conn._defineXML(exit_xml)
return HttpResponseRedirect(request.get_full_path() + '#instancexml')
if 'set_console_passwd' in request.POST:
if request.POST.get('auto_pass', ''):
passwd = ''.join([choice(letters + digits) for i in xrange(12)])
@ -290,16 +304,19 @@ def instance(request, compute_id, vname):
conn_migrate.define_move(vname)
conn_migrate.close()
return HttpResponseRedirect(reverse('instance', args=[compute_id, vname]))
if 'delete_snapshot' in request.POST:
snap_name = request.POST.get('name', '')
conn.snapshot_delete(snap_name)
return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts')
if 'revert_snapshot' in request.POST:
snap_name = request.POST.get('name', '')
conn.snapshot_revert(snap_name)
msg = _("Successful revert snapshot: ")
msg += snap_name
messages.append(msg)
if 'clone' in request.POST:
clone_data = {}
clone_data['name'] = request.POST.get('name', '')

View file

@ -191,7 +191,7 @@
<div class="well">
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="col-sm-12" id="xmlheight">
<textarea id="editor" name="from_xml""></textarea>
<textarea id="editor" name="from_xml"></textarea>
</div>
<button type="submit" class="btn btn-primary" name="create_xml">
{% trans "Create" %}

View file

@ -635,7 +635,23 @@
<div class="clearfix"></div></p>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="xmledit">
<p>XML</p>
<p>{% trans "If you need to edit xml please Power Off the instance" %}</p>
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="col-sm-12" id="xmlheight">
<textarea id="editor">{{ inst_xml }}</textarea>
</div>
{% ifequal status 5 %}
<input type="hidden" name="inst_xml">
<button type="submit" class="btn btn-lg btn-success pull-right" name="change_xml">
{% trans "Change" %}
</button>
{% else %}
<button class="btn btn-lg btn-success pull-right disabled">
{% trans "Change" %}
</button>
{% endifequal %}
</form>
<div class="clearfix"></div>
</div>
</div>
</div>
@ -692,6 +708,16 @@
</div>
{% endblock %}
{% block script %}
<script src="{{ STATIC_URL }}/js/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.getSession().setMode("ace/mode/xml");
var input = $('input[name="inst_xml"]');
editor.getSession().on("change", function () {
input.val(editor.getSession().getValue());
});
</script>
<script>
function open_console() {
window.open('{% url 'console' %}?token={{ compute_id }}-{{ uuid }}', '', 'width=850,height=485')