diff options
Diffstat (limited to 'site_config.py')
| -rw-r--r-- | site_config.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/site_config.py b/site_config.py new file mode 100644 index 0000000..81185bf --- /dev/null +++ b/site_config.py @@ -0,0 +1,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') |
