1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/usr/bin/env python3
from dataclasses import dataclass
import logging
import platform
from typing import Optional
import config
logger = logging.getLogger(__name__)
args = config.add_commandline_args(
f'({__file__})',
'Args related to __file__'
)
args.add_argument(
'--site_config_location',
default='AUTO',
const='AUTO',
nargs='?',
choices=('HOUSE', 'CABIN', 'AUTO'),
help='Where are we, HOUSE or CABIN?'
)
@dataclass
class SiteConfig(object):
network: str
network_netmask: str
network_router_ip: str
def get_location():
location = config.config['site_config_location']
if location == 'AUTO':
hostname = platform.node()
if '.house' in hostname:
location = 'HOUSE'
elif '.cabin' in hostname:
location = 'CABIN'
else:
raise Exception(f'Unknown hostname {hostname}, help.')
return location
def get_config():
location = get_location()
if location == 'HOUSE':
return SiteConfig(
network = '10.0.0.0/24',
network_netmask = '255.255.255.0',
network_router_ip = '10.0.0.1',
)
elif location == 'CABIN':
return SiteConfig(
network = '192.168.0.0/24',
network_netmask = '255.255.255.0',
network_router_ip = '192.168.0.1',
)
else:
raise Exception('Unknown site location')
|