Merge "Fix rax reverse DNS setup in launch"

This commit is contained in:
Zuul 2023-04-13 00:22:46 +00:00 committed by Gerrit Code Review
commit a5a65012c2
3 changed files with 49 additions and 32 deletions

View File

@ -19,19 +19,10 @@
# limitations under the License.
import argparse
from . import rax_rdns
from .sshfp import sshfp_print_records
from .ssh_knownhosts import generate_known_hosts
def get_href(server):
if not hasattr(server, 'links'):
return None
for link in server.links:
if link['rel'] == 'self':
return link['href']
def print_dns(cloud, server):
ip4 = server.public_v4
ip6 = server.public_v6
@ -53,23 +44,6 @@ def print_dns_opendev(name, ip4, ip6):
sshfp_print_records(name, ip4)
def set_rax_reverse_dns(cloud, server, ip4, ip6):
# Get the server object from the sdk layer so that we can pull the
# href data out of the links dict.
try:
raw_server = cloud.compute.get_server(server.id)
except AttributeError:
print("Please update your version of shade/openstacksdk."
" openstacksdk >= 0.12 is required")
raise
href = get_href(raw_server)
# Reads default config file /etc/rax-rdns-auth.conf and calls to
# API to set reverse dns for RAX servers.
auth = rax_rdns.get_auth()
rax_rdns.rax_rdns(server.name, href, ip4, ip6, 3600, auth)
def print_inventory_yaml(server, ip4, ip6):
known_hosts = generate_known_hosts(ip4)
@ -106,7 +80,4 @@ def main():
" openstacksdk >= 0.12 is required")
raise
if 'rax' in cloud.config.name:
set_rax_reverse_dns(cloud, server, ip4, ip6)
print_dns(cloud, server)

View File

@ -30,6 +30,7 @@ import time
import traceback
from . import dns
from . import rax_rdns
from . import utils
import openstack
@ -430,6 +431,9 @@ def main():
options.environment, options.volume_size,
options.timeout, options.ignore_ipv6,
options.playbooks)
if 'rax' in cloud.config.name:
rax_rdns.set_rax_reverse_dns(cloud, server,
server.public_v4, server.public_v6)
dns.print_dns(cloud, server)
print("If this is a server that is expected to send email (ask, review,")
print("lists, etc) double check that the server's IPs are not listed on")

View File

@ -39,6 +39,15 @@ import sys
RACKSPACE_IDENTITY_ENDPOINT='https://identity.api.rackspacecloud.com/v2.0/tokens'
RACKSPACE_DNS_ENDPOINT="https://dns.api.rackspacecloud.com/v1.0"
def get_href(server):
if not hasattr(server, 'links'):
return None
for link in server.links:
if link['rel'] == 'self':
return link['href']
def _get_auth_token(session, username, api_key):
# Get auth token
data = {'auth':
@ -113,6 +122,23 @@ def rax_rdns(name, server_href, ip4, ip6, ttl, auth):
logging.info("RDNS Done: %s %s" % (r.status_code, r.reason))
def set_rax_reverse_dns(cloud, server, ip4, ip6):
# Get the server object from the sdk layer so that we can pull the
# href data out of the links dict.
try:
raw_server = cloud.compute.get_server(server.id)
except AttributeError:
print("Please update your version of shade/openstacksdk."
" openstacksdk >= 0.12 is required")
raise
href = get_href(raw_server)
# Reads default config file /etc/rax-rdns-auth.conf and calls to
# API to set reverse dns for RAX servers.
auth = get_auth()
rax_rdns(server.name, href, ip4, ip6, 3600, auth)
def main():
parser = argparse.ArgumentParser(description='Update RDNS')
parser.add_argument('--debug', dest='debug', action='store_true')
@ -120,7 +146,10 @@ def main():
default='/etc/rax-rdns-auth.conf')
parser.add_argument('--ttl', dest='ttl', type=int, default=3600)
parser.add_argument('name')
parser.add_argument('server_href')
parser.add_argument('server_href', required=False,
help='If server_href is not supplied then href, '
'and ip addresses are fetched from the cloud '
'using name.')
parser.add_argument('ip4')
parser.add_argument('ip6')
args = parser.parse_args()
@ -132,5 +161,18 @@ def main():
requests_log.setLevel(logging.DEBUG)
requests_log.propogate = True
auth = get_auth(args.config)
rax_rdns(args.name, args.server_href, args.ip4, args.ip6, args.ttl, auth)
if args.server_href:
auth = get_auth(args.config)
rax_rdns(args.name, args.server_href, args.ip4, args.ip6, args.ttl, auth)
else:
import openstack
cloud = openstack.connect()
# Get the server using the shade layer so that we have server.public_v4
# and server.public_v6
try:
server = cloud.get_server(args.name)
except AttributeError:
print("Please update your version of shade/openstacksdk."
" openstacksdk >= 0.12 is required")
raise
set_rax_reverse_dns(cloud, server, server.public_v4, server.public_v6)