Limit ip_version when resolving public_host and admin_host
Use the the local_ip config option to filter results to a single
ip version when resolving public_host and admin_host to ip
addresses.
When nameservers return result for both IPv4 and IPv6 we currently
fail, due to multiple IP's for the host.
Change-Id: Ic86dcea7abb5dbae31aa20fe91957e5e9a07f94e
Related-Bug: #1763776
Related: RHBZ#1868910
(cherry picked from commit 1fd42a85da
)
This commit is contained in:
parent
47df2204b8
commit
7fcc694d00
|
@ -774,7 +774,7 @@ def get_host_ips(host, type=None):
|
|||
return list(ips)
|
||||
|
||||
|
||||
def get_single_ip(host, allow_loopback=False):
|
||||
def get_single_ip(host, allow_loopback=False, ip_version=4):
|
||||
"""Translate an hostname into a single IP address if it is a valid IP.
|
||||
|
||||
:param host: IP or hostname or FQDN to lookup
|
||||
|
@ -789,7 +789,8 @@ def get_single_ip(host, allow_loopback=False):
|
|||
|
||||
ip = host
|
||||
if not is_valid_ip(host):
|
||||
ips = get_host_ips(host)
|
||||
type = socket.AF_INET6 if ip_version == 6 else socket.AF_INET
|
||||
ips = get_host_ips(host, type=type)
|
||||
if not ips:
|
||||
raise exceptions.LookupError('No IP was found for the host: '
|
||||
'%s' % host)
|
||||
|
|
|
@ -333,9 +333,9 @@ def _calculate_allocation_pools(subnet):
|
|||
ip_set.remove(netaddr.IPAddress(subnet.get('gateway')))
|
||||
ip_set.remove(netaddr.IPNetwork(CONF.local_ip).ip)
|
||||
ip_set.remove(netaddr.IPNetwork(utils.get_single_ip(
|
||||
CONF.undercloud_admin_host)))
|
||||
CONF.undercloud_admin_host, ip_version=ip_network.version)))
|
||||
ip_set.remove(netaddr.IPNetwork(utils.get_single_ip(
|
||||
CONF.undercloud_public_host)))
|
||||
CONF.undercloud_public_host, ip_version=ip_network.version)))
|
||||
# Remove dns nameservers
|
||||
for addr in subnet.get('dns_nameservers', []):
|
||||
ip_set.remove(netaddr.IPAddress(addr))
|
||||
|
@ -687,10 +687,13 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
|
|||
|
||||
if (CONF.get('generate_service_certificate') or
|
||||
CONF.get('undercloud_service_certificate')):
|
||||
local_net = netaddr.IPNetwork(CONF.get('local_ip'))
|
||||
|
||||
endpoint_environment = _get_tls_endpoint_environment(
|
||||
CONF.get('undercloud_public_host'), tht_templates)
|
||||
|
||||
public_host = utils.get_single_ip(CONF.get('undercloud_public_host'))
|
||||
public_host = utils.get_single_ip(CONF.get('undercloud_public_host'),
|
||||
ip_version=local_net.version)
|
||||
public_ip = netaddr.IPAddress(public_host)
|
||||
deploy_args += ['--public-virtual-ip', public_host]
|
||||
|
||||
|
@ -699,11 +702,11 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
|
|||
extra_host = public_host + ' ' + CONF.get('undercloud_public_host')
|
||||
env_data['ExtraHostFileEntries'] = extra_host
|
||||
|
||||
admin_host = utils.get_single_ip(CONF.get('undercloud_admin_host'))
|
||||
admin_host = utils.get_single_ip(CONF.get('undercloud_admin_host'),
|
||||
ip_version=local_net.version)
|
||||
admin_ip = netaddr.IPAddress(admin_host)
|
||||
deploy_args += ['--control-virtual-ip', admin_host]
|
||||
|
||||
local_net = netaddr.IPNetwork(CONF.get('local_ip'))
|
||||
if CONF.get('net_config_override', None):
|
||||
if (admin_ip not in local_net.cidr):
|
||||
LOG.warning('You may need to specify a custom '
|
||||
|
|
Loading…
Reference in New Issue