diff --git a/instances/views.py b/instances/views.py index ea8a159..4e55bfb 100644 --- a/instances/views.py +++ b/instances/views.py @@ -88,28 +88,34 @@ def instances(request): addlogmsg(request.user.id, instance.id, msg) conn.start(name) 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: msg = _("Power Cycle") conn.force_shutdown(name) conn.start(name) addlogmsg(request.user.id, instance.id, msg) 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 'suspend' in request.POST: msg = _("Suspend") addlogmsg(request.user.id, instance.id, msg) conn.suspend(name) return HttpResponseRedirect(request.get_full_path()) + if 'resume' in request.POST: msg = _("Resume") addlogmsg(request.user.id, instance.id, msg) conn.resume(name) return HttpResponseRedirect(request.get_full_path()) + except libvirtError as lib_err: error_messages.append(lib_err) addlogmsg(request.user.id, instance.id, lib_err.message) @@ -206,27 +212,31 @@ def instance(request, compute_id, vname): if request.method == 'POST': if 'poweron' in request.POST: + conn.start() msg = _("Power On") addlogmsg(request.user.id, instance.id, msg) - conn.start() return HttpResponseRedirect(request.get_full_path() + '#poweron') if 'powercycle' in request.POST: - msg = _("Power Cycle") - addlogmsg(request.user.id, instance.id, msg) conn.force_shutdown() conn.start() + msg = _("Power Cycle") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#powercycle') if 'poweroff' == request.POST.get('power', ''): + conn.shutdown() msg = _("Power Off") addlogmsg(request.user.id, instance.id, msg) - conn.shutdown() return HttpResponseRedirect(request.get_full_path() + '#poweroff') - if 'delete' in request.POST: - msg = _("Destroy") + if 'powerforce' in request.POST: + conn.force_shutdown() + msg = _("Force Off") addlogmsg(request.user.id, instance.id, msg) + return HttpResponseRedirect(request.get_full_path() + '#powerforce') + + if 'delete' in request.POST: if conn.get_status() == 1: conn.force_shutdown() try: @@ -235,6 +245,8 @@ def instance(request, compute_id, vname): if request.POST.get('delete_disk', ''): conn.delete_disk() finally: + msg = _("Destroy") + addlogmsg(request.user.id, instance.id, msg) if not request.user.is_superuser: del_userinstance = UserInstance.objects.get(id=userinstace.id) del_userinstance.delete() @@ -248,8 +260,6 @@ def instance(request, compute_id, vname): return HttpResponseRedirect(reverse('instances')) if 'resize' in request.POST: - msg = _("Resize") - addlogmsg(request.user.id, instance.id, msg) vcpu = request.POST.get('vcpu', '') cur_vcpu = request.POST.get('cur_vcpu', '') memory = request.POST.get('memory', '') @@ -261,83 +271,83 @@ def instance(request, compute_id, vname): if cur_memory_custom: cur_memory = cur_memory_custom conn.resize(cur_memory, memory, cur_vcpu, vcpu) + msg = _("Resize") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#resize') if 'umount_iso' in request.POST: - msg = _("Mount media") - addlogmsg(request.user.id, instance.id, msg) image = request.POST.get('path', '') dev = request.POST.get('umount_iso', '') conn.umount_iso(dev, image) + msg = _("Mount media") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#media') if 'mount_iso' in request.POST: - msg = _("Umount media") - addlogmsg(request.user.id, instance.id, msg) image = request.POST.get('media', '') dev = request.POST.get('mount_iso', '') conn.mount_iso(dev, image) + msg = _("Umount media") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#media') if 'snapshot' in request.POST: - msg = _("New snapshot") - addlogmsg(request.user.id, instance.id, msg) name = request.POST.get('name', '') conn.create_snapshot(name) + msg = _("New snapshot") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#snapshot') if 'delete_snapshot' in request.POST: - msg = _("Delete snapshot") - addlogmsg(request.user.id, instance.id, msg) snap_name = request.POST.get('name', '') conn.snapshot_delete(snap_name) + msg = _("Delete snapshot") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#snapshot') if 'revert_snapshot' in request.POST: - msg = _("Revert snapshot") - addlogmsg(request.user.id, instance.id, msg) snap_name = request.POST.get('name', '') conn.snapshot_revert(snap_name) msg = _("Successful revert snapshot: ") msg += snap_name messages.append(msg) + msg = _("Revert snapshot") + addlogmsg(request.user.id, instance.id, msg) if request.user.is_superuser: if 'suspend' in request.POST: + conn.suspend() msg = _("Suspend") addlogmsg(request.user.id, instance.id, msg) - conn.suspend() return HttpResponseRedirect(request.get_full_path() + '#resume') if 'resume' in request.POST: + conn.resume() msg = _("Resume") addlogmsg(request.user.id, instance.id, msg) - conn.resume() return HttpResponseRedirect(request.get_full_path() + '#suspend') if 'set_autostart' in request.POST: + conn.set_autostart(1) msg = _("Set autostart") addlogmsg(request.user.id, instance.id, msg) - conn.set_autostart(1) return HttpResponseRedirect(request.get_full_path() + '#autostart') if 'unset_autostart' in request.POST: + conn.set_autostart(0) msg = _("Unset autostart") addlogmsg(request.user.id, instance.id, msg) - conn.set_autostart(0) return HttpResponseRedirect(request.get_full_path() + '#autostart') if 'change_xml' in request.POST: - msg = _("Edit XML") - addlogmsg(request.user.id, instance.id, msg) exit_xml = request.POST.get('inst_xml', '') if exit_xml: conn._defineXML(exit_xml) + msg = _("Edit XML") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#xmledit') if 'set_console_passwd' in request.POST: - msg = _("Set VNC password") - addlogmsg(request.user.id, instance.id, msg) if request.POST.get('auto_pass', ''): passwd = ''.join([choice(letters + digits) for i in xrange(12)]) 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.") error_messages.append(msg) else: + msg = _("Set VNC password") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#vncedit') if 'set_console_keymap' in request.POST: - msg = _("Set VNC keymap") - addlogmsg(request.user.id, instance.id, msg) keymap = request.POST.get('console_keymap', '') clear = request.POST.get('clear_keymap', False) if clear: conn.set_console_keymap('') else: conn.set_console_keymap(keymap) + msg = _("Set VNC keymap") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#vncedit') 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', '') conn.set_console_type(console_type) + msg = _("Set VNC type") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(request.get_full_path() + '#vncedit') if 'migrate' in request.POST: - msg = _("Migrate") - addlogmsg(request.user.id, instance.id, msg) compute_id = request.POST.get('compute_id', '') live = request.POST.get('live_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.define_move(vname) conn_migrate.close() + msg = _("Migrate") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(reverse('instance', args=[compute_id, vname])) if 'clone' in request.POST: - msg = _("Clone") - addlogmsg(request.user.id, instance.id, msg) clone_data = {} clone_data['name'] = request.POST.get('name', '') @@ -401,6 +411,8 @@ def instance(request, compute_id, vname): clone_data[post] = request.POST.get(post, '') conn.clone_instance(clone_data) + msg = _("Clone") + addlogmsg(request.user.id, instance.id, msg) return HttpResponseRedirect(reverse('instance', args=[compute_id, clone_data['name']])) conn.close() diff --git a/templates/instance.html b/templates/instance.html index de68a17..00f698e 100644 --- a/templates/instance.html +++ b/templates/instance.html @@ -88,13 +88,18 @@ <ul class="nav nav-tabs" role="tablist"> {% ifequal status 1 %} <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"> {% trans "Power Cycle" %} </a> </li> <li role="presentation"> - <a href="#poweroff" aria-controls="poweroff" role="tab" data-toggle="tab"> - {% trans "Power Off" %} + <a href="#powerforce" aria-controls="powerforce" role="tab" data-toggle="tab"> + {% trans "Force Off" %} </a> </li> {% if request.user.is_superuser %} @@ -131,17 +136,24 @@ <!-- Tab panes --> <div class="tab-content"> {% ifequal status 1 %} - <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="powercycle"> - <p>{% trans "This action forcibly powers off the instance and may cause data corruption." %}</p> + <div role="tabpanel" class="tab-pane tab-pane-bordered active" id="poweroff"> + <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 %} <input type="submit" name="powercycle" class="btn btn-lg btn-success pull-right" value="{% trans "Power Cycle" %}"> <div class="clearfix"></div> </form> </div> - <div role="tabpanel" class="tab-pane tab-pane-bordered" id="poweroff"> - <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 role="tabpanel" class="tab-pane tab-pane-bordered" id="powerforce"> + <p>{% trans "This action forcibly powers off the instance and may cause data corruption." %}</p> + <form action="" method="post" role="form">{% csrf_token %} + <input type="submit" name="powerforce" class="btn btn-lg btn-success pull-right" value="{% trans "Force Off" %}"> <div class="clearfix"></div> </form> </div> diff --git a/templates/instances.html b/templates/instances.html index 8ec059d..a8283df 100644 --- a/templates/instances.html +++ b/templates/instances.html @@ -74,7 +74,7 @@ <span class="glyphicon glyphicon-off"></span> </button> <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 class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <span class="glyphicon glyphicon-eye-open"></span> @@ -91,7 +91,7 @@ <span class="glyphicon glyphicon-off"></span> </button> <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 class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <span class="glyphicon glyphicon-eye-open"></span> @@ -108,7 +108,7 @@ <span class="glyphicon glyphicon-off"></span> </button> <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> <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> @@ -168,7 +168,7 @@ <span class="glyphicon glyphicon-off"></span> </button> <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 class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <span class="glyphicon glyphicon-eye-open"></span> @@ -182,7 +182,7 @@ <span class="glyphicon glyphicon-off"></span> </button> <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 class="btn btn-sm btn-default disabled" title="{% trans "VNC Console" %}"> <span class="glyphicon glyphicon-eye-open"></span> @@ -196,7 +196,7 @@ <span class="glyphicon glyphicon-off"></span> </button> <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> <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>