comparison net.py @ 35:51c2f861764f

refactor
author drewp@bigasterisk.com
date Sat, 15 Jan 2022 15:41:01 -0800
parents d4fb38f13c79
children dc2100504c45
comparison
equal deleted inserted replaced
34:d4fb38f13c79 35:51c2f861764f
1 from pyinfra import host 1 from pyinfra import host
2 from pyinfra.operations import apt, files, server, systemd 2 from pyinfra.operations import apt, files, server, systemd
3 3
4 is_wifi = host.name in ['frontdoor', 'living', 'plus'] 4 is_wifi = host.name in ['frontdoor', 'living', 'plus']
5 prime_public_addr = '162.243.138.136'
6 prime_gateway = '162.243.138.1'
5 7
6 if host.name in [ 8
7 'garage', 9 def cleanup():
8 'dash', 10 # past attempts
9 'slash',
10 'frontbed',
11 'prime',
12 ]:
13 # previous version
14 files.file(path='/etc/netplan/99-pyinfra-written.yaml', present=False) 11 files.file(path='/etc/netplan/99-pyinfra-written.yaml', present=False)
15 12
16 for search_dir in [ 13 for search_dir in [
17 # search path per `man systemd.network`: 14 # search path per `man systemd.network`:
18 # /lib/systemd/network # These OS files are ok. 15 # /lib/systemd/network # These OS files are ok.
24 src="files/empty_dir/", 21 src="files/empty_dir/",
25 dest=search_dir, 22 dest=search_dir,
26 delete=True, 23 delete=True,
27 ) 24 )
28 25
26 apt.packages(packages=['network-manager'], present=False)
27
28
29 if host.name in [
30 'garage',
31 'dash',
32 'slash',
33 'frontbed',
34 'prime',
35 ]:
36 cleanup()
37
29 addr = host.host_data['addr'] 38 addr = host.host_data['addr']
30 if addr.startswith('10.'): 39 if addr.startswith('10.'):
31 net = addr[:4] 40 net = addr[:4]
32 gateway = net + '.0.1' 41 gateway = net + '.0.1'
33 dns = gateway 42 dns = gateway
34 elif addr == '162.243.138.136': 43 elif addr == prime_public_addr:
35 gateway = '162.243.138.1' 44 gateway = prime_gateway
36 dns = '10.5.0.1 8.8.8.8 8.8.4.4' 45 dns = '10.5.0.1 8.8.8.8 8.8.4.4'
37 else: 46 else:
38 raise ValueError(addr) 47 raise ValueError(addr)
39 48
40 if is_wifi: 49 if is_wifi: