Translate hostname to IP when the main_vip is obtained

In some cases, the AUTH_URL parameter from the overcloudrc file
does not contain an IP, but a hostname. In those cases. the hostname
needs to be translated into an IP into the get_main_vip function

Change-Id: Ibad4d1b31c56711df231f4bbf3379d416fb3e433
This commit is contained in:
Eduardo Olivares 2022-11-16 16:23:17 +01:00
parent 39357023dc
commit eda34a2a63
1 changed files with 15 additions and 1 deletions

View File

@ -19,9 +19,11 @@ from datetime import datetime
import math
import random
import re
import socket
import time
import urllib.parse
import netaddr
from oslo_log import log
import tobiko
@ -215,7 +217,19 @@ def get_main_vip():
Retreive an ip address (ipv4/ipv6) from the auth_url."""
auth_url = keystone.default_keystone_credentials().auth_url
auth_url_parsed = urllib.parse.urlsplit(auth_url)
return auth_url_parsed.hostname
main_vip = auth_url_parsed.hostname
if not (netaddr.valid_ipv4(main_vip) or netaddr.valid_ipv6(main_vip)):
try:
# socket.gethostbyname translates hostname to IPv4 - it fails when
# no IPv4 address is available
main_vip = socket.gethostbyname(main_vip)
except socket.gaierror:
# the following method obtains an IPv6 from a hostname
main_vip = socket.getaddrinfo(
main_vip, None, socket.AF_INET6)[0][4][0]
return main_vip
def get_main_vip_controller(main_vip):