vlans
This commit is contained in:
		
							parent
							
								
									67d5a4bff8
								
							
						
					
					
						commit
						dedbffa107
					
				
					 2 changed files with 71 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -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': {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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' },
 | 
			
		||||
                        ],
 | 
			
		||||
                    },
 | 
			
		||||
                ],
 | 
			
		||||
            },
 | 
			
		||||
        },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue