From dedbffa107c2008e5e298e8dbc9a02924c8f4e21 Mon Sep 17 00:00:00 2001 From: cronekorkn Date: Mon, 23 Sep 2024 19:25:48 +0200 Subject: [PATCH] vlans --- bundles/network/metadata.py | 46 ++++++++++++++++++++++++++++--------- nodes/home.router.py | 36 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 11 deletions(-) diff --git a/bundles/network/metadata.py b/bundles/network/metadata.py index e9c552f..d9b51e6 100644 --- a/bundles/network/metadata.py +++ b/bundles/network/metadata.py @@ -11,32 +11,56 @@ defaults = { def units(metadata): units = {} - for type, network in metadata.get('network').items(): - units[f'{type}.network'] = { + for network_name, network_conf in metadata.get('network').items(): + interface_type = network_conf.get('type', None) + + # network + + units[f'{network_name}.network'] = { 'Match': { - 'Name': network['interface'], + 'Name': network_name if interface_type == 'vlan' else network_conf['interface'], }, 'Network': { - 'DHCP': network.get('dhcp', 'no'), - 'IPv6AcceptRA': network.get('dhcp', 'no'), + 'DHCP': network_conf.get('dhcp', 'no'), + 'IPv6AcceptRA': network_conf.get('dhcp', 'no'), + 'VLAN': set(network_conf.get('vlans', set())) } } + # type + + if interface_type: + units[f'{network_name}.network']['Match']['Type'] = interface_type + + # ips + for i in [4, 6]: - if network.get(f'ipv{i}', None): - units[f'{type}.network'].update({ + if network_conf.get(f'ipv{i}', None): + units[f'{network_name}.network'].update({ f'Address#ipv{i}': { - 'Address': network[f'ipv{i}'], + 'Address': network_conf[f'ipv{i}'], }, }) - if f'gateway{i}' in network: - units[f'{type}.network'].update({ + if f'gateway{i}' in network_conf: + units[f'{network_name}.network'].update({ f'Route#ipv{i}': { - 'Gateway': network[f'gateway{i}'], + 'Gateway': network_conf[f'gateway{i}'], 'GatewayOnlink': 'yes', } }) + # as vlan + + if interface_type == 'vlan': + units[f"{network_name}.netdev"] = { + 'NetDev': { + 'Name': network_name, + 'Kind': 'vlan', + }, + 'VLAN': { + 'Id': network_conf['id'], + } + } return { 'systemd': { diff --git a/nodes/home.router.py b/nodes/home.router.py index 8a3e22a..ae5fbcd 100644 --- a/nodes/home.router.py +++ b/nodes/home.router.py @@ -17,12 +17,28 @@ 'internal': { 'interface': 'eno1', 'ipv4': '10.0.0.1/24', + 'vlans': {'iot', 'internet', 'guest'}, }, 'temp': { 'interface': 'enx00e04c220682', 'ipv4': '10.0.99.126/24', 'gateway4': '10.0.99.1', }, + 'iot': { + 'type': 'vlan', + 'id': 2, + 'ipv4': '10.0.2.1/24', + }, + 'internet': { + 'type': 'vlan', + 'id': 3, + 'ipv4': '10.0.3.1/24', + }, + 'guest': { + 'type': 'vlan', + 'id': 9, + 'ipv4': '10.0.9.1/24', + }, }, 'kea': { 'Dhcp4': { @@ -40,6 +56,26 @@ { 'name': 'domain-name-servers', 'data': '10.0.10.2' }, ], }, + { + 'subnet': '10.0.2.0/24', + 'pools': [ + { 'pool': '10.0.2.100 - 10.0.2.200' }, + ], + 'option-data': [ + { 'name': 'routers', 'data': '10.0.2.1' }, + { 'name': 'domain-name-servers', 'data': '10.0.10.2' }, + ], + }, + { + 'subnet': '10.0.9.0/24', + 'pools': [ + { 'pool': '10.0.9.100 - 10.0.9.200' }, + ], + 'option-data': [ + { 'name': 'routers', 'data': '10.0.9.1' }, + { 'name': 'domain-name-servers', 'data': '10.0.10.2' }, + ], + }, ], }, },