From 40738d792017e4a7642733c47a7512c20adc74a7 Mon Sep 17 00:00:00 2001 From: Bandic007 Date: Thu, 27 Sep 2018 11:54:11 +0300 Subject: [PATCH] Additional changes --- computes/templates/overview.html | 3 + computes/urls.py | 23 ++- computes/views.py | 22 +++ console/templates/console-vnc-full.html | 4 +- console/templates/console-vnc-lite.html | 3 +- console/views.py | 5 +- instances/templates/compute_instances.html | 199 +++++++++++++++++++++ instances/templates/instances_grouped.html | 1 + instances/views.py | 13 +- interfaces/templates/interfaces.html | 5 +- networks/templates/networks.html | 5 +- nwfilters/templates/nwfilters.html | 3 + secrets/templates/secrets.html | 7 +- static/js/sortable.min.js | 2 +- storages/templates/storage.html | 2 +- storages/templates/storages.html | 5 +- webvirtcloud/urls.py | 6 + 17 files changed, 289 insertions(+), 19 deletions(-) create mode 100644 instances/templates/compute_instances.html diff --git a/computes/templates/overview.html b/computes/templates/overview.html index 89251cc..466c10e 100644 --- a/computes/templates/overview.html +++ b/computes/templates/overview.html @@ -11,6 +11,9 @@
  • {% trans "Overview" %}
  • +
  • + {% trans "Instances" %} +
  • {% trans "Storages" %}
  • diff --git a/computes/urls.py b/computes/urls.py index 58a0497..4b4ab6d 100644 --- a/computes/urls.py +++ b/computes/urls.py @@ -1,9 +1,22 @@ from django.conf.urls import url -from . import views +from storages.views import storages, storage +from networks.views import networks, network +from secrets.views import secrets +from create.views import create_instance +from interfaces.views import interfaces, interface +from computes.views import overview, compute_graph +from instances.views import instances urlpatterns = [ - url(r'^$', views.computes, name='computes'), - url(r'^overview/(?P[0-9]+)/$', views.overview, name='overview'), - url(r'^statistics/(?P[0-9]+)/$', - views.compute_graph, name='compute_graph'), + url(r'^(?P[0-9]+)/$', overview, name='overview'), + url(r'^(?P[0-9]+)/statistics$', compute_graph, name='compute_graph'), + url(r'^(?P[0-9]+)/instances/$', instances, name='compute_instances'), + url(r'^(?P[0-9]+)/storages/$', storages, name='storages'), + url(r'^(?P[0-9]+)/storage/(?P[\w\-\.\/]+)/$', storage, name='storage'), + url(r'^(?P[0-9]+)/networks/$', networks, name='networks'), + url(r'^(?P[0-9]+)/network/(?P[\w\-\.]+)/$', network, name='network'), + url(r'^(?P[0-9]+)/interfaces/$', interfaces, name='interfaces'), + url(r'^(?P[0-9]+)/interface/(?P[\w\-\.\:]+)/$', interface, name='interface'), + url(r'^(?P[0-9]+)/secrets/$', secrets, name='secrets'), + url(r'^(?P[0-9]+)/create/$', create_instance, name='create_instance'), ] diff --git a/computes/views.py b/computes/views.py index 18ad680..93e3f5e 100644 --- a/computes/views.py +++ b/computes/views.py @@ -134,6 +134,28 @@ def computes(request): error_messages.append(msg_err.as_text()) return render(request, 'computes.html', locals()) +@login_required +def compute_instances(request, compute_id): + """ + :param request: + :return: + """ + if not request.user.is_superuser: + return HttpResponseRedirect(reverse('index')) + error_messages = [] + compute = get_object_or_404(Compute, pk=compute_id) + try: + conn = wvmHostDetails(compute.hostname, + compute.login, + compute.password, + compute.type) + hostname, host_arch, host_memory, logical_cpu, model_cpu, uri_conn = conn.get_node_info() + hypervisor = conn.hypervisor_type() + mem_usage = conn.get_memory_usage() + conn.close() + except libvirtError as lib_err: + error_messages.append(lib_err) + return render(request, 'compute_instances.html', locals()) @login_required def overview(request, compute_id): diff --git a/console/templates/console-vnc-full.html b/console/templates/console-vnc-full.html index 6149289..ff6ee98 100755 --- a/console/templates/console-vnc-full.html +++ b/console/templates/console-vnc-full.html @@ -233,7 +233,7 @@
  • - +
  • @@ -332,4 +332,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/console/templates/console-vnc-lite.html b/console/templates/console-vnc-lite.html index 4dd7bfe..0502a62 100755 --- a/console/templates/console-vnc-lite.html +++ b/console/templates/console-vnc-lite.html @@ -220,6 +220,7 @@ //var port = WebUtil.getConfigVar('port', window.location.port); var host = '{{ ws_host }}'; var port = '{{ ws_port }}'; + var wspath = '{{ ws_path }}'; // if port == 80 (or 443) then it won't be present and should be // set manually @@ -263,7 +264,7 @@ url = 'ws'; } - url += '://' + host; + url += '://' + host + wspath; if(port) { url += ':' + port; } diff --git a/console/views.py b/console/views.py index 4196ff0..70d0186 100644 --- a/console/views.py +++ b/console/views.py @@ -7,6 +7,8 @@ from instances.models import Instance from vrtManager.instance import wvmInstance from webvirtcloud.settings import WS_PORT from webvirtcloud.settings import WS_PUBLIC_HOST +from webvirtcloud.settings import WS_PUBLIC_PORT +from webvirtcloud.settings import WS_PUBLIC_PATH from libvirt import libvirtError @@ -40,8 +42,9 @@ def console(request): console_websocket_port = None console_passwd = None - ws_port = console_websocket_port if console_websocket_port else WS_PORT + ws_port = console_websocket_port if console_websocket_port else WS_PUBLIC_PORT ws_host = WS_PUBLIC_HOST if WS_PUBLIC_HOST else request.get_host() + ws_path = WS_PUBLIC_PATH if WS_PUBLIC_PATH else '/' if ':' in ws_host: ws_host = re.sub(':[0-9]+', '', ws_host) diff --git a/instances/templates/compute_instances.html b/instances/templates/compute_instances.html new file mode 100644 index 0000000..e96c763 --- /dev/null +++ b/instances/templates/compute_instances.html @@ -0,0 +1,199 @@ +{% extends "base.html" %} +{% load i18n %} +{% load staticfiles %} +{% block title %}{% trans "Instances" %} - {{ compute.name }}{% endblock %} +{% block style %} + +{% endblock %} +{% block content %} + +
    +
    + {% if request.user.is_superuser %} + {% include 'create_inst_block.html' %} + {% endif %} + {% if all_host_vms or all_user_vms %} + + {% endif %} +

    {{ compute.name }}

    +
    +
    + + + + {% include 'errors_block.html' %} +
    + {% if not all_host_vms %} +
    +
    + + {% trans "Warning:" %} {% trans "Hypervisor doesn't have any instances" %} +
    +
    + {% else %} +
    + + + + + + + + + + + + + {% for host, inst in all_host_vms.items %} + {% for vm, info in inst.items %} + + + + + + + + + {% endfor %} + {% endfor %} + +
    Name
    Description
    Host
    User
    StatusVCPUMemoryActions
    {{ vm }}
    {{ info.title }}
    {{ host.1 }}
    {% if info.userinstances.count > 0 %}{{ info.userinstances.first_user.user.username }}{% if info.userinstances.count > 1 %} (+{{ info.userinstances.count|add:"-1" }}){% endif %}{% endif %}
    + {% ifequal info.status 1 %}{% trans "Active" %}{% endifequal %} + {% ifequal info.status 5 %}{% trans "Off" %}{% endifequal %} + {% ifequal info.status 3 %}{% trans "Suspend" %}{% endifequal %} + {{ info.vcpu }}{{ info.memory|filesizeformat }}
    {% csrf_token %} + + + {% ifequal info.status 5 %} + {% if info.is_template %} + + {% else %} + + {% endif %} + + + + + {% endifequal %} + {% ifequal info.status 3 %} + + + + + + {% endifequal %} + {% ifequal info.status 1 %} + + + + + + + + {% endifequal %} +
    +
    +
    + {% endif %} +
    +{% endblock %} +{% block script %} + + + + +{% if request.user.is_superuser %} + +{% endif %} +{% endblock %} diff --git a/instances/templates/instances_grouped.html b/instances/templates/instances_grouped.html index 2e129c2..0d16056 100644 --- a/instances/templates/instances_grouped.html +++ b/instances/templates/instances_grouped.html @@ -15,6 +15,7 @@ {% for host, inst in all_host_vms.items %} + {{ inst.items|length }} {{ host.1 }} diff --git a/instances/views.py b/instances/views.py index 70fb9bf..19db3fb 100644 --- a/instances/views.py +++ b/instances/views.py @@ -38,7 +38,7 @@ def index(request): @login_required -def instances(request): +def instances(request, compute_id=None): """ :param request: :return: @@ -47,7 +47,11 @@ def instances(request): error_messages = [] all_host_vms = {} all_user_vms = {} - computes = Compute.objects.all().order_by("name") + + if not compute_id: + computes = Compute.objects.all().order_by("name") + else: + computes = [Compute.objects.get(id=compute_id),] def get_userinstances_info(instance): info = {} @@ -195,8 +199,11 @@ def instances(request): view_style = settings.VIEW_INSTANCES_LIST_STYLE - return render(request, 'instances.html', locals()) + if compute_id: + compute = computes[0] + return render(request, 'compute_instances.html', locals()) + return render(request, 'instances.html', locals()) @login_required def instance(request, compute_id, vname): diff --git a/interfaces/templates/interfaces.html b/interfaces/templates/interfaces.html index 58d4978..c121595 100644 --- a/interfaces/templates/interfaces.html +++ b/interfaces/templates/interfaces.html @@ -12,6 +12,9 @@
  • {% trans "Overview" %}
  • +
  • + {% trans "Instances" %} +
  • {% trans "Storages" %}
  • @@ -94,4 +97,4 @@ }).change(); }); -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/networks/templates/networks.html b/networks/templates/networks.html index 2acc1f3..5e843ae 100644 --- a/networks/templates/networks.html +++ b/networks/templates/networks.html @@ -11,6 +11,9 @@
  • {% trans "Overview" %}
  • +
  • + {% trans "Instances" %} +
  • {% trans "Storages" %}
  • @@ -80,4 +83,4 @@ }).change(); }); -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/nwfilters/templates/nwfilters.html b/nwfilters/templates/nwfilters.html index e237380..9fd228f 100644 --- a/nwfilters/templates/nwfilters.html +++ b/nwfilters/templates/nwfilters.html @@ -12,6 +12,9 @@
  • {% trans "Overview" %}
  • +
  • + {% trans "Instances" %} +
  • {% trans "Storages" %}
  • diff --git a/secrets/templates/secrets.html b/secrets/templates/secrets.html index 07b104a..28d8dbd 100644 --- a/secrets/templates/secrets.html +++ b/secrets/templates/secrets.html @@ -10,11 +10,14 @@
    {% include 'create_secret_block.html' %} -

    {% trans "Secrets" %}

    +

    {{ compute.name }}

    diff --git a/storages/templates/storages.html b/storages/templates/storages.html index 026fe13..20f147c 100644 --- a/storages/templates/storages.html +++ b/storages/templates/storages.html @@ -11,6 +11,9 @@
  • {% trans "Overview" %}
  • +
  • + {% trans "Instances" %} +
  • {% trans "Storages" %}
  • @@ -67,4 +70,4 @@ {% endfor %} {% endif %}
    -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/webvirtcloud/urls.py b/webvirtcloud/urls.py index 79992af..2aa2c58 100644 --- a/webvirtcloud/urls.py +++ b/webvirtcloud/urls.py @@ -8,6 +8,7 @@ from create.views import create_instance from interfaces.views import interfaces, interface from console.views import console from nwfilters.views import nwfilters, nwfilter +from computes.views import computes # from django.contrib import admin urlpatterns = [ @@ -15,8 +16,13 @@ urlpatterns = [ url(r'^instances/$', instances, name='instances'), url(r'^instance/', include('instances.urls')), + url(r'^instances/$', instances, name='instances'), + url(r'^accounts/', include('accounts.urls')), + url(r'^computes/', include('computes.urls')), + url(r'^computes/', computes, name='computes'), + url(r'^logs/', include('logs.urls')), url(r'^datasource/', include('datasource.urls')),