vlans
This commit is contained in:
		
							parent
							
								
									6aad319d53
								
							
						
					
					
						commit
						45d48f7bb0
					
				
					 2 changed files with 71 additions and 11 deletions
				
			
		| 
						 | 
					@ -11,32 +11,56 @@ defaults = {
 | 
				
			||||||
def units(metadata):
 | 
					def units(metadata):
 | 
				
			||||||
    units = {}
 | 
					    units = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for type, network in metadata.get('network').items():
 | 
					    for network_name, network_conf in metadata.get('network').items():
 | 
				
			||||||
        units[f'{type}.network'] = {
 | 
					        interface_type = network_conf.get('type', None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # network
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        units[f'{network_name}.network'] = {
 | 
				
			||||||
            'Match': {
 | 
					            'Match': {
 | 
				
			||||||
                'Name': network['interface'],
 | 
					                'Name': network_name if interface_type == 'vlan' else network_conf['interface'],
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            'Network': {
 | 
					            'Network': {
 | 
				
			||||||
                'DHCP': network.get('dhcp', 'no'),
 | 
					                'DHCP': network_conf.get('dhcp', 'no'),
 | 
				
			||||||
                'IPv6AcceptRA': network.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]:
 | 
					        for i in [4, 6]:
 | 
				
			||||||
            if network.get(f'ipv{i}', None):
 | 
					            if network_conf.get(f'ipv{i}', None):
 | 
				
			||||||
                units[f'{type}.network'].update({
 | 
					                units[f'{network_name}.network'].update({
 | 
				
			||||||
                    f'Address#ipv{i}': {
 | 
					                    f'Address#ipv{i}': {
 | 
				
			||||||
                        'Address': network[f'ipv{i}'],
 | 
					                        'Address': network_conf[f'ipv{i}'],
 | 
				
			||||||
                    },
 | 
					                    },
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
                if f'gateway{i}' in network:
 | 
					                if f'gateway{i}' in network_conf:
 | 
				
			||||||
                    units[f'{type}.network'].update({
 | 
					                    units[f'{network_name}.network'].update({
 | 
				
			||||||
                        f'Route#ipv{i}': {
 | 
					                        f'Route#ipv{i}': {
 | 
				
			||||||
                            'Gateway': network[f'gateway{i}'],
 | 
					                            'Gateway': network_conf[f'gateway{i}'],
 | 
				
			||||||
                            'GatewayOnlink': 'yes',
 | 
					                            '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 {
 | 
					    return {
 | 
				
			||||||
        'systemd': {
 | 
					        'systemd': {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,12 +17,28 @@
 | 
				
			||||||
            'internal': {
 | 
					            'internal': {
 | 
				
			||||||
                'interface': 'eno1',
 | 
					                'interface': 'eno1',
 | 
				
			||||||
                'ipv4': '10.0.0.1/24',
 | 
					                'ipv4': '10.0.0.1/24',
 | 
				
			||||||
 | 
					                'vlans': {'iot', 'internet', 'guest'},
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            'temp': {
 | 
					            'temp': {
 | 
				
			||||||
                'interface': 'enx00e04c220682',
 | 
					                'interface': 'enx00e04c220682',
 | 
				
			||||||
                'ipv4': '10.0.99.126/24',
 | 
					                'ipv4': '10.0.99.126/24',
 | 
				
			||||||
                'gateway4': '10.0.99.1',
 | 
					                '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': {
 | 
					        'kea': {
 | 
				
			||||||
            'Dhcp4': {
 | 
					            'Dhcp4': {
 | 
				
			||||||
| 
						 | 
					@ -40,6 +56,26 @@
 | 
				
			||||||
                            { 'name': 'domain-name-servers', 'data': '10.0.10.2' },
 | 
					                            { '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' },
 | 
				
			||||||
 | 
					                        ],
 | 
				
			||||||
 | 
					                    },
 | 
				
			||||||
                ],
 | 
					                ],
 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue