mirror of https://gitlab.crans.org/nounous/nixos
start poc, config switch
parent
94dfc8c6a4
commit
314a76cbcc
|
|
@ -9,6 +9,7 @@ rec {
|
|||
vr = {id = 27;};
|
||||
aurore = {id = 28;};
|
||||
imprimante = {id = 2756;};
|
||||
vlan-mlag = {id = 4094;};
|
||||
};
|
||||
|
||||
reseaux = {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,89 @@
|
|||
{lib, ...}:
|
||||
let
|
||||
generate_config = switch_name: user_switch: host:
|
||||
let
|
||||
server = host.physiques;
|
||||
in
|
||||
''
|
||||
! File generated by the NixOS configuration
|
||||
hostname ${switch_name}
|
||||
ip domain-name adm.crans.org
|
||||
!
|
||||
spanning-tree mode mstp
|
||||
no spanning-tree vlan ${toString host.vlans.vlan-mlag.id}
|
||||
''
|
||||
+
|
||||
# On définie un user pour pouvoir s'y conncter en ssh
|
||||
''
|
||||
no aaa root
|
||||
username ${user_switch.name} role network-admin secret 5 ${user_switch.hashedPassword}
|
||||
username ${user_switch.name} sshkey ${user_switch.ssh_key}
|
||||
''
|
||||
+
|
||||
# On définie les vlans
|
||||
map host.vlans (name: value:
|
||||
''
|
||||
vlan ${toString value.id}
|
||||
name ${name}
|
||||
''
|
||||
)
|
||||
+
|
||||
# On définie les port et le mlag si le machine est connecte sur les deux switch
|
||||
lib.mapAttrs host.physiques (name: value:
|
||||
if value.switch.${switch_name} then
|
||||
let
|
||||
port_channel = value.switch.${switch_name};
|
||||
in
|
||||
# FIX: certains n'ont pas de Port-Channel car sur un seul switch & port switch
|
||||
# peut etre different donc il faut un autre truc pour determiner le numero du
|
||||
# Port Channel
|
||||
''
|
||||
interface Ethernet${toString value.switch.${switch_name}}
|
||||
mtu 9000
|
||||
channel-group ${toString port_channel} mode active
|
||||
|
||||
interface Port-Channel${toString port_channel}
|
||||
mtu 9000
|
||||
switchport trunk allowed vlan ${lib.concatStringsSep "," (host.physiques.vlans.map (vlan: toString vlan.id)) }
|
||||
switchport mode trunk
|
||||
mlag ${toString port_channel}
|
||||
''
|
||||
else ''''
|
||||
)
|
||||
+
|
||||
# On définie un port channel supplémentaire pour le mlag
|
||||
''
|
||||
interface Port-Channel2000
|
||||
switchport mode trunk
|
||||
switchport trunk group mlag
|
||||
''
|
||||
+
|
||||
# On attribue une ip statique de management au switch
|
||||
''
|
||||
interface Management1
|
||||
ip address 172.16.10.${toString host.physiques.${switch_name}.id}/24
|
||||
''
|
||||
+
|
||||
# Je sais pas, c'etait dans la conf sur les switchs
|
||||
''
|
||||
no ip routing
|
||||
''
|
||||
+
|
||||
# On configure le mlag
|
||||
''
|
||||
mlag configuration
|
||||
domain-id mlag-01
|
||||
heartbeat-interval 10000
|
||||
local-interface Vlan${toString host.vlans.vlan-mlag.id}
|
||||
peer-address 10.0.0.${if switch_name == "arceus" then "2" else "1"}
|
||||
peer-link Port-Channel2000
|
||||
reload-delay 150
|
||||
''
|
||||
+
|
||||
''
|
||||
end
|
||||
''
|
||||
;
|
||||
in
|
||||
{
|
||||
}
|
||||
Loading…
Reference in New Issue