1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-11-01 03:54:15 +00:00

Users permission

This commit is contained in:
Retspen 2015-03-16 11:57:55 +02:00
parent b98084b7ee
commit 983dbaf91a
5 changed files with 270 additions and 225 deletions

View file

@ -106,6 +106,24 @@ def instance(request, compute_id, vname):
if not request.user.is_authenticated():
return HttpResponseRedirect(reverse('index'))
error_messages = []
messages = []
compute = Compute.objects.get(id=compute_id)
computes = Compute.objects.all()
computes_count = len(computes)
keymaps = QEMU_KEYMAPS
console_types = QEMU_CONSOLE_TYPES
try:
userinstace = UserInstance.objects.get(instance__compute_id=compute_id,
instance__name=vname,
user__id=request.user.id)
except UserInstance.DoesNotExist:
userinstace = None
if not request.user.is_superuser:
if not userinstace:
return HttpResponseRedirect(reverse('index'))
def show_clone_disk(disks):
clone_disk = []
for disk in disks:
@ -120,14 +138,6 @@ def instance(request, compute_id, vname):
{'dev': disk['dev'], 'storage': disk['storage'], 'image': image, 'format': disk['format']})
return clone_disk
error_messages = []
messages = []
compute = Compute.objects.get(id=compute_id)
computes = Compute.objects.all()
computes_count = len(computes)
keymaps = QEMU_KEYMAPS
console_types = QEMU_CONSOLE_TYPES
try:
conn = wvmInstance(compute.hostname,
compute.login,
@ -164,8 +174,6 @@ def instance(request, compute_id, vname):
has_managed_save_image = conn.get_managed_save_image()
clone_disks = show_clone_disk(disks)
console_passwd = conn.get_console_passwd()
except libvirtError as lib_err:
error_messages.append(lib_err)
try:
instance = Instance.objects.get(compute_id=compute_id, name=vname)
@ -176,9 +184,7 @@ def instance(request, compute_id, vname):
instance = Instance(compute_id=compute_id, name=vname, uuid=uuid)
instance.save()
try:
if request.method == 'POST':
if 'poweron' in request.POST:
conn.start()
return HttpResponseRedirect(request.get_full_path() + '#poweron')
@ -209,8 +215,17 @@ def instance(request, compute_id, vname):
if request.POST.get('delete_disk', ''):
conn.delete_disk()
finally:
if not request.user.is_superuser:
del_userinstance = UserInstance.objects.get(id=userinstace.id)
del_userinstance.delete()
else:
try:
del_userinstance = UserInstance.objects.filter(instance__compute_id=compute_id, instance__name=vname)
del_userinstance.save()
except UserInstance.DoesNotExist:
pass
conn.delete()
return HttpResponseRedirect(reverse('instances', args=[compute_id]))
return HttpResponseRedirect(reverse('instances'))
if 'snapshot' in request.POST:
name = request.POST.get('name', '')
@ -330,7 +345,7 @@ def instance(request, compute_id, vname):
conn.close()
except libvirtError as err:
error_messages.append(err)
except libvirtError as lib_err:
error_messages.append(lib_err)
return render(request, 'instance.html', locals())

View file

@ -7,14 +7,8 @@
<div class="col-lg-12">
<h1 class="page-header">{{ vname }}</h1>
</div>
</div>
<!-- /.row -->
{% include 'errors_block.html' %}
<div class="row" id="max-width-page">
<div class="col-lg-12">
<h4 class="page-header">
{% trans "Status:" %}
{% ifequal status 5 %}
<span class="text-danger">{% trans "Off" %}</span>
{% endifequal %}
@ -24,16 +18,22 @@
{% ifequal status 3 %}
<span class="text-warning">{% trans "Suspend" %}</span>
{% endifequal %}
{% if cur_vcpu %}{{ cur_vcpu }}{% else %}{{ vcpu }}{% endif %} {% trans "Vcpu" %}
{{ cur_memory }}{% trans "MB" %} {% trans "Ram" %}
{% trans "Vcpu:" %}
{% if cur_vcpu %}{{ cur_vcpu }}{% else %}{{ vcpu }}{% endif %}
{% trans "Ram:" %}
{{ cur_memory }}{% trans "MB" %}
{% trans "Disk:" %}
{% for disk in disks %}
{{ disk.size|filesizeformat }} {% trans "Disk" %}
{{ disk.size|filesizeformat }}
{% endfor %}
</h4>
</div>
<!-- /.row -->
{{ description }}
<hr>
{% include 'errors_block.html' %}
<div class="row" id="max-width-page">
<div class="col-lg-12">
<div role="tabpanel">
<!-- Nav tabs -->
<ul class="nav nav-pills" role="tablist">
@ -97,11 +97,13 @@
{% trans "Power Off" %}
</a>
</li>
{% if status %}
<li role="presentation">
<a href="#suspend" aria-controls="suspend" role="tab" data-toggle="tab">
{% trans "Suspend" %}
</a>
</li>
{% endif %}
{% endifequal %}
{% ifequal status 3 %}
<li role="presentation" class="active">
@ -201,6 +203,7 @@
<!-- Tab panes -->
<div class="tab-content">
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resizevm">
{% if request.user.is_superuser or userinstace.is_change %}
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<p style="font-weight:bold;">{% trans "Logical host CPUs:" %} {{ vcpu_host }}</p>
<div class="form-group">
@ -262,6 +265,10 @@
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
{% endifequal %}
</form>
{% else %}
{% trans "You don't have permission for resizing instance" %}
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
{% endif %}
<div class="clearfix"></div>
</div>
</div>
@ -685,6 +692,7 @@
<div class="tab-content">
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="destroy">
<p>{% trans "Delete storage for instance?" %}</p>
{% if request.user.is_superuser or userinstace.is_delete %}
<form class="form-group" method="post" role="form">{% csrf_token %}
<div class="checkbox" style="margin-left: 8px;">
<label>
@ -694,6 +702,9 @@
</div>
<button type="submit" class="btn btn-lg btn-success pull-right" name="delete">{% trans "Destroy" %}</button>
</form>
{% else %}
<button class="btn btn-lg btn-success disabled pull-right" name="delete">{% trans "Destroy" %}</button>
{% endif %}
<div class="clearfix"></div>
</div>
</div>

View file

@ -23,6 +23,14 @@
<div class="col-lg-12">
<div class="table-responsive">
{% if request.user.is_superuser %}
{% if not all_host_vms %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "You don't have any Instace" %}
</div>
</div>
{% else %}
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
<thead>
<tr>
@ -107,6 +115,15 @@
{% endfor %}
</tbody>
</table>
{% endif %}
{% else %}
{% if not all_user_vms %}
<div class="col-lg-12">
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<i class="fa fa-exclamation-triangle"></i> <strong>{% trans "Warning:" %}</strong> {% trans "You don't have any Instace" %}
</div>
</div>
{% else %}
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
<thead>
@ -190,6 +207,7 @@
</tbody>
</table>
{% endif %}
{% endif %}
</div>
</div>
</div>

View file

@ -29,7 +29,7 @@
<tr>
<th>#</th>
<th>{% trans "Name" %}</th>
<th>{% trans "Is blocked" %}</th>
<th>{% trans "User blocked" %}</th>
<th>{% trans "Can change" %}</th>
<th>{% trans "Can delete" %}</th>
<th colspan="2">{% trans "Action" %}</th>

View file

@ -195,6 +195,7 @@ class wvmInstance(wvmConnect):
storage = None
src_fl = None
disk_format = None
disk_size = None
for disk in ctx.xpathEval('/domain/devices/disk'):
device = disk.xpathEval('@device')[0].content
if device == 'disk':