mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-25 12:53:11 +00:00
Rajoute une acl need_infra sur l'object ip
This commit is contained in:
parent
32217118e1
commit
ea20cede0c
4 changed files with 28 additions and 3 deletions
|
@ -42,7 +42,7 @@ class AddInterfaceForm(EditInterfaceForm):
|
||||||
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
||||||
if not infra:
|
if not infra:
|
||||||
self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
|
self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False))
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)).filter(need_infra=False)
|
||||||
else:
|
else:
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ class BaseEditInterfaceForm(EditInterfaceForm):
|
||||||
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
self.fields['ipv4'].empty_label = "Assignation automatique de l'ipv4"
|
||||||
if not infra:
|
if not infra:
|
||||||
self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
|
self.fields['type'].queryset = MachineType.objects.filter(ip_type=IpType.objects.filter(need_infra=False))
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False))
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True).filter(ip_type=IpType.objects.filter(need_infra=False)).filter(need_infra=False)
|
||||||
else:
|
else:
|
||||||
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
self.fields['ipv4'].queryset = IpList.objects.filter(interface__isnull=True)
|
||||||
|
|
||||||
|
|
19
machines/migrations/0034_iplist_need_infra.py
Normal file
19
machines/migrations/0034_iplist_need_infra.py
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('machines', '0033_extension_need_infra'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='iplist',
|
||||||
|
name='need_infra',
|
||||||
|
field=models.BooleanField(default=False),
|
||||||
|
),
|
||||||
|
]
|
|
@ -124,6 +124,7 @@ class IpList(models.Model):
|
||||||
|
|
||||||
ipv4 = models.GenericIPAddressField(protocol='IPv4', unique=True)
|
ipv4 = models.GenericIPAddressField(protocol='IPv4', unique=True)
|
||||||
ip_type = models.ForeignKey('IpType', on_delete=models.PROTECT)
|
ip_type = models.ForeignKey('IpType', on_delete=models.PROTECT)
|
||||||
|
need_infra = models.BooleanField(default=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.ipv4
|
return self.ipv4
|
||||||
|
|
|
@ -60,7 +60,10 @@ def assign_ips(user):
|
||||||
|
|
||||||
def free_ip(type):
|
def free_ip(type):
|
||||||
""" Renvoie la liste des ip disponibles """
|
""" Renvoie la liste des ip disponibles """
|
||||||
return IpList.objects.filter(interface__isnull=True).filter(ip_type=type)
|
if not type.need_infra:
|
||||||
|
return IpList.objects.filter(interface__isnull=True).filter(ip_type=type).filter(need_infra=False)
|
||||||
|
else:
|
||||||
|
return IpList.objects.filter(interface__isnull=True).filter(ip_type=type)
|
||||||
|
|
||||||
def assign_ipv4(interface):
|
def assign_ipv4(interface):
|
||||||
""" Assigne une ip à l'interface """
|
""" Assigne une ip à l'interface """
|
||||||
|
@ -142,6 +145,8 @@ def edit_interface(request, interfaceid):
|
||||||
new_machine.save()
|
new_machine.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machine_form.changed_data))
|
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in machine_form.changed_data))
|
||||||
|
if free_ip(new_interface.type.ip_type) and not new_interface.ipv4:
|
||||||
|
new_interface = assign_ipv4(new_interface)
|
||||||
with transaction.atomic(), reversion.create_revision():
|
with transaction.atomic(), reversion.create_revision():
|
||||||
new_interface.save()
|
new_interface.save()
|
||||||
reversion.set_user(request.user)
|
reversion.set_user(request.user)
|
||||||
|
|
Loading…
Reference in a new issue