From 609651d707255b826fac7fa24e9abe82d7bf72b3 Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Thu, 9 Mar 2017 15:14:38 +0100 Subject: [PATCH 01/38] disable page reloading while migrating vm and pleaseWaitDialog is displayed fixes: http redirect after migrate does not jump to new compute node --- instances/templates/instance.html | 5 +++-- templates/pleasewaitdialog.html | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index b77d469..f795687 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -1290,13 +1290,14 @@ }); From fe89af9d8fdae0e5d2d76a643fb22ea83d78e318 Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Fri, 31 Mar 2017 14:29:27 +0200 Subject: [PATCH 02/38] using custom accounts.backends.MyRemoteUserBackend, which adds default instances and attributes for user create_missing_userattributes removed from accounts view --- accounts/backends.py | 25 ++++++++++++++++++++++++- accounts/views.py | 10 ---------- webvirtcloud/settings.py | 4 ++-- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/accounts/backends.py b/accounts/backends.py index 77aa509..3fb208b 100644 --- a/accounts/backends.py +++ b/accounts/backends.py @@ -1,7 +1,30 @@ from django.contrib.auth.backends import RemoteUserBackend +from accounts.models import UserInstance, UserAttributes +from instances.models import Instance class MyRemoteUserBackend(RemoteUserBackend): + + #create_unknown_user = True + default_instances = [ 'debian8-template' ] + + def create_missing_userattributes(self, user): + try: + userattributes = user.userattributes + except UserAttributes.DoesNotExist: + userattributes = UserAttributes(user=user) + userattributes.save() + + def add_default_instances(self, user): + existing_instances = UserInstance.objects.filter(user=user) + if not existing_instances: + for instance_name in self.default_instances: + instance = Instance.objects.get(name=instance_name) + user_instance = UserInstance(user=user, instance=instance) + user_instance.save() + def configure_user(self, user): - user.is_superuser = True + #user.is_superuser = True + self.create_missing_userattributes(user) + self.add_default_instances(user) return user diff --git a/accounts/views.py b/accounts/views.py index 155ecc8..568eb6a 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -70,21 +70,11 @@ def accounts(request): :param request: :return: """ - - def create_missing_userattributes(users): - for user in users: - try: - userattributes = user.userattributes - except UserAttributes.DoesNotExist: - userattributes = UserAttributes(user=user) - userattributes.save() - if not request.user.is_superuser: return HttpResponseRedirect(reverse('index')) error_messages = [] users = User.objects.all().order_by('username') - create_missing_userattributes(users) allow_empty_password = settings.ALLOW_EMPTY_PASSWORD if request.method == 'POST': diff --git a/webvirtcloud/settings.py b/webvirtcloud/settings.py index 0c31433..9e0ff3a 100644 --- a/webvirtcloud/settings.py +++ b/webvirtcloud/settings.py @@ -45,8 +45,8 @@ MIDDLEWARE_CLASSES = ( ) AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.RemoteUserBackend', - #'accounts.backends.MyRemoteUserBackend', + #'django.contrib.auth.backends.RemoteUserBackend', + 'accounts.backends.MyRemoteUserBackend', ) LOGIN_URL = '/accounts/login' From 14b0751930c75daaf964f4222ac3a74c2cb736ec Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Fri, 31 Mar 2017 14:33:03 +0200 Subject: [PATCH 03/38] UserAttributes can_clone_instances defaults to True --- accounts/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/models.py b/accounts/models.py index 06fefee..3c8b00c 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -24,7 +24,7 @@ class UserSSHKey(models.Model): class UserAttributes(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) - can_clone_instances = models.BooleanField(default=False) + can_clone_instances = models.BooleanField(default=True) max_instances = models.IntegerField(default=1) max_cpus = models.IntegerField(default=1) max_memory = models.IntegerField(default=2048) From 6858448b60dd5ee7b08fe035b85198295a593b34 Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Thu, 20 Apr 2017 14:45:01 +0200 Subject: [PATCH 04/38] fix multiple media selection in instance settings form --- instances/templates/instance.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index f795687..7de295b 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -546,8 +546,8 @@
-
{% csrf_token %} - {% for cd in media %} + {% for cd in media %} + {% csrf_token %}
{% if not cd.image %} @@ -579,8 +579,8 @@
{% endif %}
- {% endfor %} - + + {% endfor %}
{% if request.user.is_superuser %} From b7457a4362797fbdefb09059931463fdd0ed29f2 Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Thu, 20 Apr 2017 14:46:42 +0200 Subject: [PATCH 05/38] automatic remove instances with the same name sometimes (fe. after manual migrations) some instances appear multiple times in the database. this patch removes them from the database while refreshing instance uuid. only under superuser. records log message. --- instances/views.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/instances/views.py b/instances/views.py index 44297ce..e098788 100644 --- a/instances/views.py +++ b/instances/views.py @@ -57,6 +57,25 @@ def instances(request): info['first_user'] = None return info + def refresh_instance_database(comp, vm, info): + instances_count = Instance.objects.filter(name=vm).count() + if instances_count > 1: + for i in Instance.objects.filter(name=vm): + user_instances_count = UserInstance.objects.filter(instance=i).count() + if user_instances_count == 0: + addlogmsg(request.user.username, i.name, _("Deleting due to multiple records.")) + i.delete() + + try: + check_uuid = Instance.objects.get(compute_id=comp.id, name=vm) + if check_uuid.uuid != info['uuid']: + check_uuid.save() + all_host_vms[comp.id, comp.name][vm]['is_template'] = check_uuid.is_template + all_host_vms[comp.id, comp.name][vm]['userinstances'] = get_userinstances_info(check_uuid) + except Instance.DoesNotExist: + check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid']) + check_uuid.save() + if not request.user.is_superuser: user_instances = UserInstance.objects.filter(user_id=request.user.id) for usr_inst in user_instances: @@ -76,15 +95,8 @@ def instances(request): if conn.get_host_instances(): all_host_vms[comp.id, comp.name] = conn.get_host_instances() for vm, info in conn.get_host_instances().items(): - try: - check_uuid = Instance.objects.get(compute_id=comp.id, name=vm) - if check_uuid.uuid != info['uuid']: - check_uuid.save() - all_host_vms[comp.id, comp.name][vm]['is_template'] = check_uuid.is_template - all_host_vms[comp.id, comp.name][vm]['userinstances'] = get_userinstances_info(check_uuid) - except Instance.DoesNotExist: - check_uuid = Instance(compute_id=comp.id, name=vm, uuid=info['uuid']) - check_uuid.save() + refresh_instance_database(comp, vm, info) + conn.close() except libvirtError as lib_err: error_messages.append(lib_err) From 4d08f956fb8af591feed1b69df6c40e7d1655a5c Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Thu, 11 May 2017 10:46:39 +0200 Subject: [PATCH 06/38] add /instance/sshkeys/ endpoint for retrieving instance owners ssh keys --- instances/urls.py | 2 ++ instances/views.py | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/instances/urls.py b/instances/urls.py index e8f263b..dfba916 100644 --- a/instances/urls.py +++ b/instances/urls.py @@ -14,4 +14,6 @@ urlpatterns = [ views.guess_clone_name, name='guess_clone_name'), url(r'^check_instance/(?P[\w\-\.]+)/$', views.check_instance, name='check_instance'), + url(r'^sshkeys/(?P[\w\-\.]+)/$', + views.sshkeys, name='sshkeys'), ] diff --git a/instances/views.py b/instances/views.py index e098788..a746763 100644 --- a/instances/views.py +++ b/instances/views.py @@ -807,7 +807,7 @@ def guess_mac_address(request, vname): if name_found and "hardware ethernet" in line: data['mac'] = line.split(' ')[-1].strip().strip(';') break - return HttpResponse(json.dumps(data)); + return HttpResponse(json.dumps(data)) @login_required def guess_clone_name(request): @@ -823,7 +823,7 @@ def guess_clone_name(request): hostname = fqdn.split('.')[0] if hostname.startswith(prefix) and hostname not in instance_names: return HttpResponse(json.dumps({'name': hostname})) - return HttpResponse(json.dumps({})); + return HttpResponse(json.dumps({})) @login_required def check_instance(request, vname): @@ -831,4 +831,20 @@ def check_instance(request, vname): data = { 'vname': vname, 'exists': False } if check_instance: data['exists'] = True - return HttpResponse(json.dumps(data)); + return HttpResponse(json.dumps(data)) + +def sshkeys(request, vname): + """ + :param request: + :param vm: + :return: + """ + + instance_keys = [] + userinstances = UserInstance.objects.filter(instance__name=vname) + + for ui in userinstances: + keys = UserSSHKey.objects.filter(user=ui.user) + for k in keys: + instance_keys.append(k.keypublic) + return HttpResponse(json.dumps(instance_keys)) From f959dc7016778af4266e2031030ada0b046ad5fe Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Tue, 6 Jun 2017 12:49:33 +0200 Subject: [PATCH 07/38] settings: TEMPLATE_DIRS is deprecated, using TEMPLATES instead --- webvirtcloud/settings.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/webvirtcloud/settings.py b/webvirtcloud/settings.py index 9e0ff3a..f78a02b 100644 --- a/webvirtcloud/settings.py +++ b/webvirtcloud/settings.py @@ -78,9 +78,13 @@ STATICFILES_DIRS = ( os.path.join(BASE_DIR, "static"), ) -TEMPLATE_DIRS = ( - os.path.join(BASE_DIR, 'templates'), -) +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [ os.path.join(BASE_DIR, 'templates'), ], + 'APP_DIRS': True, + } +] ## WebVirtCloud settings From d715e996b01e695d0e6ac3697a1d18a5f36a6702 Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Tue, 6 Jun 2017 12:51:32 +0200 Subject: [PATCH 08/38] templates/instance.html view redesign. smaller instance details, instance title added --- instances/templates/instance.html | 65 ++++++++++++++----------------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 7de295b..deda273 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -5,44 +5,37 @@ {% include 'pleasewaitdialog.html' %}
- - - - - - -

{{ vname }}

- {% ifequal status 5 %} - {% trans "Off" %} - {% endifequal %} - {% ifequal status 1 %} - {% trans "Active" %} - {% endifequal %} - {% ifequal status 3 %} - {% trans "Suspend" %} - {% endifequal %} - - -
- - - - +
+

+ {{ vname }}{% if title %} ({{ title }}){% endif %} +

+
+
+
+ {% ifequal status 5 %} + {% trans "Off" %} + {% endifequal %} + {% ifequal status 1 %} + {% trans "Active" %} + {% endifequal %} + {% ifequal status 3 %} + {% trans "Suspend" %} + {% endifequal %} + | + {% if cur_vcpu %} + {{ cur_vcpu }} {% trans "Vcpu" %} + {% else %} + {{ vcpu }} {% trans "Vcpu" %} + {% endif %} + | + {{ cur_memory }} {% trans "MB" %} {% trans "Ram" %} + | {% for disk in disks %} -
+ {{ disk.size|filesizeformat }} {% trans "Disk" %} | {% endfor %} - -
- {% if cur_vcpu %} -

{{ cur_vcpu }} {% trans "Vcpu" %}

- {% else %} -

{{ vcpu }} {% trans "Vcpu" %}

- {% endif %} -
-

{{ cur_memory }} {% trans "MB" %} {% trans "Ram" %}

-
-

{{ disk.size|filesizeformat }} {% trans "Disk" %}

-
+ +
+ {% if user_quota_msg %} {{ user_quota_msg|capfirst }} quota reached. {% endif %} From c5f86358becf6e74ee0f5c8591482fc7cd4f8117 Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Tue, 6 Jun 2017 14:49:11 +0200 Subject: [PATCH 09/38] fix STATIC_URL in templates. static urls should be generated by "static" template tag --- console/templates/console-base.html | 11 ++++++----- instances/templates/instance.html | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/console/templates/console-base.html b/console/templates/console-base.html index d0e0e7a..10ef4a3 100644 --- a/console/templates/console-base.html +++ b/console/templates/console-base.html @@ -1,11 +1,12 @@ +{% load staticfiles %} {% load i18n %} - + - - + +