Start reverse
This commit is contained in:
parent
16f6bb5eab
commit
4e04cfb8be
1 changed files with 20 additions and 8 deletions
28
main.py
28
main.py
|
@ -26,9 +26,11 @@ template_txt = "{field1} IN TXT {field2}"
|
|||
template_srv = "_{service}._{protocol}.{zone} {ttl} IN SRV {priority} {weight} {port} {target}"
|
||||
template_a = "{hostname} IN A {ipv4}"
|
||||
template_aaaa = "{hostname} IN AAAA {ipv6}"
|
||||
template_cname = "{hostname} IN CNAME {alias}{extension}"
|
||||
template_cname = "{hostname} IN CNAME {alias}"
|
||||
template_ptr = "{target} IN PTR {hostname}"
|
||||
|
||||
template_zone = ("{soa}\n"
|
||||
template_zone = ("$TTL 2D\n"
|
||||
"{soa}\n"
|
||||
"\n"
|
||||
"{originv4}\n"
|
||||
"{originv6}\n"
|
||||
|
@ -47,8 +49,14 @@ template_zone = ("{soa}\n"
|
|||
"\n"
|
||||
"{cname_records}")
|
||||
|
||||
template_reverse = ("$TTL 2D\n"
|
||||
"{soa}\n"
|
||||
"\n"
|
||||
"{ns_records}\n"
|
||||
"\n"
|
||||
"{ptr_records}\n")
|
||||
|
||||
def regen_dns(api_client):
|
||||
def write_dns_files(api_client):
|
||||
for zone in api_client.list_dnszones():
|
||||
zone_name = zone['name'][1:]
|
||||
|
||||
|
@ -101,13 +109,13 @@ def regen_dns(api_client):
|
|||
target=x['target'])
|
||||
for x in zone['srv_records']
|
||||
)
|
||||
|
||||
|
||||
a_records = "\n".join(
|
||||
template_a.format(hostname=x['hostname'],
|
||||
ipv4=x['ipv4'])
|
||||
for x in zone['a_records']
|
||||
)
|
||||
|
||||
|
||||
aaaa_records = "\n".join(
|
||||
template_aaaa.format(hostname=x['hostname'],
|
||||
ipv6=x['ipv6'])
|
||||
|
@ -116,8 +124,7 @@ def regen_dns(api_client):
|
|||
|
||||
cname_records = "\n".join(
|
||||
template_cname.format(hostname=x['hostname'],
|
||||
alias=x['alias'],
|
||||
extension=x['extension'])
|
||||
alias=x['alias']+extension=x['extension'])
|
||||
for x in zone['cname_records']
|
||||
)
|
||||
|
||||
|
@ -135,6 +142,10 @@ def regen_dns(api_client):
|
|||
filename = 'dns.{zone}.zone'.format(zone=zone_name)
|
||||
with open(filename, 'w+') as f:
|
||||
f.write(zone_file_content)
|
||||
|
||||
|
||||
def write_dns_reverse_file(api_client):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
|
@ -146,5 +157,6 @@ for service in api_client.list_servicesregen():
|
|||
# if service['hostname'] == client_hostname and \
|
||||
# service['service_name'] == 'dns' and \
|
||||
# service['need_regen']:
|
||||
regen_dns(api_client)
|
||||
write_dns_zone_file(api_client)
|
||||
write_dns_reverse_file(api_client)
|
||||
# api_client.patch(service['api_url'], data={'need_regen': False})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue