diff --git a/README.md b/README.md index 503616c..6f40feb 100644 --- a/README.md +++ b/README.md @@ -273,6 +273,25 @@ You need to put cloud public key into authorized keys on the compute node. Simpl sudo -u www-data ssh-copy-id root@compute1 ``` +### Host SMBIOS information is not available + +If you see warning +``` +Unsupported configuration: Host SMBIOS information is not available +``` +Then you need to install `dmidecode` package on your host using your package manager and restart libvirt daemon. + +Debian/Ubuntu like: +``` +$ sudo apt-get install dmidecode +$ sudo service libvirt-bin restart +``` +Arch Linux +``` +$ sudo pacman -S dmidecode +$ systemctl restart libvirtd +``` + ### Cloud-init Currently supports only root ssh authorized keys and hostname. Example configuration of the cloud-init client follows. ``` diff --git a/accounts/migrations/0002_addAdmin.py b/accounts/migrations/0002_addAdmin.py index c0286cf..09a91fc 100644 --- a/accounts/migrations/0002_addAdmin.py +++ b/accounts/migrations/0002_addAdmin.py @@ -6,8 +6,10 @@ from django.db import migrations def add_useradmin(apps, schema_editor): from django.utils import timezone from django.contrib.auth.models import User + from accounts.models import UserAttributes - User.objects.create_superuser('admin', None, 'admin', last_login=timezone.now()) + admin = User.objects.create_superuser('admin', None, 'admin', last_login=timezone.now()) + UserAttributes(user=admin, max_instances=-1, max_cpus=-1, max_memory=-1, max_disk_size=-1).save() class Migration(migrations.Migration): diff --git a/accounts/migrations/0003_permissionset.py b/accounts/migrations/0003_permissionset.py new file mode 100644 index 0000000..d7cf465 --- /dev/null +++ b/accounts/migrations/0003_permissionset.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.12 on 2020-05-27 12:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0002_addAdmin'), + ] + + operations = [ + migrations.CreateModel( + name='PermissionSet', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ], + options={ + 'permissions': (('change_password', 'Can change password'),), + 'managed': False, + 'default_permissions': (), + }, + ), + ] diff --git a/accounts/migrations/0004_apply_change_password.py b/accounts/migrations/0004_apply_change_password.py new file mode 100644 index 0000000..f313b7e --- /dev/null +++ b/accounts/migrations/0004_apply_change_password.py @@ -0,0 +1,25 @@ +from django.db import migrations + + +def apply_change_password(apps, schema_editor): + from django.conf import settings + from django.contrib.auth.models import User, Permission + + if hasattr(settings, 'SHOW_PROFILE_EDIT_PASSWORD'): + if settings.SHOW_PROFILE_EDIT_PASSWORD: + permission = Permission.objects.get(codename='change_password') + users = User.objects.all() + user: User + for user in users: + user.user_permissions.add(permission) + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0003_permissionset'), + ] + + operations = [ + migrations.RunPython(apply_change_password), + ] diff --git a/accounts/migrations/0005_remove_userattributes_can_clone_instances.py b/accounts/migrations/0005_remove_userattributes_can_clone_instances.py new file mode 100644 index 0000000..76e0458 --- /dev/null +++ b/accounts/migrations/0005_remove_userattributes_can_clone_instances.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.12 on 2020-05-28 04:24 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0004_apply_change_password'), + ('instances', '0003_migrate_can_clone_instances'), + ] + + operations = [ + migrations.RemoveField( + model_name='userattributes', + name='can_clone_instances', + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 77cf81a..8484a7e 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -1,39 +1,54 @@ -from django.db.models import Model, BooleanField, IntegerField, CharField -from django.db.models import ForeignKey, OneToOneField -from django.db.models import CASCADE, DO_NOTHING -from django.contrib.auth.models import User from django.conf import settings -from instances.models import Instance +from django.contrib.auth.models import User from django.core.validators import MinValueValidator +from django.db import models +from django.utils.translation import ugettext_lazy as _ + +from instances.models import Instance -class UserInstance(Model): - user = ForeignKey(User, on_delete=CASCADE) - instance = ForeignKey(Instance, on_delete=CASCADE) - is_change = BooleanField(default=False) - is_delete = BooleanField(default=False) - is_vnc = BooleanField(default=False) +class UserInstance(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + instance = models.ForeignKey(Instance, on_delete=models.CASCADE) + is_change = models.BooleanField(default=False) + is_delete = models.BooleanField(default=False) + is_vnc = models.BooleanField(default=False) def __unicode__(self): return self.instance.name -class UserSSHKey(Model): - user = ForeignKey(User, on_delete=DO_NOTHING) - keyname = CharField(max_length=25) - keypublic = CharField(max_length=500) +class UserSSHKey(models.Model): + user = models.ForeignKey(User, on_delete=models.DO_NOTHING) + keyname = models.CharField(max_length=25) + keypublic = models.CharField(max_length=500) def __unicode__(self): return self.keyname -class UserAttributes(Model): - user = OneToOneField(User, on_delete=CASCADE) - can_clone_instances = BooleanField(default=True) - max_instances = IntegerField(default=1, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1), ]) - max_cpus = IntegerField(default=1, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1)]) - max_memory = IntegerField(default=2048, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1)]) - max_disk_size = IntegerField(default=20, help_text="-1 for unlimited. Any integer value", validators=[MinValueValidator(-1)]) +class UserAttributes(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + max_instances = models.IntegerField(default=1, + help_text="-1 for unlimited. Any integer value", + validators=[ + MinValueValidator(-1), + ]) + max_cpus = models.IntegerField( + default=1, + help_text="-1 for unlimited. Any integer value", + validators=[MinValueValidator(-1)], + ) + max_memory = models.IntegerField( + default=2048, + help_text="-1 for unlimited. Any integer value", + validators=[MinValueValidator(-1)], + ) + max_disk_size = models.IntegerField( + default=20, + help_text="-1 for unlimited. Any integer value", + validators=[MinValueValidator(-1)], + ) @staticmethod def create_missing_userattributes(user): @@ -51,7 +66,7 @@ class UserAttributes(Model): instance = Instance.objects.get(name=instance_name) user_instance = UserInstance(user=user, instance=instance) user_instance.save() - + @staticmethod def configure_user(user): UserAttributes.create_missing_userattributes(user) @@ -59,3 +74,14 @@ class UserAttributes(Model): def __unicode__(self): return self.user.username + + +class PermissionSet(models.Model): + """ + Dummy model for holding set of permissions we need to be automatically added by Django + """ + class Meta: + default_permissions = () + permissions = (('change_password', _('Can change password')), ) + + managed = False diff --git a/accounts/templates/accounts-list.html b/accounts/templates/accounts-list.html deleted file mode 100644 index d6630cc..0000000 --- a/accounts/templates/accounts-list.html +++ /dev/null @@ -1,175 +0,0 @@ -{% extends "base.html" %} -{% load i18n %} -{% load staticfiles %} -{% block title %}{% trans "Users" %}{% endblock %} -{% block content %} - -
{% trans "Username" %} | -{% trans "Status" %} | -{% trans "Staff" %} | -{% trans "Superuser" %} | -{% trans "Clone" %} | -
---|---|---|---|---|
- {{ user.username }} - - - - | -- {% if user.is_active %} - {% trans "Active" %} - {% else %} - {% trans "Blocked" %} - {% endif %} - | -{% if user.is_staff %}{% endif %} | -{% if user.is_superuser %}{% endif %} | -{% if user.userattributes.can_clone_instances %}{% endif %} | -
{% trans "Status:" %}
-{% trans "Active" %}
- {% else %} -{% trans "Blocked" %}
- {% endif %} -