making it work

strange behaviors to explore, and deployement shell script todo
This commit is contained in:
catvayor 2024-04-05 19:40:35 +02:00
parent e7d1abfae3
commit be2534386a
2 changed files with 23 additions and 7 deletions

View file

@ -35,7 +35,7 @@ let module_inst = {
vlans = { vlans = {
"users".ids = [ { begin = 3045; end = 4094; } ]; "users".ids = [ { begin = 3045; end = 4094; } ];
"admin" = { "admin" = {
ids = [ 3000 ]; ids = 3000;
management = "10.0.0.2/22"; management = "10.0.0.2/22";
}; };
"uplink-cri".ids = [ 223 ]; "uplink-cri".ids = [ 223 ];

View file

@ -10,7 +10,9 @@ in with lib; {
}; };
vlan_type.options = { vlan_type.options = {
ids = mkOption { ids = mkOption {
type = types.listOf (types.either types.ints.unsigned (types.submodule range_type)); type = types.either
types.ints.unsigned
(types.listOf (types.either types.ints.unsigned (types.submodule range_type)));
default = [ ]; default = [ ];
}; };
management = mkOption { management = mkOption {
@ -65,7 +67,7 @@ in with lib; {
mgmt_fam = if !builtins.isNull cfg.interfaces.${name}.management then '' mgmt_fam = if !builtins.isNull cfg.interfaces.${name}.management then ''
<inet> <inet>
<address> <address>
${cfg.interfaces.${name}.management} <name>${cfg.interfaces.${name}.management}</name>
</address> </address>
</inet>'' else ""; </inet>'' else "";
members = map (vlan: "<members>${builtins.toString vlan}</members>") cfg.interfaces.${name}.vlans; members = map (vlan: "<members>${builtins.toString vlan}</members>") cfg.interfaces.${name}.vlans;
@ -73,6 +75,7 @@ in with lib; {
<ethernet-switching> <ethernet-switching>
<interface-mode>${cfg.interfaces.${name}.interface-mode}</interface-mode> <interface-mode>${cfg.interfaces.${name}.interface-mode}</interface-mode>
<vlan>${builtins.concatStringsSep "" members}</vlan> <vlan>${builtins.concatStringsSep "" members}</vlan>
<storm-control><profile-name>default</profile-name></storm-control>
</ethernet-switching>''; </ethernet-switching>'';
in '' in ''
<interface> <interface>
@ -85,8 +88,14 @@ in with lib; {
${eth_switch} ${eth_switch}
</family> </family>
</unit> </unit>
</interface>''; </interface>
'';
interface_xmls = map intf_xmlGen interfaces; interface_xmls = map intf_xmlGen interfaces;
rstp_gen = name:
if cfg.interfaces.${name}.enable && !builtins.isNull cfg.interfaces.${name}.interface-mode then
"<interface><name>${name}</name></interface>"
else "";
rstps = map rstp_gen interfaces;
vlan_trust_table = let vlan_trust_table = let
vlan_map = inter: vlan: vlan_map = inter: vlan:
if builtins.isString vlan && cfg.interfaces.${inter}.enable then if builtins.isString vlan && cfg.interfaces.${inter}.enable then
@ -109,7 +118,9 @@ in with lib; {
"${builtins.toString id.begin}-${builtins.toString id.end}"; "${builtins.toString id.begin}-${builtins.toString id.end}";
in ''<vlan-id-list>${list}</vlan-id-list>''; in ''<vlan-id-list>${list}</vlan-id-list>'';
vlan_map = vlan: let vlan_map = vlan: let
ids = map id_map cfg.vlans.${vlan}.ids; ids = if !builtins.isList cfg.vlans.${vlan}.ids then
[ "<vlan-id>${builtins.toString cfg.vlans.${vlan}.ids}</vlan-id>" ]
else map id_map cfg.vlans.${vlan}.ids;
mgmt_flag = if !builtins.isNull cfg.vlans.${vlan}.management mgmt_flag = if !builtins.isNull cfg.vlans.${vlan}.management
then "<l3-interface>irb.0</l3-interface>" else ""; then "<l3-interface>irb.0</l3-interface>" else "";
in '' in ''
@ -137,11 +148,16 @@ in with lib; {
'' ''
else ""; else "";
in [ '' in [ ''
<interfaces> <interfaces operation="replace">
${builtins.concatStringsSep "\n" interface_xmls} ${builtins.concatStringsSep "\n" interface_xmls}
${irb_intf} ${irb_intf}
</interfaces> </interfaces>
<vlans> <protocols>
<rstp operation="replace">
${builtins.concatStringsSep "\n" rstps}
</rstp>
</protocols>
<vlans operation="replace">
${builtins.concatStringsSep "\n" vlans} ${builtins.concatStringsSep "\n" vlans}
</vlans>'' vlan_trust_table </vlans>'' vlan_trust_table
]; ];