mirror of
https://github.com/retspen/webvirtcloud
synced 2024-11-01 03:54:15 +00:00
Users permission
This commit is contained in:
parent
b98084b7ee
commit
983dbaf91a
5 changed files with 270 additions and 225 deletions
|
@ -106,6 +106,24 @@ def instance(request, compute_id, vname):
|
||||||
if not request.user.is_authenticated():
|
if not request.user.is_authenticated():
|
||||||
return HttpResponseRedirect(reverse('index'))
|
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):
|
def show_clone_disk(disks):
|
||||||
clone_disk = []
|
clone_disk = []
|
||||||
for disk in disks:
|
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']})
|
{'dev': disk['dev'], 'storage': disk['storage'], 'image': image, 'format': disk['format']})
|
||||||
return clone_disk
|
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:
|
try:
|
||||||
conn = wvmInstance(compute.hostname,
|
conn = wvmInstance(compute.hostname,
|
||||||
compute.login,
|
compute.login,
|
||||||
|
@ -164,8 +174,6 @@ def instance(request, compute_id, vname):
|
||||||
has_managed_save_image = conn.get_managed_save_image()
|
has_managed_save_image = conn.get_managed_save_image()
|
||||||
clone_disks = show_clone_disk(disks)
|
clone_disks = show_clone_disk(disks)
|
||||||
console_passwd = conn.get_console_passwd()
|
console_passwd = conn.get_console_passwd()
|
||||||
except libvirtError as lib_err:
|
|
||||||
error_messages.append(lib_err)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
instance = Instance.objects.get(compute_id=compute_id, name=vname)
|
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 = Instance(compute_id=compute_id, name=vname, uuid=uuid)
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
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')
|
||||||
|
@ -209,8 +215,17 @@ 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:
|
||||||
|
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()
|
conn.delete()
|
||||||
return HttpResponseRedirect(reverse('instances', args=[compute_id]))
|
return HttpResponseRedirect(reverse('instances'))
|
||||||
|
|
||||||
if 'snapshot' in request.POST:
|
if 'snapshot' in request.POST:
|
||||||
name = request.POST.get('name', '')
|
name = request.POST.get('name', '')
|
||||||
|
@ -330,7 +345,7 @@ def instance(request, compute_id, vname):
|
||||||
|
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
except libvirtError as err:
|
except libvirtError as lib_err:
|
||||||
error_messages.append(err)
|
error_messages.append(lib_err)
|
||||||
|
|
||||||
return render(request, 'instance.html', locals())
|
return render(request, 'instance.html', locals())
|
|
@ -7,14 +7,8 @@
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<h1 class="page-header">{{ vname }}</h1>
|
<h1 class="page-header">{{ vname }}</h1>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
<h4 class="page-header">
|
||||||
<!-- /.row -->
|
{% trans "Status:" %}
|
||||||
|
|
||||||
{% include 'errors_block.html' %}
|
|
||||||
|
|
||||||
<div class="row" id="max-width-page">
|
|
||||||
<div class="col-lg-12">
|
|
||||||
|
|
||||||
{% ifequal status 5 %}
|
{% ifequal status 5 %}
|
||||||
<span class="text-danger">{% trans "Off" %}</span>
|
<span class="text-danger">{% trans "Off" %}</span>
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
|
@ -24,16 +18,22 @@
|
||||||
{% ifequal status 3 %}
|
{% ifequal status 3 %}
|
||||||
<span class="text-warning">{% trans "Suspend" %}</span>
|
<span class="text-warning">{% trans "Suspend" %}</span>
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
|
{% trans "Vcpu:" %}
|
||||||
{% if cur_vcpu %}{{ cur_vcpu }}{% else %}{{ vcpu }}{% endif %} {% trans "Vcpu" %}
|
{% if cur_vcpu %}{{ cur_vcpu }}{% else %}{{ vcpu }}{% endif %}
|
||||||
{{ cur_memory }}{% trans "MB" %} {% trans "Ram" %}
|
{% trans "Ram:" %}
|
||||||
|
{{ cur_memory }}{% trans "MB" %}
|
||||||
|
{% trans "Disk:" %}
|
||||||
{% for disk in disks %}
|
{% for disk in disks %}
|
||||||
{{ disk.size|filesizeformat }} {% trans "Disk" %}
|
{{ disk.size|filesizeformat }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</h4>
|
||||||
|
</div>
|
||||||
|
<!-- /.row -->
|
||||||
|
|
||||||
{{ description }}
|
{% include 'errors_block.html' %}
|
||||||
<hr>
|
|
||||||
|
|
||||||
|
<div class="row" id="max-width-page">
|
||||||
|
<div class="col-lg-12">
|
||||||
<div role="tabpanel">
|
<div role="tabpanel">
|
||||||
<!-- Nav tabs -->
|
<!-- Nav tabs -->
|
||||||
<ul class="nav nav-pills" role="tablist">
|
<ul class="nav nav-pills" role="tablist">
|
||||||
|
@ -97,11 +97,13 @@
|
||||||
{% trans "Power Off" %}
|
{% trans "Power Off" %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% if status %}
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a href="#suspend" aria-controls="suspend" role="tab" data-toggle="tab">
|
<a href="#suspend" aria-controls="suspend" role="tab" data-toggle="tab">
|
||||||
{% trans "Suspend" %}
|
{% trans "Suspend" %}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
{% ifequal status 3 %}
|
{% ifequal status 3 %}
|
||||||
<li role="presentation" class="active">
|
<li role="presentation" class="active">
|
||||||
|
@ -201,6 +203,7 @@
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="resizevm">
|
<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 %}
|
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
|
||||||
<p style="font-weight:bold;">{% trans "Logical host CPUs:" %} {{ vcpu_host }}</p>
|
<p style="font-weight:bold;">{% trans "Logical host CPUs:" %} {{ vcpu_host }}</p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -262,6 +265,10 @@
|
||||||
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
|
<button class="btn btn-lg btn-success pull-right disabled">{% trans "Resize" %}</button>
|
||||||
{% endifequal %}
|
{% endifequal %}
|
||||||
</form>
|
</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 class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -685,6 +692,7 @@
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="destroy">
|
<div role="tabpanel" class="tab-pane tab-pane-bordered active" id="destroy">
|
||||||
<p>{% trans "Delete storage for instance?" %}</p>
|
<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 %}
|
<form class="form-group" method="post" role="form">{% csrf_token %}
|
||||||
<div class="checkbox" style="margin-left: 8px;">
|
<div class="checkbox" style="margin-left: 8px;">
|
||||||
<label>
|
<label>
|
||||||
|
@ -694,6 +702,9 @@
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-lg btn-success pull-right" name="delete">{% trans "Destroy" %}</button>
|
<button type="submit" class="btn btn-lg btn-success pull-right" name="delete">{% trans "Destroy" %}</button>
|
||||||
</form>
|
</form>
|
||||||
|
{% else %}
|
||||||
|
<button class="btn btn-lg btn-success disabled pull-right" name="delete">{% trans "Destroy" %}</button>
|
||||||
|
{% endif %}
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -23,6 +23,14 @@
|
||||||
<div class="col-lg-12">
|
<div class="col-lg-12">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
{% if request.user.is_superuser %}
|
{% 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>
|
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -107,6 +115,15 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</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 %}
|
{% else %}
|
||||||
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
|
<table class="table table-hover table-striped sortable-theme-bootstrap" data-sortable>
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -190,6 +207,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>#</th>
|
<th>#</th>
|
||||||
<th>{% trans "Name" %}</th>
|
<th>{% trans "Name" %}</th>
|
||||||
<th>{% trans "Is blocked" %}</th>
|
<th>{% trans "User blocked" %}</th>
|
||||||
<th>{% trans "Can change" %}</th>
|
<th>{% trans "Can change" %}</th>
|
||||||
<th>{% trans "Can delete" %}</th>
|
<th>{% trans "Can delete" %}</th>
|
||||||
<th colspan="2">{% trans "Action" %}</th>
|
<th colspan="2">{% trans "Action" %}</th>
|
||||||
|
|
|
@ -195,6 +195,7 @@ class wvmInstance(wvmConnect):
|
||||||
storage = None
|
storage = None
|
||||||
src_fl = None
|
src_fl = None
|
||||||
disk_format = None
|
disk_format = None
|
||||||
|
disk_size = None
|
||||||
for disk in ctx.xpathEval('/domain/devices/disk'):
|
for disk in ctx.xpathEval('/domain/devices/disk'):
|
||||||
device = disk.xpathEval('@device')[0].content
|
device = disk.xpathEval('@device')[0].content
|
||||||
if device == 'disk':
|
if device == 'disk':
|
||||||
|
|
Loading…
Reference in a new issue