From 0b8cdb8e07a1a028056ae5db1af422ce8000904c Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Thu, 10 Oct 2019 17:55:59 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20:=20Permet=20d'avoir=20plusieurs=20blocs?= =?UTF-8?q?=20de=20switchs=20ordonn=C3=A9s=20sur=20le=20m=C3=AAme=20sous-r?= =?UTF-8?q?=C3=A9seau=20(ex=20/24=20dans=20/16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/serializers.py | 2 +- machines/models.py | 17 +++++++++++------ preferences/models.py | 2 +- topologie/models.py | 20 ++++++++++++++++++-- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index eabcc73a..f925d2bd 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -824,7 +824,7 @@ class SwitchPortSerializer(serializers.ModelSerializer): fields = ('short_name', 'model', 'switchbay', 'ports', 'ipv4', 'ipv6', 'interfaces_subnet', 'interfaces6_subnet', 'automatic_provision', 'rest_enabled', 'web_management_enabled', 'get_radius_key_value', 'get_management_cred_value', - 'list_modules') + 'get_radius_servers', 'list_modules') # LOCAL EMAILS diff --git a/machines/models.py b/machines/models.py index c2012568..97881438 100644 --- a/machines/models.py +++ b/machines/models.py @@ -448,12 +448,17 @@ class IpType(RevMixin, AclMixin, models.Model): @cached_property def ip_net_full_info(self): """Renvoie les infos du network contenant du range""" - return { - 'network': str(self.ip_network.network), - 'netmask': str(self.ip_network.netmask), - 'broadcast': str(self.ip_network.broadcast), - 'netmask_cidr': str(self.ip_network.prefixlen), - } + if self.ip_network: + return { + 'network': str(self.ip_network.network), + 'netmask': str(self.ip_network.netmask), + 'broadcast': str(self.ip_network.broadcast), + 'netmask_cidr': str(self.ip_network.prefixlen), + 'vlan': str(self.vlan), + 'vlan_id': self.vlan.vlan_id + } + else: + return None @cached_property def complete_prefixv6(self): diff --git a/preferences/models.py b/preferences/models.py index f3c8fd7b..e52998cd 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -294,7 +294,7 @@ class OptionalTopologie(AclMixin, PreferencesModel): subnet = None subnet6 = None if self.switchs_ip_type: - subnet = self.switchs_ip_type.ip_set_full_info + subnet = self.switchs_ip_type.ip_net_full_info or self.switchs_ip_type.ip_set_full_info[0] subnet6 = self.switchs_ip_type.ip6_set_full_info return {'ntp_servers': return_ips_dict(ntp_servers), 'log_servers': return_ips_dict(log_servers), 'radius_servers': return_ips_dict(radius_servers), 'dhcp_servers': return_ips_dict(dhcp_servers), 'dns_recursive_servers': return_ips_dict(dns_recursive_servers), 'subnet': subnet, 'subnet6': subnet6} diff --git a/topologie/models.py b/topologie/models.py index c942c93b..0ed4b9dd 100644 --- a/topologie/models.py +++ b/topologie/models.py @@ -55,7 +55,13 @@ from preferences.models import ( RadiusKey, SwitchManagementCred ) -from machines.models import Machine, regen +from machines.models import ( + Machine, + regen, + Role, + MachineType, + Ipv6List +) from re2o.mixins import AclMixin, RevMixin @@ -321,6 +327,16 @@ class Switch(AclMixin, Machine): else: return None + @cached_property + def get_radius_servers_objects(self): + return Role.all_interfaces_for_roletype("radius-server").filter(machine_type__in=MachineType.objects.filter(interface__in=self.interface_set.all())) + + @cached_property + def get_radius_servers(self): + def return_ips_dict(interfaces): + return {'ipv4' : [str(interface.ipv4) for interface in interfaces], 'ipv6' : Ipv6List.objects.filter(interface__in=interfaces).values_list('ipv6', flat=True)} + return return_ips_dict(self.get_radius_servers_objects) + @cached_property def get_management_cred(self): """Retourne l'objet des creds de managament de ce switch""" @@ -362,7 +378,7 @@ class Switch(AclMixin, Machine): @cached_property def interfaces_subnet(self): """Return dict ip:subnet for all ip of the switch""" - return dict((str(interface.ipv4), interface.machine_type.ip_type.ip_set_full_info) for interface in self.interface_set.all()) + return dict((str(interface.ipv4), interface.machine_type.ip_type.ip_net_full_info or interface.machine_type.ip_type.ip_set_full_info[0]) for interface in self.interface_set.all()) @cached_property def interfaces6_subnet(self):