mgmt on vlan
This commit is contained in:
parent
5741324cb7
commit
e7d1abfae3
2 changed files with 45 additions and 6 deletions
|
@ -33,9 +33,12 @@ let module_inst = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
vlans = {
|
vlans = {
|
||||||
"users" = [ { begin = 3045; end = 4094; } ];
|
"users".ids = [ { begin = 3045; end = 4094; } ];
|
||||||
"admin" = [ 3000 ];
|
"admin" = {
|
||||||
"uplink-cri" = [ 223 ];
|
ids = [ 3000 ];
|
||||||
|
management = "10.0.0.2/22";
|
||||||
|
};
|
||||||
|
"uplink-cri".ids = [ 223 ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
module = import ./moduleMaker.nix [
|
module = import ./moduleMaker.nix [
|
||||||
|
|
|
@ -8,8 +8,23 @@ in with lib; {
|
||||||
begin = mkOption { type = types.ints.unsigned; };
|
begin = mkOption { type = types.ints.unsigned; };
|
||||||
end = mkOption { type = types.ints.unsigned; };
|
end = mkOption { type = types.ints.unsigned; };
|
||||||
};
|
};
|
||||||
|
vlan_type.options = {
|
||||||
|
ids = mkOption {
|
||||||
|
type = types.listOf (types.either types.ints.unsigned (types.submodule range_type));
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
management = mkOption {
|
||||||
|
# FIXME : support ipv4 and ipv6, either static or dhcp (with the coffee)
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
description = ''
|
||||||
|
IP address with wich to permit management on this vlan.
|
||||||
|
Only one vlan can set an IP (this module limitation, not switch).
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
in mkOption {
|
in mkOption {
|
||||||
type = types.attrsOf (types.listOf (types.either types.ints.unsigned (types.submodule range_type)));
|
type = types.attrsOf (types.submodule vlan_type);
|
||||||
};
|
};
|
||||||
interfaces = let
|
interfaces = let
|
||||||
template = name: {
|
template = name: {
|
||||||
|
@ -94,16 +109,37 @@ 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 = map id_map cfg.vlans.${vlan}.ids;
|
||||||
|
mgmt_flag = if !builtins.isNull cfg.vlans.${vlan}.management
|
||||||
|
then "<l3-interface>irb.0</l3-interface>" else "";
|
||||||
in ''
|
in ''
|
||||||
<vlan>
|
<vlan>
|
||||||
<name>${vlan}</name>
|
<name>${vlan}</name>
|
||||||
|
${mgmt_flag}
|
||||||
${builtins.concatStringsSep "\n" ids}
|
${builtins.concatStringsSep "\n" ids}
|
||||||
</vlan>'';
|
</vlan>'';
|
||||||
in map vlan_map (builtins.attrNames cfg.vlans);
|
in map vlan_map (builtins.attrNames cfg.vlans);
|
||||||
|
irb_intf = let
|
||||||
|
addresses = map (vlan: vlan.management) (builtins.attrValues cfg.vlans);
|
||||||
|
addr = builtins.foldl' (acc: addr: if !builtins.isNull addr then addr else acc) null addresses;
|
||||||
|
in if !builtins.isNull addr then ''
|
||||||
|
<interface>
|
||||||
|
<name>irb</name>
|
||||||
|
<unit>
|
||||||
|
<name>0</name>
|
||||||
|
<family>
|
||||||
|
<inet>
|
||||||
|
<address><name>${addr}</name></address>
|
||||||
|
</inet>
|
||||||
|
</family>
|
||||||
|
</unit>
|
||||||
|
</interface>
|
||||||
|
''
|
||||||
|
else "";
|
||||||
in [ ''
|
in [ ''
|
||||||
<interfaces>
|
<interfaces>
|
||||||
${builtins.concatStringsSep "\n" interface_xmls}
|
${builtins.concatStringsSep "\n" interface_xmls}
|
||||||
|
${irb_intf}
|
||||||
</interfaces>
|
</interfaces>
|
||||||
<vlans>
|
<vlans>
|
||||||
${builtins.concatStringsSep "\n" vlans}
|
${builtins.concatStringsSep "\n" vlans}
|
||||||
|
|
Loading…
Reference in a new issue