pkgs/switches/*: don't configure null vlans

This commit is contained in:
Astro 2022-01-19 17:18:00 +01:00
parent b75633566d
commit 7b80560aed
4 changed files with 101 additions and 76 deletions

View File

@ -54,23 +54,27 @@ with lib;
builtins.split "/" netConfig.subnet4 builtins.split "/" netConfig.subnet4
) 2; ) 2;
netmask = self.lib.netmasks.${prefixLength}; netmask = self.lib.netmasks.${prefixLength};
in '' in
send "vlan ${vlan}\r" if netConfig.vlan != null
expect -- "-vlan${vlan}]" then ''
send "name ${net}\r" send "vlan ${vlan}\r"
expect -- "-vlan${vlan}]" expect -- "-vlan${vlan}]"
${optionalString (net == "mgmt") '' send "name ${net}\r"
# Actually only used for mgmt_vlan, switches are not routers expect -- "-vlan${vlan}]"
send "interface Vlan-interface ${vlan}\r" ${optionalString (net == "mgmt") ''
expect "]" # Actually only used for mgmt_vlan, switches are not routers
${optionalString (hosts4 ? ${hostName}) '' send "interface Vlan-interface ${vlan}\r"
send "ip address ${hostAddr4} ${netmask}\r"
expect "]" expect "]"
${optionalString (hosts4 ? ${hostName}) ''
send "ip address ${hostAddr4} ${netmask}\r"
expect "]"
''}
''} ''}
''} send "quit\r"
send "quit\r" expect "${hostName}]"
expect "${hostName}]" ''
'') (sortNetsByVlan (builtins.attrNames config.site.net)) else ""
) (sortNetsByVlan (builtins.attrNames config.site.net))
} }
${concatMapStrings (name: ${concatMapStrings (name:

View File

@ -37,7 +37,7 @@ with lib;
send "logging facility local6\r" send "logging facility local6\r"
expect "(config)# " expect "(config)# "
# todo ntp # TODO ntp
# timesync sntp # timesync sntp
# ip timep manual {#ntp#} interval 10 # ip timep manual {#ntp#} interval 10
@ -51,38 +51,42 @@ with lib;
builtins.split "/" netConfig.subnet4 builtins.split "/" netConfig.subnet4
) 2; ) 2;
netmask = self.lib.netmasks.${prefixLength}; netmask = self.lib.netmasks.${prefixLength};
in '' in
send "vlan ${vlan}\r" if netConfig.vlan != null
expect "(vlan-${vlan})#"
send "name ${net}\r"
expect "(vlan-${vlan})#"
send "jumbo\r"
expect "(vlan-${vlan})#"
${optionalString (hosts4 ? ${hostName}) ''
# Actually only used for mgmt_vlan, switches are not routers
send "ip address ${hostAddr4} ${netmask}\r"
expect "(vlan-${vlan})#"
''}
send "exit\r"
expect "(config)# "
${if net == "mgmt"
then '' then ''
send "management-vlan ${vlan}\r" send "vlan ${vlan}\r"
expect "(vlan-${vlan})#"
send "name ${net}\r"
expect "(vlan-${vlan})#"
send "jumbo\r"
expect "(vlan-${vlan})#"
${optionalString (hosts4 ? ${hostName}) ''
# Actually only used for mgmt_vlan, switches are not routers
send "ip address ${hostAddr4} ${netmask}\r"
expect "(vlan-${vlan})#"
''}
send "exit\r"
expect "(config)# " expect "(config)# "
'' else ''
# If not mgmt, reset all VLAN mappings ${if net == "mgmt"
send "no vlan ${vlan} tagged all\r" then ''
expect "(config)# " send "management-vlan ${vlan}\r"
send "no vlan ${vlan} untagged all\r" expect "(config)# "
expect "(config)# " '' else ''
''} # If not mgmt, reset all VLAN mappings
'') (sortNetsByVlan (builtins.attrNames config.site.net)) send "no vlan ${vlan} tagged all\r"
} expect "(config)# "
send "no vlan ${vlan} untagged all\r"
expect "(config)# "
''}
''
else ""
) (sortNetsByVlan (builtins.attrNames config.site.net))
}
${concatMapStrings (name: ${concatMapStrings (name:
let let

View File

@ -60,26 +60,29 @@ with lib;
builtins.split "/" netConfig.subnet4 builtins.split "/" netConfig.subnet4
) 2; ) 2;
netmask = self.lib.netmasks.${prefixLength}; netmask = self.lib.netmasks.${prefixLength};
in '' in
${optionalString (net != "mgmt") '' if netConfig.vlan != null
send "vlan ${vlan}\r" then ''
expect "(config-vlan)#" ${optionalString (net != "mgmt") ''
send "name \"${net}\"\r" send "vlan ${vlan}\r"
expect "(config-vlan)#" expect "(config-vlan)#"
send "name \"${net}\"\r"
expect "(config-vlan)#"
send "exit\r"
expect "(config)#"
''}
send "interface vlan ${vlan}\r"
expect "(config-if)#"
${optionalString (hosts4 ? ${hostName}) ''
# Actually only used for mgmt_vlan, switches are not routers
send "ip address ${hostAddr4} ${netmask}\r"
expect "(config-if)#"
''}
send "exit\r" send "exit\r"
expect "(config)#" expect "(config)#"
''} ''
else ""
send "interface vlan ${vlan}\r"
expect "(config-if)#"
${optionalString (hosts4 ? ${hostName}) ''
# Actually only used for mgmt_vlan, switches are not routers
send "ip address ${hostAddr4} ${netmask}\r"
expect "(config-if)#"
''}
send "exit\r"
expect "(config)#"
''
) (sortNetsByVlan (builtins.attrNames config.site.net))} ) (sortNetsByVlan (builtins.attrNames config.site.net))}
${concatMapStrings (name: ${concatMapStrings (name:

View File

@ -33,21 +33,35 @@ with lib;
send "vlan database\r" send "vlan database\r"
expect "(config-vlan)# " expect "(config-vlan)# "
${concatMapStrings (net: '' ${concatMapStrings (net:
send "vlan ${toString config.site.net.${net}.vlan}\r" let
expect "(config-vlan)#" netConfig = config.site.net.${net};
'') (sortNetsByVlan (builtins.attrNames config.site.net))} in
if netConfig.vlan != null
then ''
send "vlan ${toString netConfig.vlan}\r"
expect "(config-vlan)#"
''
else ""
) (sortNetsByVlan (builtins.attrNames config.site.net))}
send "exit\r" send "exit\r"
expect "(config)#" expect "(config)#"
${concatMapStrings (net: '' ${concatMapStrings (net:
send "interface vlan ${toString config.site.net.${net}.vlan}\r" let
expect "(config-if)#" netConfig = config.site.net.${net};
send "name ${net}\r" in
expect "(config-if)#" if netConfig.vlan != null
send "exit\r" then ''
expect "(config)#" send "interface vlan ${toString config.site.net.${net}.vlan}\r"
'') (sortNetsByVlan (builtins.attrNames config.site.net))} expect "(config-if)#"
send "name ${net}\r"
expect "(config-if)#"
send "exit\r"
expect "(config)#"
''
else ""
) (sortNetsByVlan (builtins.attrNames config.site.net))}
${concatMapStrings (name: ${concatMapStrings (name:
let let