Just skightky tested, does not work

main
Micke Nordin 6 days ago
parent 8d4c9bc470
commit 8119459d2f

@ -45,7 +45,7 @@ def get_config(config_filename: str):
return yaml.safe_load(fh.read()) return yaml.safe_load(fh.read())
def get_openstack_addresses(name: str, cloud: str): def get_openstack_addresses(cloud: str, name: str):
conn = openstack.connect(cloud=cloud) conn = openstack.connect(cloud=cloud)
# List the servers # List the servers
@ -55,7 +55,7 @@ def get_openstack_addresses(name: str, cloud: str):
exit(1) exit(1)
openstack_addresses = [] openstack_addresses = []
for network in server.addresses: for network in server.addresses:
for address in network: for address in server.addresses[network]:
openstack_addresses.append(address) openstack_addresses.append(address)
return openstack_addresses return openstack_addresses
@ -235,32 +235,43 @@ def run_openstack_sync(cloud: str, name: str, zone: str, headers: dict,
baseurl: str, jsonout: bool): baseurl: str, jsonout: bool):
url = setup_url( url = setup_url(
baseurl, baseurl,
zone=zone, None, # arguments,
name=name, None, # data,
name,
None, # rtype,
None, # ttl,
zone,
) )
current_records = run_list(url, jsonout=True, headers=headers, ret=True) current_records = run_list(url, jsonout=True, headers=headers, ret=True)
openstack_addresses = get_openstack_addresses(cloud, name) openstack_addresses = get_openstack_addresses(cloud, name)
if current_records is None: if current_records["Code"] == 404:
for address in openstack_addresses: for address in openstack_addresses:
rtype = None rtype = None
if address.version == 4: if address["version"] == 4:
rtype = "A" rtype = "A"
elif address.version == 6: elif address["version"] == 6:
rtype = "AAAA" rtype = "AAAA"
if rtype: if rtype:
url = setup_url(baseurl, url = setup_url(
zone=zone, baseurl,
name=name, None, # arguments,
rtype=rtype, address["addr"], # data,
data=address.addr) name,
rtype,
None, # ttl,
zone,
)
run_add(url, jsonout, headers) run_add(url, jsonout, headers)
else: else:
previpv4, previpv6, curripv4, curripv6 = False previpv4 = False
previpv6 = False
curripv4 = False
curripv6 = False
for record in current_records: for record in current_records:
if record["type"] == "A": if record.type == "A":
previpv4 = record["data"] previpv4 = record.data
elif record["type"] == "AAAA": elif record.type == "AAAA":
previpv6 = record["data"] previpv6 = record.data
for address in openstack_addresses: for address in openstack_addresses:
rtype = None rtype = None
if address.version == 4: if address.version == 4:
@ -269,43 +280,63 @@ def run_openstack_sync(cloud: str, name: str, zone: str, headers: dict,
elif address.version == 6: elif address.version == 6:
rtype = "AAAA" rtype = "AAAA"
curripv6 = True curripv6 = True
if rtype and record["type"] == rtype: if rtype and recor.type == rtype:
if record["data"] == address.addr: if record.data == address.addr:
continue continue
else: else:
url = setup_url(baseurl, url = setup_url(
zone=zone, baseurl,
name=name, None, # arguments,
rtype=record["type"], address.addr, # data,
data=address.addr) name,
record.type,
None, # ttl,
zone,
)
run_update(url, jsonout, headers) run_update(url, jsonout, headers)
if previpv4 and not curripv4: if previpv4 and not curripv4:
url = setup_url(baseurl, url = setup_url(
zone=zone, baseurl,
name=name, None, # arguments,
rtype="A", previpv4, # data,
data=previpv4) name,
"A",
None, # ttl,
zone,
)
run_delete(url, jsonout, headers) run_delete(url, jsonout, headers)
if previpv6 and not curripv6: if previpv6 and not curripv6:
url = setup_url(baseurl, url = setup_url(
zone=zone, baseurl,
name=name, None, # arguments,
rtype="AAAA", previpv6, # data,
data=previpv4) name,
"AAAA",
None, # ttl,
zone,
)
run_delete(url, jsonout, headers) run_delete(url, jsonout, headers)
if curripv4 and not previpv4: if curripv4 and not previpv4:
url = setup_url(baseurl, url = setup_url(
zone=zone, baseurl,
name=name, None, # arguments,
rtype="A", curripv4, # data,
data=curripv4) name,
"A",
None, # ttl,
zone,
)
run_add(url, jsonout, headers) run_add(url, jsonout, headers)
if curripv6 and not previpv6: if curripv6 and not previpv6:
url = setup_url(baseurl, url = setup_url(
zone=zone, baseurl,
name=name, None, # arguments,
rtype="AAAA", curripv6, # data,
data=curripv6) name,
"AAAA",
None, # ttl,
zone,
)
run_add(url, jsonout, headers) run_add(url, jsonout, headers)

Loading…
Cancel
Save