Fixed config loading, added Dockerfile
This commit is contained in:
@@ -11,8 +11,8 @@ def get_container_name(container):
|
||||
"""
|
||||
x = container.attrs['Name'][1:]
|
||||
|
||||
if config['hostname_label'] in container.attrs['Config']['Labels']:
|
||||
x = container.attrs['Config']['Labels'][config['hostname_label']]
|
||||
if config['HOSTNAME_LABEL'] in container.attrs['Config']['Labels']:
|
||||
x = container.attrs['Config']['Labels'][config['HOSTNAME_LABEL']]
|
||||
|
||||
x = x.replace("_", "-") # Be compliant with RFC1035
|
||||
return x
|
||||
@@ -28,11 +28,12 @@ def get_container_ip(container):
|
||||
x = container.attrs['NetworkSettings']['IPAddress']
|
||||
|
||||
if next(iter(container.attrs['NetworkSettings']['Networks'])):
|
||||
network_name = next(iter(container.attrs['NetworkSettings']['Networks']))
|
||||
network_name = next(
|
||||
iter(container.attrs['NetworkSettings']['Networks']))
|
||||
x = container.attrs['NetworkSettings']['Networks'][network_name]['IPAddress']
|
||||
|
||||
if config['default_network'] in container.attrs['NetworkSettings']['Networks']:
|
||||
x = container.attrs['NetworkSettings']['Networks'][config['default_network']]
|
||||
if config['DEFAULT_NETWORK'] in container.attrs['NetworkSettings']['Networks']:
|
||||
x = container.attrs['NetworkSettings']['Networks'][config['DEFAULT_NETWORK']]
|
||||
|
||||
return x
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ config = {}
|
||||
|
||||
|
||||
def add_records(records):
|
||||
keyring = dns.tsigkeyring.from_text({config['tsig_name']: config['tsig_key']})
|
||||
keyring = dns.tsigkeyring.from_text(
|
||||
{config['TSIG_NAME']: config['TSIG_KEY']})
|
||||
for hostname, ip in records.items():
|
||||
print("Adding record for " + hostname + "(" + ip + ")")
|
||||
|
||||
@@ -18,18 +19,19 @@ def add_records(records):
|
||||
if isinstance(address, ipaddress.IPv6Address):
|
||||
rrtype = "AAAA"
|
||||
|
||||
update = dns.update.Update(config['domain'], keyring=keyring)
|
||||
update = dns.update.Update(config['DOMAIN'], keyring=keyring)
|
||||
update.add(hostname, 60, rrtype, ip)
|
||||
dns.query.tcp(update, config['nameserver'], timeout=2)
|
||||
dns.query.tcp(update, config['NAMESERVER'], timeout=2)
|
||||
|
||||
|
||||
def delete_records(records):
|
||||
keyring = dns.tsigkeyring.from_text({config['tsig_name']: config['tsig_key']})
|
||||
keyring = dns.tsigkeyring.from_text(
|
||||
{config['TSIG_NAME']: config['TSIG_KEY']})
|
||||
for hostname, ip in records.items():
|
||||
print("Deleting record for " + hostname + "(" + ip + ")")
|
||||
update = dns.update.Update(config['domain'], keyring=keyring)
|
||||
update = dns.update.Update(config['DOMAIN'], keyring=keyring)
|
||||
update.delete(hostname)
|
||||
dns.query.tcp(update, config['nameserver'], timeout=2)
|
||||
dns.query.tcp(update, config['NAMESERVER'], timeout=2)
|
||||
|
||||
|
||||
def init(_config):
|
||||
|
||||
Reference in New Issue
Block a user