Commit c53db327 by Szeberényi Imre

Merge branch 'group_instance_limits' into 'master'

Group instance limits

See merge request !421
parents 9413d8af 133e6649
Pipeline #1389 failed with stage
in 0 seconds
......@@ -271,6 +271,8 @@ class GroupProfileUpdateForm(NoFormTagMixin, forms.ModelForm):
if not new_groups:
self.fields['org_id'].widget = HiddenInput()
self.fields['disk_quota'].widget = HiddenInput()
self.fields['instance_limit'].widget = HiddenInput()
self.fields['template_instance_limit'].widget = HiddenInput()
self.fields['description'].widget = forms.Textarea(attrs={'rows': 3})
@property
......@@ -288,7 +290,8 @@ class GroupProfileUpdateForm(NoFormTagMixin, forms.ModelForm):
class Meta:
model = GroupProfile
fields = ('description', 'org_id', 'disk_quota')
fields = ('description', 'org_id', 'disk_quota',
'instance_limit', 'template_instance_limit')
class HostForm(NoFormTagMixin, forms.ModelForm):
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.25 on 2021-02-01 17:30
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dashboard', '0008_profile_template_instance_limit'),
]
operations = [
migrations.AddField(
model_name='groupprofile',
name='instance_limit',
field=models.IntegerField(default=5),
),
migrations.AddField(
model_name='groupprofile',
name='template_instance_limit',
field=models.IntegerField(default=1),
),
]
......@@ -293,6 +293,8 @@ class GroupProfile(AclBase):
org_id = CharField(
unique=True, blank=True, null=True, max_length=64,
help_text=_('Unique identifier of the group at the organization.'))
instance_limit = IntegerField(default=5)
template_instance_limit = IntegerField(default=1)
description = TextField(blank=True)
disk_quota = FileSizeField(
verbose_name=_('disk quota'),
......
......@@ -1035,8 +1035,10 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
except ValueError:
messages.error(self.request, _("Error during filtering."))
return queryset.prefetch_related("owner", "node", "owner__profile", "lease",
"interface_set", "interface_set__host", "template").distinct()
return queryset.prefetch_related(
"owner", "node", "owner__profile", "lease",
"interface_set", "interface_set__host", "template"
).distinct()
class VmCreate(LoginRequiredMixin, TemplateView):
......@@ -1170,8 +1172,20 @@ class VmCreate(LoginRequiredMixin, TemplateView):
# limit chekcs
try:
instance_limit = user.profile.instance_limit
template_instance_limit = user.profile.template_instance_limit
instance_limits = [user.profile.instance_limit]
instance_limits += [
group.profile.instance_limit
for group in user.groups.all()
]
template_instance_limits = [user.profile.template_instance_limit]
template_instance_limits += [
group.profile.template_instance_limit
for group in user.groups.all()
]
instance_limit = max(instance_limits)
template_instance_limit = max(template_instance_limits)
except Exception as e:
logger.debug('No profile or instance limit: %s', e)
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment