launch: further DNS cleanups

As pointed out by clarkb in review of prior change
I06995027a4b80133bdac91c263d7a92fd495493b the hostname handling here
is a bit wonky.

Use "host" instead of "hostname" since we use that in the rest of the
file.  The print_dns() function doesn't need a cloud argument, remove
it.  The print_sshfp_records was incorrectly splitting the host/domain
for nodes like "mirror.rax.iad.openstack.org" -- simply pass only the
host for the bind record from the print_dns() function.

Change-Id: I3d851902ef52588a69294b02e22f4b4667454629
This commit is contained in:
Ian Wienand 2023-04-14 10:29:25 +10:00
parent 03de935048
commit ff45b12412
No known key found for this signature in database
2 changed files with 7 additions and 9 deletions

View File

@ -22,9 +22,9 @@
import argparse
import subprocess
def print_sshfp_records(hostname, ip):
def print_sshfp_records(host, ip):
'''Given a hostname and and IP address, scan the IP address (hostname
not in dns yet) and return a bind string with sshfp records'''
not in dns yet) and print the sshfp records in standard bind format'''
p = ['ssh-keyscan', '-D', ip]
s = subprocess.run(p,
stdout=subprocess.PIPE,
@ -45,12 +45,10 @@ def print_sshfp_records(hostname, ip):
# sort by algo and key_type to keep it consistent
fingerprints = sorted(fingerprints,
key=lambda x: (x[0], x[1]))
dns_hostname = hostname.split('.')[0]
for f in fingerprints:
print(f"{dns_hostname}\t\t\tIN\tSSHFP\t{f[0]} {f[1]} {f[2]}")
print(f"{host}\t\t\tIN\tSSHFP\t{f[0]} {f[1]} {f[2]}")
def print_dns(cloud, server):
def print_dns(server):
ip4 = server.public_v4
ip6 = server.public_v6
# note handle things like mirror.iad.rax.opendev.org
@ -66,7 +64,7 @@ def print_dns(cloud, server):
print(f"{host} IN A {ip4}")
if ip6:
print(f"{host} IN AAAA {ip6}")
print_sshfp_records(server.name, ip4)
print_sshfp_records(host, ip4)
def main():
parser = argparse.ArgumentParser()
@ -84,4 +82,4 @@ def main():
" openstacksdk >= 0.12 is required")
raise
print_dns(cloud, server)
print_dns(server)

View File

@ -456,7 +456,7 @@ def main():
print()
print("-------- CONFIGURATION --------\n")
dns.print_dns(cloud, server)
dns.print_dns(server)
print()
print_inventory_yaml(server)
print()