diff --git a/instances/views.py b/instances/views.py index 337e75a..1459d7e 100644 --- a/instances/views.py +++ b/instances/views.py @@ -2,6 +2,8 @@ from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse from django.shortcuts import render from computes.models import Compute +from instances.models import Instance +from users.models import UserInstance from vrtManager.hostdetails import wvmHostDetails from vrtManager.connection import connection_manager from libvirt import libvirtError @@ -30,16 +32,38 @@ def instances(request): error_messages = [] all_host_vms = {} - computes = Compute.objects.filter() + all_user_vms = {} + computes = Compute.objects.all() - for compute in computes: - if connection_manager.host_is_up(compute.type, compute.hostname): - try: - conn = wvmHostDetails(compute, compute.login, compute.password, compute.type) - all_host_vms[compute.id, compute.name] = conn.get_host_instances() - conn.close() - except libvirtError as lib_err: - error_messages.append(lib_err) + if not request.user.is_superuser: + user_instances = UserInstance.objects.all() + for usr_inst in user_instances: + if connection_manager.host_is_up(usr_inst.instance.compute.type, + usr_inst.instance.compute.hostname): + conn = wvmHostDetails(usr_inst.instance.compute, + usr_inst.instance.compute.login, + usr_inst.instance.compute.password, + usr_inst.instance.compute.type) + all_user_vms[usr_inst.instance.compute.id, + usr_inst.instance.compute.name] = conn.get_user_instances(usr_inst.instance.name) + else: + for compute in computes: + if connection_manager.host_is_up(compute.type, compute.hostname): + try: + conn = wvmHostDetails(compute, compute.login, compute.password, compute.type) + all_host_vms[compute.id, compute.name] = conn.get_host_instances() + for vm, info in conn.get_host_instances().items(): + try: + check_uuid = Instance.objects.get(compute_id=compute.id, name=vm) + if check_uuid.uuid != info['uuid']: + check_uuid.save() + except Instance.DoesNotExist: + check_uuid = Instance(compute_id=compute.id, name=vm, uuid=info['uuid']) + check_uuid.save() + conn.close() + except libvirtError as lib_err: + print 'Error' + error_messages.append(lib_err) return render(request, 'instances.html', locals()) @@ -53,4 +77,4 @@ def instance(request, comptes_id, vname): if not request.user.is_authenticated(): return HttpResponseRedirect(reverse('index')) - return render(request, 'instances.html', locals()) \ No newline at end of file + return render(request, 'instance.html', locals()) \ No newline at end of file diff --git a/templates/instance.html b/templates/instance.html new file mode 100644 index 0000000..838de5e --- /dev/null +++ b/templates/instance.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% load i18n %} +{% block title %}{% trans "Instance" %} - {{ vname }}{% endblock %} +{% block content %} +
+
+ + {% include 'sidebar.html' %} + +
+ {% if request.user.is_superuser %} + + {% endif %} +

{{ vname }}

+ + {% include 'errors.html' %} + + +
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/instances.html b/templates/instances.html index 22edd2e..3277835 100644 --- a/templates/instances.html +++ b/templates/instances.html @@ -13,12 +13,16 @@ {% include 'errors.html' %} +
+ {% if request.user.is_superuser %} + + @@ -33,6 +37,8 @@ + +
Name HostVCPUMemory Status Actions
{{ host.1 }} {{ info.vcpu }}{{ info.memory }} {% ifequal info.status 1 %} {% trans "Running" %} {% endifequal %} @@ -99,6 +105,94 @@ {% endfor %}
+ + {% else %} + + + + + + + + + + + + + {% for host, vm in all_user_vms.items %} + + + + + + + + {% endfor %} + +
NameVCPUMemoryStatusActions
+ {{ vm.name }} + {{ vm.vcpu }}{{ vm.memory }} {% trans "MB" %}{% ifequal vm.status 1 %} + {% trans "Running" %} + {% endifequal %} + {% ifequal vm.status 5 %} + {% trans "Shutoff" %} + {% endifequal %} + {% ifequal vm.status 3 %} + {% trans "Suspend" %} + {% endifequal %} +
{% csrf_token %} + + + {% ifequal vm.status 5 %} + + + + + {% endifequal %} + {% ifequal vm.status 3 %} + + + + + {% endifequal %} + {% ifequal vm.status 1 %} + + + + + + + {% endifequal %} +
+
+ {% endif %} +
diff --git a/templates/login.html b/templates/login.html new file mode 100644 index 0000000..1e6811f --- /dev/null +++ b/templates/login.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} +{% load i18n %} +{% block title %}{% trans "Sign In" %}{% endblock %} +{% block content %} +
+
+ {% if form.errors %} +
+ + {% trans "Incorrect username or password." %} +
+ {% endif %} + +
+
+{% endblock %} \ No newline at end of file diff --git a/templates/logout.html b/templates/logout.html new file mode 100644 index 0000000..f82ad5d --- /dev/null +++ b/templates/logout.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} +{% load i18n %} +{% block title %}{% trans "Sign Out" %}{% endblock %} +{% block content %} +
+
+
+

{% trans "Successful log out" %}

+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/sidebar.html b/templates/sidebar.html index 9a4d92d..1b0960f 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -5,8 +5,10 @@