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

Fixed buttons on inst pages

This commit is contained in:
Retspen 2015-03-27 11:53:13 +02:00
parent 7bb6782037
commit be97a09dde
3 changed files with 77 additions and 53 deletions

View file

@ -88,28 +88,34 @@ def instances(request):
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
conn.start(name) conn.start(name)
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'poweroff' in request.POST:
msg = _("Power Off")
addlogmsg(request.user.id, instance.id, msg)
conn.shutdown(name)
return HttpResponseRedirect(request.get_full_path())
if 'powercycle' in request.POST: if 'powercycle' in request.POST:
msg = _("Power Cycle") msg = _("Power Cycle")
conn.force_shutdown(name) conn.force_shutdown(name)
conn.start(name) conn.start(name)
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'poweroff' in request.POST:
msg = _("Power Off")
addlogmsg(request.user.id, instance.id, msg)
conn.shutdown(name)
return HttpResponseRedirect(request.get_full_path())
if request.user.is_superuser: if request.user.is_superuser:
if 'suspend' in request.POST: if 'suspend' in request.POST:
msg = _("Suspend") msg = _("Suspend")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
conn.suspend(name) conn.suspend(name)
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
if 'resume' in request.POST: if 'resume' in request.POST:
msg = _("Resume") msg = _("Resume")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
conn.resume(name) conn.resume(name)
return HttpResponseRedirect(request.get_full_path()) return HttpResponseRedirect(request.get_full_path())
except libvirtError as lib_err: except libvirtError as lib_err:
error_messages.append(lib_err) error_messages.append(lib_err)
addlogmsg(request.user.id, instance.id, lib_err.message) addlogmsg(request.user.id, instance.id, lib_err.message)
@ -206,27 +212,31 @@ def instance(request, compute_id, vname):
if request.method == 'POST': if request.method == 'POST':
if 'poweron' in request.POST: if 'poweron' in request.POST:
conn.start()
msg = _("Power On") msg = _("Power On")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
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:
msg = _("Power Cycle")
addlogmsg(request.user.id, instance.id, msg)
conn.force_shutdown() conn.force_shutdown()
conn.start() conn.start()
msg = _("Power Cycle")
addlogmsg(request.user.id, instance.id, msg)
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()
msg = _("Power Off") msg = _("Power Off")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
conn.shutdown()
return HttpResponseRedirect(request.get_full_path() + '#poweroff') return HttpResponseRedirect(request.get_full_path() + '#poweroff')
if 'delete' in request.POST: if 'powerforce' in request.POST:
msg = _("Destroy") conn.force_shutdown()
msg = _("Force Off")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#powerforce')
if 'delete' in request.POST:
if conn.get_status() == 1: if conn.get_status() == 1:
conn.force_shutdown() conn.force_shutdown()
try: try:
@ -235,6 +245,8 @@ def instance(request, compute_id, vname):
if request.POST.get('delete_disk', ''): if request.POST.get('delete_disk', ''):
conn.delete_disk() conn.delete_disk()
finally: finally:
msg = _("Destroy")
addlogmsg(request.user.id, instance.id, msg)
if not request.user.is_superuser: if not request.user.is_superuser:
del_userinstance = UserInstance.objects.get(id=userinstace.id) del_userinstance = UserInstance.objects.get(id=userinstace.id)
del_userinstance.delete() del_userinstance.delete()
@ -248,8 +260,6 @@ def instance(request, compute_id, vname):
return HttpResponseRedirect(reverse('instances')) return HttpResponseRedirect(reverse('instances'))
if 'resize' in request.POST: if 'resize' in request.POST:
msg = _("Resize")
addlogmsg(request.user.id, instance.id, msg)
vcpu = request.POST.get('vcpu', '') vcpu = request.POST.get('vcpu', '')
cur_vcpu = request.POST.get('cur_vcpu', '') cur_vcpu = request.POST.get('cur_vcpu', '')
memory = request.POST.get('memory', '') memory = request.POST.get('memory', '')
@ -261,83 +271,83 @@ def instance(request, compute_id, vname):
if cur_memory_custom: if cur_memory_custom:
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)
msg = _("Resize")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#resize') return HttpResponseRedirect(request.get_full_path() + '#resize')
if 'umount_iso' in request.POST: if 'umount_iso' in request.POST:
msg = _("Mount media")
addlogmsg(request.user.id, instance.id, msg)
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)
msg = _("Mount media")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#media') return HttpResponseRedirect(request.get_full_path() + '#media')
if 'mount_iso' in request.POST: if 'mount_iso' in request.POST:
msg = _("Umount media")
addlogmsg(request.user.id, instance.id, msg)
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)
msg = _("Umount media")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#media') return HttpResponseRedirect(request.get_full_path() + '#media')
if 'snapshot' in request.POST: if 'snapshot' in request.POST:
msg = _("New snapshot")
addlogmsg(request.user.id, instance.id, msg)
name = request.POST.get('name', '') name = request.POST.get('name', '')
conn.create_snapshot(name) conn.create_snapshot(name)
msg = _("New snapshot")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#snapshot') return HttpResponseRedirect(request.get_full_path() + '#snapshot')
if 'delete_snapshot' in request.POST: if 'delete_snapshot' in request.POST:
msg = _("Delete snapshot")
addlogmsg(request.user.id, instance.id, msg)
snap_name = request.POST.get('name', '') snap_name = request.POST.get('name', '')
conn.snapshot_delete(snap_name) conn.snapshot_delete(snap_name)
msg = _("Delete snapshot")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#snapshot') return HttpResponseRedirect(request.get_full_path() + '#snapshot')
if 'revert_snapshot' in request.POST: if 'revert_snapshot' in request.POST:
msg = _("Revert snapshot")
addlogmsg(request.user.id, instance.id, msg)
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)
msg = _("Revert snapshot")
addlogmsg(request.user.id, instance.id, msg)
if request.user.is_superuser: if request.user.is_superuser:
if 'suspend' in request.POST: if 'suspend' in request.POST:
conn.suspend()
msg = _("Suspend") msg = _("Suspend")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
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()
msg = _("Resume") msg = _("Resume")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
conn.resume()
return HttpResponseRedirect(request.get_full_path() + '#suspend') return HttpResponseRedirect(request.get_full_path() + '#suspend')
if 'set_autostart' in request.POST: if 'set_autostart' in request.POST:
conn.set_autostart(1)
msg = _("Set autostart") msg = _("Set autostart")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
conn.set_autostart(1)
return HttpResponseRedirect(request.get_full_path() + '#autostart') return HttpResponseRedirect(request.get_full_path() + '#autostart')
if 'unset_autostart' in request.POST: if 'unset_autostart' in request.POST:
conn.set_autostart(0)
msg = _("Unset autostart") msg = _("Unset autostart")
addlogmsg(request.user.id, instance.id, msg) addlogmsg(request.user.id, instance.id, msg)
conn.set_autostart(0)
return HttpResponseRedirect(request.get_full_path() + '#autostart') return HttpResponseRedirect(request.get_full_path() + '#autostart')
if 'change_xml' in request.POST: if 'change_xml' in request.POST:
msg = _("Edit XML")
addlogmsg(request.user.id, instance.id, msg)
exit_xml = request.POST.get('inst_xml', '') exit_xml = request.POST.get('inst_xml', '')
if exit_xml: if exit_xml:
conn._defineXML(exit_xml) conn._defineXML(exit_xml)
msg = _("Edit XML")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#xmledit') return HttpResponseRedirect(request.get_full_path() + '#xmledit')
if 'set_console_passwd' in request.POST: if 'set_console_passwd' in request.POST:
msg = _("Set VNC password")
addlogmsg(request.user.id, instance.id, msg)
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)])
else: else:
@ -353,29 +363,29 @@ def instance(request, compute_id, vname):
msg = _("Error setting console password. You should check that your instance have an graphic device.") msg = _("Error setting console password. You should check that your instance have an graphic device.")
error_messages.append(msg) error_messages.append(msg)
else: else:
msg = _("Set VNC password")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#vncedit') return HttpResponseRedirect(request.get_full_path() + '#vncedit')
if 'set_console_keymap' in request.POST: if 'set_console_keymap' in request.POST:
msg = _("Set VNC keymap")
addlogmsg(request.user.id, instance.id, msg)
keymap = request.POST.get('console_keymap', '') keymap = request.POST.get('console_keymap', '')
clear = request.POST.get('clear_keymap', False) clear = request.POST.get('clear_keymap', False)
if clear: if clear:
conn.set_console_keymap('') conn.set_console_keymap('')
else: else:
conn.set_console_keymap(keymap) conn.set_console_keymap(keymap)
msg = _("Set VNC keymap")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#vncedit') return HttpResponseRedirect(request.get_full_path() + '#vncedit')
if 'set_console_type' in request.POST: if 'set_console_type' in request.POST:
msg = _("Set VNC type")
addlogmsg(request.user.id, instance.id, msg)
console_type = request.POST.get('console_type', '') console_type = request.POST.get('console_type', '')
conn.set_console_type(console_type) conn.set_console_type(console_type)
msg = _("Set VNC type")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(request.get_full_path() + '#vncedit') return HttpResponseRedirect(request.get_full_path() + '#vncedit')
if 'migrate' in request.POST: if 'migrate' in request.POST:
msg = _("Migrate")
addlogmsg(request.user.id, instance.id, msg)
compute_id = request.POST.get('compute_id', '') compute_id = request.POST.get('compute_id', '')
live = request.POST.get('live_migrate', False) live = request.POST.get('live_migrate', False)
unsafe = request.POST.get('unsafe_migrate', False) unsafe = request.POST.get('unsafe_migrate', False)
@ -388,11 +398,11 @@ def instance(request, compute_id, vname):
conn_migrate.moveto(conn, vname, live, unsafe, xml_del) conn_migrate.moveto(conn, vname, live, unsafe, xml_del)
conn_migrate.define_move(vname) conn_migrate.define_move(vname)
conn_migrate.close() conn_migrate.close()
msg = _("Migrate")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(reverse('instance', args=[compute_id, vname])) return HttpResponseRedirect(reverse('instance', args=[compute_id, vname]))
if 'clone' in request.POST: if 'clone' in request.POST:
msg = _("Clone")
addlogmsg(request.user.id, instance.id, msg)
clone_data = {} clone_data = {}
clone_data['name'] = request.POST.get('name', '') clone_data['name'] = request.POST.get('name', '')
@ -401,6 +411,8 @@ def instance(request, compute_id, vname):
clone_data[post] = request.POST.get(post, '') clone_data[post] = request.POST.get(post, '')
conn.clone_instance(clone_data) conn.clone_instance(clone_data)
msg = _("Clone")
addlogmsg(request.user.id, instance.id, msg)
return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']])) return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']]))
conn.close() conn.close()

View file

@ -88,13 +88,18 @@
<ul class="nav nav-tabs" role="tablist"> <ul class="nav nav-tabs" role="tablist">
{% ifequal status 1 %} {% ifequal status 1 %}
<li role="presentation" class="active"> <li role="presentation" class="active">
<a href="#poweroff" aria-controls="poweroff" role="tab" data-toggle="tab">
{% trans "Power Off" %}
</a>
</li>
<li role="presentation">
<a href="#powercycle" aria-controls="powercycle" role="tab" data-toggle="tab"> <a href="#powercycle" aria-controls="powercycle" role="tab" data-toggle="tab">
{% trans "Power Cycle" %} {% trans "Power Cycle" %}
</a> </a>
</li> </li>
<li role="presentation"> <li role="presentation">
<a href="#poweroff" aria-controls="poweroff" role="tab" data-toggle="tab"> <a href="#powerforce" aria-controls="powerforce" role="tab" data-toggle="tab">
{% trans "Power Off" %} {% trans "Force Off" %}
</a> </a>
</li> </li>
{% if request.user.is_superuser %} {% if request.user.is_superuser %}
@ -131,17 +136,24 @@
<!-- Tab panes --> <!-- Tab panes -->
<div class="tab-content"> <div class="tab-content">
{% ifequal status 1 %} {% ifequal status 1 %}
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="powercycle"> <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="poweroff">
<p>{% trans "This action forcibly powers off the instance and may cause data corruption." %}</p> <p>{% trans "This action sends an ACPI shutdown signal to the instance." %}</p>
<form action="" method="post" role="form">{% csrf_token %}
<input type="submit" name="poweroff" class="btn btn-lg btn-success pull-right" value="{% trans "Power Off" %}">
<div class="clearfix"></div>
</form>
</div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="powercycle">
<p>{% trans "This action forcibly powers off and start the instance and may cause data corruption." %}</p>
<form action="" method="post" role="form">{% csrf_token %} <form action="" method="post" role="form">{% csrf_token %}
<input type="submit" name="powercycle" class="btn btn-lg btn-success pull-right" value="{% trans "Power Cycle" %}"> <input type="submit" name="powercycle" class="btn btn-lg btn-success pull-right" value="{% trans "Power Cycle" %}">
<div class="clearfix"></div> <div class="clearfix"></div>
</form> </form>
</div> </div>
<div role="tabpanel" class="tab-pane tab-pane-bordered" id="poweroff"> <div role="tabpanel" class="tab-pane tab-pane-bordered" id="powerforce">
<p>{% trans "This action sends an ACPI shutdown signal to the instance." %}</p> <p>{% trans "This action forcibly powers off the instance and may cause data corruption." %}</p>
<form action="" method="post" role="form">{% csrf_token %} <form action="" method="post" role="form">{% csrf_token %}
<input type="submit" name="poweroff" class="btn btn-lg btn-success pull-right" value="{% trans "Power Off" %}"> <input type="submit" name="powerforce" class="btn btn-lg btn-success pull-right" value="{% trans "Force Off" %}">
<div class="clearfix"></div> <div class="clearfix"></div>
</form> </form>
</div> </div>

View file

@ -74,7 +74,7 @@
<span class="glyphicon glyphicon-off"></span> <span class="glyphicon glyphicon-off"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<span class="glyphicon glyphicon-stop"></span> <span class="glyphicon glyphicon-refresh"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>
@ -91,7 +91,7 @@
<span class="glyphicon glyphicon-off"></span> <span class="glyphicon glyphicon-off"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<span class="glyphicon glyphicon-stop"></span> <span class="glyphicon glyphicon-refresh"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>
@ -108,7 +108,7 @@
<span class="glyphicon glyphicon-off"></span> <span class="glyphicon glyphicon-off"></span>
</button> </button>
<button class="btn btn-sm btn-default" type="submit" name="powercycle" title="{% trans "Power Cycle" %}" onclick="return confirm('Are you sure?')"> <button class="btn btn-sm btn-default" type="submit" name="powercycle" title="{% trans "Power Cycle" %}" onclick="return confirm('Are you sure?')">
<span class="glyphicon glyphicon-stop"></span> <span class="glyphicon glyphicon-refresh"></span>
</button> </button>
<a href="#" class="btn btn-sm btn-default" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}"> <a href="#" class="btn btn-sm btn-default" onclick='open_console("{{ host.0 }}-{{ info.uuid }}")' title="{% trans "Console" %}">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>
@ -168,7 +168,7 @@
<span class="glyphicon glyphicon-off"></span> <span class="glyphicon glyphicon-off"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<span class="glyphicon glyphicon-stop"></span> <span class="glyphicon glyphicon-refresh"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>
@ -182,7 +182,7 @@
<span class="glyphicon glyphicon-off"></span> <span class="glyphicon glyphicon-off"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "Power Cycle" %}">
<span class="glyphicon glyphicon-stop"></span> <span class="glyphicon glyphicon-refresh"></span>
</button> </button>
<button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <button class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>
@ -196,7 +196,7 @@
<span class="glyphicon glyphicon-off"></span> <span class="glyphicon glyphicon-off"></span>
</button> </button>
<button class="btn btn-sm btn-default" type="submit" name="powercycle" title="{% trans "Power Cycle" %}" onclick="return confirm('Are you sure?')"> <button class="btn btn-sm btn-default" type="submit" name="powercycle" title="{% trans "Power Cycle" %}" onclick="return confirm('Are you sure?')">
<span class="glyphicon glyphicon-stop"></span> <span class="glyphicon glyphicon-refresh"></span>
</button> </button>
<a href="#" class="btn btn-sm btn-default" onclick='open_console("{{ host.0 }}-{{ vm.uuid }}")' title="{% trans "Console" %}"> <a href="#" class="btn btn-sm btn-default" onclick='open_console("{{ host.0 }}-{{ vm.uuid }}")' title="{% trans "Console" %}">
<span class="glyphicon glyphicon-eye-open"></span> <span class="glyphicon glyphicon-eye-open"></span>