Commit 31f1acaa by Czémán Arnold

firewall: repair the Vlan's get_new_address() method. Issue: #425

parent f5902b8f
Pipeline #91 passed with stage
in 0 seconds
...@@ -36,6 +36,7 @@ from django.core.validators import MinValueValidator, MaxValueValidator ...@@ -36,6 +36,7 @@ from django.core.validators import MinValueValidator, MaxValueValidator
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
import django.conf import django.conf
from django.db.models.signals import post_save, post_delete from django.db.models.signals import post_save, post_delete
from django.db.models import Q
from celery.exceptions import TimeoutError from celery.exceptions import TimeoutError
from netaddr import IPSet, EUI, IPNetwork, IPAddress, ipv6_full from netaddr import IPSet, EUI, IPNetwork, IPAddress, ipv6_full
...@@ -499,7 +500,12 @@ class Vlan(AclBase, models.Model): ...@@ -499,7 +500,12 @@ class Vlan(AclBase, models.Model):
def get_new_address(self): def get_new_address(self):
hosts = self.host_set hosts = self.host_set
used_v4 = IPSet(hosts.values_list('ipv4', flat=True)) query = Q(shared_ip=False)\
| Q(external_ipv4__isnull=False)\
| Q(vlan=self)
ipv4_hosts = Host.objects.filter(query)
used_v4 = IPSet(ipv4_hosts.values_list('ipv4', flat=True))
used_v6 = IPSet(hosts.exclude(ipv6__isnull=True) used_v6 = IPSet(hosts.exclude(ipv6__isnull=True)
.values_list('ipv6', flat=True)) .values_list('ipv6', flat=True))
......
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