Just skightky tested, does not work

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

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

Loading…
Cancel
Save