Commit cbdce68f by Máhonfai Bálint

Also check group limits when creating VMs

parent f2d34c8e
...@@ -1035,8 +1035,10 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView): ...@@ -1035,8 +1035,10 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
except ValueError: except ValueError:
messages.error(self.request, _("Error during filtering.")) messages.error(self.request, _("Error during filtering."))
return queryset.prefetch_related("owner", "node", "owner__profile", "lease", return queryset.prefetch_related(
"interface_set", "interface_set__host", "template").distinct() "owner", "node", "owner__profile", "lease",
"interface_set", "interface_set__host", "template"
).distinct()
class VmCreate(LoginRequiredMixin, TemplateView): class VmCreate(LoginRequiredMixin, TemplateView):
...@@ -1170,8 +1172,20 @@ class VmCreate(LoginRequiredMixin, TemplateView): ...@@ -1170,8 +1172,20 @@ class VmCreate(LoginRequiredMixin, TemplateView):
# limit chekcs # limit chekcs
try: try:
instance_limit = user.profile.instance_limit instance_limits = [user.profile.instance_limit]
template_instance_limit = user.profile.template_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: except Exception as e:
logger.debug('No profile or instance limit: %s', e) logger.debug('No profile or instance limit: %s', e)
else: 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