1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-24 23:25:24 +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: try:
if request.method == 'POST': if request.method == 'POST':
if 'poweron' in request.POST: if 'poweron' in request.POST:
conn.start() conn.start()
return HttpResponseRedirect(request.get_full_path() + '#poweron') return HttpResponseRedirect(request.get_full_path() + '#poweron')
if 'powercycle' in request.POST: if 'powercycle' in request.POST:
conn.force_shutdown() conn.force_shutdown()
conn.start() conn.start()
return HttpResponseRedirect(request.get_full_path() + '#powercycle') return HttpResponseRedirect(request.get_full_path() + '#powercycle')
if 'poweroff' == request.POST.get('power', ''): if 'poweroff' == request.POST.get('power', ''):
conn.shutdown() conn.shutdown()
return HttpResponseRedirect(request.get_full_path() + '#poweroff') return HttpResponseRedirect(request.get_full_path() + '#poweroff')
if 'suspend' in request.POST: if 'suspend' in request.POST:
conn.suspend() conn.suspend()
return HttpResponseRedirect(request.get_full_path() + '#resume') return HttpResponseRedirect(request.get_full_path() + '#resume')
if 'resume' in request.POST: if 'resume' in request.POST:
conn.resume() conn.resume()
return HttpResponseRedirect(request.get_full_path() + '#suspend') return HttpResponseRedirect(request.get_full_path() + '#suspend')
if 'delete' in request.POST: if 'delete' in request.POST:
if conn.get_status() == 1: if conn.get_status() == 1:
conn.force_shutdown() conn.force_shutdown()
@ -205,26 +211,32 @@ def instance(request, compute_id, vname):
finally: finally:
conn.delete() conn.delete()
return HttpResponseRedirect(reverse('instances', args=[compute_id])) return HttpResponseRedirect(reverse('instances', args=[compute_id]))
if 'snapshot' in request.POST: if 'snapshot' in request.POST:
name = request.POST.get('name', '') name = request.POST.get('name', '')
conn.create_snapshot(name) conn.create_snapshot(name)
return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts') return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts')
if 'umount_iso' in request.POST: if 'umount_iso' in request.POST:
image = request.POST.get('path', '') image = request.POST.get('path', '')
dev = request.POST.get('umount_iso', '') dev = request.POST.get('umount_iso', '')
conn.umount_iso(dev, image) conn.umount_iso(dev, image)
return HttpResponseRedirect(request.get_full_path() + '#instancemedia') return HttpResponseRedirect(request.get_full_path() + '#instancemedia')
if 'mount_iso' in request.POST: if 'mount_iso' in request.POST:
image = request.POST.get('media', '') image = request.POST.get('media', '')
dev = request.POST.get('mount_iso', '') dev = request.POST.get('mount_iso', '')
conn.mount_iso(dev, image) conn.mount_iso(dev, image)
return HttpResponseRedirect(request.get_full_path() + '#instancemedia') return HttpResponseRedirect(request.get_full_path() + '#instancemedia')
if 'set_autostart' in request.POST: if 'set_autostart' in request.POST:
conn.set_autostart(1) conn.set_autostart(1)
return HttpResponseRedirect(request.get_full_path() + '#instancesettings') return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
if 'unset_autostart' in request.POST: if 'unset_autostart' in request.POST:
conn.set_autostart(0) conn.set_autostart(0)
return HttpResponseRedirect(request.get_full_path() + '#instancesettings') return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
if 'resize' in request.POST: if 'resize' in request.POST:
description = request.POST.get('description', '') description = request.POST.get('description', '')
vcpu = request.POST.get('vcpu', '') vcpu = request.POST.get('vcpu', '')
@ -239,11 +251,13 @@ def instance(request, compute_id, vname):
cur_memory = cur_memory_custom cur_memory = cur_memory_custom
conn.resize(cur_memory, memory, cur_vcpu, vcpu) conn.resize(cur_memory, memory, cur_vcpu, vcpu)
return HttpResponseRedirect(request.get_full_path() + '#instancesettings') return HttpResponseRedirect(request.get_full_path() + '#instancesettings')
if 'change_xml' in request.POST: if 'change_xml' in request.POST:
xml = request.POST.get('inst_xml', '') exit_xml = request.POST.get('inst_xml', '')
if xml: if exit_xml:
conn._defineXML(xml) conn._defineXML(exit_xml)
return HttpResponseRedirect(request.get_full_path() + '#instancexml') return HttpResponseRedirect(request.get_full_path() + '#instancexml')
if 'set_console_passwd' in request.POST: if 'set_console_passwd' in request.POST:
if request.POST.get('auto_pass', ''): if request.POST.get('auto_pass', ''):
passwd = ''.join([choice(letters + digits) for i in xrange(12)]) 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.define_move(vname)
conn_migrate.close() conn_migrate.close()
return HttpResponseRedirect(reverse('instance', args=[compute_id, vname])) return HttpResponseRedirect(reverse('instance', args=[compute_id, vname]))
if 'delete_snapshot' in request.POST: if 'delete_snapshot' in request.POST:
snap_name = request.POST.get('name', '') snap_name = request.POST.get('name', '')
conn.snapshot_delete(snap_name) conn.snapshot_delete(snap_name)
return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts') return HttpResponseRedirect(request.get_full_path() + '#istaceshapshosts')
if 'revert_snapshot' in request.POST: if 'revert_snapshot' in request.POST:
snap_name = request.POST.get('name', '') snap_name = request.POST.get('name', '')
conn.snapshot_revert(snap_name) conn.snapshot_revert(snap_name)
msg = _("Successful revert snapshot: ") msg = _("Successful revert snapshot: ")
msg += snap_name msg += snap_name
messages.append(msg) messages.append(msg)
if 'clone' in request.POST: if 'clone' in request.POST:
clone_data = {} clone_data = {}
clone_data['name'] = request.POST.get('name', '') clone_data['name'] = request.POST.get('name', '')

View file

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

View file

@ -635,7 +635,23 @@
<div class="clearfix"></div></p> <div class="clearfix"></div></p>
</div> </div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="xmledit"> <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> </div>
</div> </div>
@ -692,6 +708,16 @@
</div> </div>
{% endblock %} {% endblock %}
{% block script %} {% 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> <script>
function open_console() { function open_console() {
window.open('{% url 'console' %}?token={{ compute_id }}-{{ uuid }}', '', 'width=850,height=485') window.open('{% url 'console' %}?token={{ compute_id }}-{{ uuid }}', '', 'width=850,height=485')