From 317c2a85ae70a7e08c9d77c568369d4d0c892d18 Mon Sep 17 00:00:00 2001 From: Jan Krcmar Date: Wed, 23 Mar 2016 09:00:42 +0100 Subject: [PATCH] user can now clone instances, admin can specify user quotas (instances,cpus,memory) user can only select predefined instance names, mac and disk names are selected automatically --- accounts/migrations/0004_userattributes.py | 26 +++++ ...0005_userattributes_can_clone_instances.py | 19 ++++ accounts/models.py | 10 ++ accounts/templates/accounts.html | 24 +++++ accounts/views.py | 20 +++- instances/templates/instance.html | 100 ++++++++++++------ instances/views.py | 72 ++++++++++--- vrtManager/instance.py | 3 +- webvirtcloud/settings.py | 1 + 9 files changed, 221 insertions(+), 54 deletions(-) create mode 100644 accounts/migrations/0004_userattributes.py create mode 100644 accounts/migrations/0005_userattributes_can_clone_instances.py diff --git a/accounts/migrations/0004_userattributes.py b/accounts/migrations/0004_userattributes.py new file mode 100644 index 0000000..fb32539 --- /dev/null +++ b/accounts/migrations/0004_userattributes.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +from django.conf import settings + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('accounts', '0003_usersshkey'), + ] + + operations = [ + migrations.CreateModel( + name='UserAttributes', + fields=[ + ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), + ('max_instances', models.IntegerField(default=0)), + ('max_cpus', models.IntegerField(default=0)), + ('max_memory', models.IntegerField(default=0)), + ('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/accounts/migrations/0005_userattributes_can_clone_instances.py b/accounts/migrations/0005_userattributes_can_clone_instances.py new file mode 100644 index 0000000..4539657 --- /dev/null +++ b/accounts/migrations/0005_userattributes_can_clone_instances.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0004_userattributes'), + ] + + operations = [ + migrations.AddField( + model_name='userattributes', + name='can_clone_instances', + field=models.BooleanField(default=False), + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 15cedee..16f5f6e 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -20,3 +20,13 @@ class UserSSHKey(models.Model): def __unicode__(self): return self.keyname + +class UserAttributes(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + can_clone_instances = models.BooleanField(default=False) + max_instances = models.IntegerField(default=0) + max_cpus = models.IntegerField(default=0) + max_memory = models.IntegerField(default=0) + + def __unicode__(self): + return self.user.username diff --git a/accounts/templates/accounts.html b/accounts/templates/accounts.html index cc03668..41d5448 100644 --- a/accounts/templates/accounts.html +++ b/accounts/templates/accounts.html @@ -83,6 +83,30 @@ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ {% endif %} + {% if request.user.is_superuser or request.user.userattributes.can_clone_instances %}

{% trans "Create a clone" %}

{% csrf_token %}
+ {% if request.user.is_superuser %} + {% else %} + + {% endif %}
-

{% trans "Network devices" %}

- {% for network in networks %} -
- -
- -
-
- - -
-
- {% endfor %} -

{% trans "Storage devices" %}

- {% for disk in clone_disks %} -
- -
- -
- {% ifequal disk.format 'qcow2' %} - -
- + {% if request.user.is_superuser %} +

{% trans "Network devices" %}

+ {% for network in networks %} +
+ +
+
- {% endifequal %} -
- {% endfor %} +
+ + +
+
+ {% endfor %} + {% else %} + {% for network in networks %} + + {% endfor %} + {% endif %} + {% if request.user.is_superuser %} +

{% trans "Storage devices" %}

+ {% for disk in clone_disks %} +
+ +
+ +
+ {% ifequal disk.format 'qcow2' %} + +
+ +
+ {% endifequal %} +
+ {% endfor %} + {% else %} + {% for disk in clone_disks %} + + {% endfor %} + {% endif %}
@@ -749,6 +775,8 @@
+ {% endif %} + {% if request.user.is_superuser %}

{% trans "For migration both host servers must have equal settings and OS type" %}

{% csrf_token %} @@ -986,8 +1014,8 @@ }