mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 15:15:22 +00:00
Fixed #7
This commit is contained in:
parent
5b336b2126
commit
1d22771519
6 changed files with 70 additions and 39 deletions
|
@ -37,3 +37,10 @@ wget -O - https://clck.ru/9Sz6S | sudo sh
|
||||||
login: admin
|
login: admin
|
||||||
|
|
||||||
password: admin
|
password: admin
|
||||||
|
|
||||||
|
|
||||||
|
### How To Update
|
||||||
|
```bash
|
||||||
|
$ python manage.py migrate
|
||||||
|
$ sudo service supervisor restart
|
||||||
|
```
|
|
@ -85,13 +85,13 @@ def instances(request):
|
||||||
instance.compute.type)
|
instance.compute.type)
|
||||||
if 'poweron' in request.POST:
|
if 'poweron' in request.POST:
|
||||||
msg = _("Power On")
|
msg = _("Power On")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
conn.start(name)
|
conn.start(name)
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
if 'poweroff' in request.POST:
|
if 'poweroff' in request.POST:
|
||||||
msg = _("Power Off")
|
msg = _("Power Off")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
conn.shutdown(name)
|
conn.shutdown(name)
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
return HttpResponseRedirect(request.get_full_path())
|
||||||
|
|
||||||
|
@ -99,26 +99,26 @@ def instances(request):
|
||||||
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.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path())
|
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.username, instance.name, 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.username, instance.name, 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.username, instance.name, lib_err.message)
|
||||||
|
|
||||||
return render(request, 'instances.html', locals())
|
return render(request, 'instances.html', locals())
|
||||||
|
|
||||||
|
@ -215,26 +215,26 @@ def instance(request, compute_id, vname):
|
||||||
if 'poweron' in request.POST:
|
if 'poweron' in request.POST:
|
||||||
conn.start()
|
conn.start()
|
||||||
msg = _("Power On")
|
msg = _("Power On")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
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()
|
||||||
msg = _("Power Cycle")
|
msg = _("Power Cycle")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, 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()
|
conn.shutdown()
|
||||||
msg = _("Power Off")
|
msg = _("Power Off")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#poweroff')
|
return HttpResponseRedirect(request.get_full_path() + '#poweroff')
|
||||||
|
|
||||||
if 'powerforce' in request.POST:
|
if 'powerforce' in request.POST:
|
||||||
conn.force_shutdown()
|
conn.force_shutdown()
|
||||||
msg = _("Force Off")
|
msg = _("Force Off")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#powerforce')
|
return HttpResponseRedirect(request.get_full_path() + '#powerforce')
|
||||||
|
|
||||||
if 'delete' in request.POST:
|
if 'delete' in request.POST:
|
||||||
|
@ -242,19 +242,20 @@ def instance(request, compute_id, vname):
|
||||||
conn.force_shutdown()
|
conn.force_shutdown()
|
||||||
try:
|
try:
|
||||||
instance = Instance.objects.get(compute_id=compute_id, name=vname)
|
instance = Instance.objects.get(compute_id=compute_id, name=vname)
|
||||||
|
instance_name = instance.name
|
||||||
instance.delete()
|
instance.delete()
|
||||||
if request.POST.get('delete_disk', ''):
|
if request.POST.get('delete_disk', ''):
|
||||||
conn.delete_disk()
|
conn.delete_disk()
|
||||||
finally:
|
finally:
|
||||||
msg = _("Destroy")
|
msg = _("Destroy")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance_name, 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()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
del_userinstance = UserInstance.objects.filter(instance__compute_id=compute_id, instance__name=vname)
|
del_userinstance = UserInstance.objects.filter(instance__compute_id=compute_id, instance__name=vname)
|
||||||
del_userinstance.save()
|
del_userinstance.delete()
|
||||||
except UserInstance.DoesNotExist:
|
except UserInstance.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
conn.delete()
|
conn.delete()
|
||||||
|
@ -273,7 +274,7 @@ 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)
|
||||||
msg = _("Resize")
|
msg = _("Resize")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, 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:
|
||||||
|
@ -281,7 +282,7 @@ def instance(request, compute_id, vname):
|
||||||
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")
|
msg = _("Mount media")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, 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:
|
||||||
|
@ -289,21 +290,21 @@ def instance(request, compute_id, vname):
|
||||||
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")
|
msg = _("Umount media")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, 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:
|
||||||
name = request.POST.get('name', '')
|
name = request.POST.get('name', '')
|
||||||
conn.create_snapshot(name)
|
conn.create_snapshot(name)
|
||||||
msg = _("New snapshot")
|
msg = _("New snapshot")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#takesnapshot')
|
return HttpResponseRedirect(request.get_full_path() + '#takesnapshot')
|
||||||
|
|
||||||
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)
|
||||||
msg = _("Delete snapshot")
|
msg = _("Delete snapshot")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#restoresnapshot')
|
return HttpResponseRedirect(request.get_full_path() + '#restoresnapshot')
|
||||||
|
|
||||||
if 'revert_snapshot' in request.POST:
|
if 'revert_snapshot' in request.POST:
|
||||||
|
@ -313,31 +314,31 @@ def instance(request, compute_id, vname):
|
||||||
msg += snap_name
|
msg += snap_name
|
||||||
messages.append(msg)
|
messages.append(msg)
|
||||||
msg = _("Revert snapshot")
|
msg = _("Revert snapshot")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
|
|
||||||
if request.user.is_superuser:
|
if request.user.is_superuser:
|
||||||
if 'suspend' in request.POST:
|
if 'suspend' in request.POST:
|
||||||
conn.suspend()
|
conn.suspend()
|
||||||
msg = _("Suspend")
|
msg = _("Suspend")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
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()
|
||||||
msg = _("Resume")
|
msg = _("Resume")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
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)
|
conn.set_autostart(1)
|
||||||
msg = _("Set autostart")
|
msg = _("Set autostart")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
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)
|
conn.set_autostart(0)
|
||||||
msg = _("Unset autostart")
|
msg = _("Unset autostart")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
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:
|
||||||
|
@ -345,7 +346,7 @@ def instance(request, compute_id, vname):
|
||||||
if exit_xml:
|
if exit_xml:
|
||||||
conn._defineXML(exit_xml)
|
conn._defineXML(exit_xml)
|
||||||
msg = _("Edit XML")
|
msg = _("Edit XML")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, 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:
|
||||||
|
@ -365,7 +366,7 @@ def instance(request, compute_id, vname):
|
||||||
error_messages.append(msg)
|
error_messages.append(msg)
|
||||||
else:
|
else:
|
||||||
msg = _("Set VNC password")
|
msg = _("Set VNC password")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
|
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
|
||||||
|
|
||||||
if 'set_console_keymap' in request.POST:
|
if 'set_console_keymap' in request.POST:
|
||||||
|
@ -376,14 +377,14 @@ def instance(request, compute_id, vname):
|
||||||
else:
|
else:
|
||||||
conn.set_console_keymap(keymap)
|
conn.set_console_keymap(keymap)
|
||||||
msg = _("Set VNC keymap")
|
msg = _("Set VNC keymap")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
|
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
|
||||||
|
|
||||||
if 'set_console_type' in request.POST:
|
if 'set_console_type' in request.POST:
|
||||||
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")
|
msg = _("Set VNC type")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, msg)
|
||||||
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
|
return HttpResponseRedirect(request.get_full_path() + '#vncsettings')
|
||||||
|
|
||||||
if 'migrate' in request.POST:
|
if 'migrate' in request.POST:
|
||||||
|
@ -400,7 +401,7 @@ def instance(request, compute_id, vname):
|
||||||
conn_migrate.define_move(vname)
|
conn_migrate.define_move(vname)
|
||||||
conn_migrate.close()
|
conn_migrate.close()
|
||||||
msg = _("Migrate")
|
msg = _("Migrate")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, 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:
|
||||||
|
@ -413,14 +414,14 @@ def instance(request, compute_id, vname):
|
||||||
|
|
||||||
conn.clone_instance(clone_data)
|
conn.clone_instance(clone_data)
|
||||||
msg = _("Clone")
|
msg = _("Clone")
|
||||||
addlogmsg(request.user.id, instance.id, msg)
|
addlogmsg(request.user.username, instance.name, 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()
|
||||||
|
|
||||||
except libvirtError as lib_err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(lib_err.message)
|
error_messages.append(lib_err.message)
|
||||||
addlogmsg(request.user.id, instance.id, lib_err.message)
|
addlogmsg(request.user.username, instance.name, lib_err.message)
|
||||||
|
|
||||||
return render(request, 'instance.html', locals())
|
return render(request, 'instance.html', locals())
|
||||||
|
|
||||||
|
|
24
logs/migrations/0003_auto_20150518_1855.py
Normal file
24
logs/migrations/0003_auto_20150518_1855.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('logs', '0002_auto_20150316_1420'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='logs',
|
||||||
|
name='instance',
|
||||||
|
field=models.CharField(max_length=50),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='logs',
|
||||||
|
name='user',
|
||||||
|
field=models.CharField(max_length=50),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,12 +1,11 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from instances.models import Instance
|
|
||||||
from django.contrib.auth.models import User
|
|
||||||
|
|
||||||
class Logs(models.Model):
|
class Logs(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.CharField(max_length=50)
|
||||||
instance = models.ForeignKey(Instance)
|
instance = models.CharField(max_length=50)
|
||||||
message = models.CharField(max_length=255)
|
message = models.CharField(max_length=255)
|
||||||
date = models.DateTimeField(auto_now=True)
|
date = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.instance
|
return self.instance
|
||||||
|
|
|
@ -37,10 +37,10 @@
|
||||||
{% for log in logs %}
|
{% for log in logs %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ forloop.counter }}</td>
|
<td>{{ forloop.counter }}</td>
|
||||||
<td><a href="{% url 'account' log.user.id %}">{{ log.user }}</a></td>
|
<td>{{ log.user }}</a></td>
|
||||||
<td><a href="{% url 'instance' log.instance.compute.id log.instance %}">{{ log.instance }}</a></td>
|
<td>{{ log.instance }}</a></td>
|
||||||
<td>{{ log.message }}</td>
|
<td>{{ log.message }}</td>
|
||||||
<td style="width:120px;">{{ log.date|date:"M d H:i:s" }}</td>
|
<td style="width:130px;">{{ log.date|date:"M d H:i:s" }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -4,12 +4,12 @@ from django.core.urlresolvers import reverse
|
||||||
from logs.models import Logs
|
from logs.models import Logs
|
||||||
|
|
||||||
|
|
||||||
def addlogmsg(userid, instanceid, message):
|
def addlogmsg(user, instance, message):
|
||||||
"""
|
"""
|
||||||
:param request:
|
:param request:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
add_log_msg = Logs(user_id=userid, instance_id=instanceid, message=message)
|
add_log_msg = Logs(user=user, instance=instance, message=message)
|
||||||
add_log_msg.save()
|
add_log_msg.save()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue