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
) 2;
netmask = self.lib.netmasks.${prefixLength};
in ''
send "vlan ${vlan}\r"
expect -- "-vlan${vlan}]"
send "name ${net}\r"
expect -- "-vlan${vlan}]"
${optionalString (net == "mgmt") ''
# Actually only used for mgmt_vlan, switches are not routers
send "interface Vlan-interface ${vlan}\r"
expect "]"
${optionalString (hosts4 ? ${hostName}) ''
send "ip address ${hostAddr4} ${netmask}\r"
in
if netConfig.vlan != null
then ''
send "vlan ${vlan}\r"
expect -- "-vlan${vlan}]"
send "name ${net}\r"
expect -- "-vlan${vlan}]"
${optionalString (net == "mgmt") ''
# Actually only used for mgmt_vlan, switches are not routers
send "interface Vlan-interface ${vlan}\r"
expect "]"
${optionalString (hosts4 ? ${hostName}) ''
send "ip address ${hostAddr4} ${netmask}\r"
expect "]"
''}
''}
''}
send "quit\r"
expect "${hostName}]"
'') (sortNetsByVlan (builtins.attrNames config.site.net))
send "quit\r"
expect "${hostName}]"
''
else ""
) (sortNetsByVlan (builtins.attrNames config.site.net))
}
${concatMapStrings (name:

View File

@ -37,7 +37,7 @@ with lib;
send "logging facility local6\r"
expect "(config)# "
# todo ntp
# TODO ntp
# timesync sntp
# ip timep manual {#ntp#} interval 10
@ -51,38 +51,42 @@ with lib;
builtins.split "/" netConfig.subnet4
) 2;
netmask = self.lib.netmasks.${prefixLength};
in ''
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)# "
${if net == "mgmt"
in
if netConfig.vlan != null
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)# "
'' else ''
# If not mgmt, reset all VLAN mappings
send "no vlan ${vlan} tagged all\r"
expect "(config)# "
send "no vlan ${vlan} untagged all\r"
expect "(config)# "
''}
'') (sortNetsByVlan (builtins.attrNames config.site.net))
}
${if net == "mgmt"
then ''
send "management-vlan ${vlan}\r"
expect "(config)# "
'' else ''
# If not mgmt, reset all VLAN mappings
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:
let

View File

@ -60,26 +60,29 @@ with lib;
builtins.split "/" netConfig.subnet4
) 2;
netmask = self.lib.netmasks.${prefixLength};
in ''
${optionalString (net != "mgmt") ''
send "vlan ${vlan}\r"
expect "(config-vlan)#"
send "name \"${net}\"\r"
expect "(config-vlan)#"
in
if netConfig.vlan != null
then ''
${optionalString (net != "mgmt") ''
send "vlan ${vlan}\r"
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"
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"
expect "(config)#"
''
''
else ""
) (sortNetsByVlan (builtins.attrNames config.site.net))}
${concatMapStrings (name:

View File

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