8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 07:02:26 +00:00

Merge branch 'multi_iptypes_switchs' into 'dev'

Multi iptypes switchs

See merge request federez/re2o!459
This commit is contained in:
klafyvel 2019-10-10 19:25:42 +02:00
commit 59ce4829aa
4 changed files with 31 additions and 10 deletions

View file

@ -824,7 +824,7 @@ class SwitchPortSerializer(serializers.ModelSerializer):
fields = ('short_name', 'model', 'switchbay', 'ports', 'ipv4', 'ipv6', fields = ('short_name', 'model', 'switchbay', 'ports', 'ipv4', 'ipv6',
'interfaces_subnet', 'interfaces6_subnet', 'automatic_provision', 'rest_enabled', 'interfaces_subnet', 'interfaces6_subnet', 'automatic_provision', 'rest_enabled',
'web_management_enabled', 'get_radius_key_value', 'get_management_cred_value', 'web_management_enabled', 'get_radius_key_value', 'get_management_cred_value',
'list_modules') 'get_radius_servers', 'list_modules')
# LOCAL EMAILS # LOCAL EMAILS

View file

@ -448,12 +448,17 @@ class IpType(RevMixin, AclMixin, models.Model):
@cached_property @cached_property
def ip_net_full_info(self): def ip_net_full_info(self):
"""Renvoie les infos du network contenant du range""" """Renvoie les infos du network contenant du range"""
return { if self.ip_network:
'network': str(self.ip_network.network), return {
'netmask': str(self.ip_network.netmask), 'network': str(self.ip_network.network),
'broadcast': str(self.ip_network.broadcast), 'netmask': str(self.ip_network.netmask),
'netmask_cidr': str(self.ip_network.prefixlen), '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 @cached_property
def complete_prefixv6(self): def complete_prefixv6(self):

View file

@ -294,7 +294,7 @@ class OptionalTopologie(AclMixin, PreferencesModel):
subnet = None subnet = None
subnet6 = None subnet6 = None
if self.switchs_ip_type: 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 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} 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}

View file

@ -55,7 +55,13 @@ from preferences.models import (
RadiusKey, RadiusKey,
SwitchManagementCred SwitchManagementCred
) )
from machines.models import Machine, regen from machines.models import (
Machine,
regen,
Role,
MachineType,
Ipv6List
)
from re2o.mixins import AclMixin, RevMixin from re2o.mixins import AclMixin, RevMixin
@ -321,6 +327,16 @@ class Switch(AclMixin, Machine):
else: else:
return None 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 @cached_property
def get_management_cred(self): def get_management_cred(self):
"""Retourne l'objet des creds de managament de ce switch""" """Retourne l'objet des creds de managament de ce switch"""
@ -362,7 +378,7 @@ class Switch(AclMixin, Machine):
@cached_property @cached_property
def interfaces_subnet(self): def interfaces_subnet(self):
"""Return dict ip:subnet for all ip of the switch""" """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 @cached_property
def interfaces6_subnet(self): def interfaces6_subnet(self):