4 db_config_path
= '/etc/0tdns/db_connection_config.yml'
6 def start_db_connection():
7 config
= yaml
.safe_load(open(db_config_path
, 'r'))
8 connection
= psycopg2
.connect(user
=config
['user'], password
=config
['password'],
9 host
=config
['host'], port
=config
['port'],
10 database
=config
['database'])
11 # we might later decide that each user of start_db_connection()
12 # should set it themselves - but for now, set it here
13 connection
.autocommit
= True
16 # we'll use it for setting SNAT
17 # https://stackoverflow.com/questions/166506/finding-local-ip-addresses-using-pythons-stdlib
18 def get_default_host_address(remote_address
):
20 config
= yaml
.safe_load(open(db_config_path
, 'r'))
21 s
= socket
.socket(socket
.AF_INET
, socket
.SOCK_DGRAM
)
22 s
.connect((config
['database'], 80))
23 hostaddr
= s
.getsockname()[0]