From ff45b12412d6df5cb46e0b7b8c04c870aa9808b0 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Fri, 14 Apr 2023 10:29:25 +1000 Subject: [PATCH] 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 --- launch/src/opendev_launch/dns.py | 14 ++++++-------- launch/src/opendev_launch/launch_node.py | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/launch/src/opendev_launch/dns.py b/launch/src/opendev_launch/dns.py index 4befe8357a..a2276e4cc6 100755 --- a/launch/src/opendev_launch/dns.py +++ b/launch/src/opendev_launch/dns.py @@ -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) diff --git a/launch/src/opendev_launch/launch_node.py b/launch/src/opendev_launch/launch_node.py index 5d90a69c8d..cd297f6d5d 100755 --- a/launch/src/opendev_launch/launch_node.py +++ b/launch/src/opendev_launch/launch_node.py @@ -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()