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
This commit is contained in:
parent
9c03d2b18f
commit
1fd42a85da
|
@ -772,7 +772,7 @@ def get_host_ips(host, type=None):
|
||||||
return list(ips)
|
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.
|
"""Translate an hostname into a single IP address if it is a valid IP.
|
||||||
|
|
||||||
:param host: IP or hostname or FQDN to lookup
|
:param host: IP or hostname or FQDN to lookup
|
||||||
|
@ -787,7 +787,8 @@ def get_single_ip(host, allow_loopback=False):
|
||||||
|
|
||||||
ip = host
|
ip = host
|
||||||
if not is_valid_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:
|
if not ips:
|
||||||
raise exceptions.LookupError('No IP was found for the host: '
|
raise exceptions.LookupError('No IP was found for the host: '
|
||||||
'%s' % host)
|
'%s' % host)
|
||||||
|
|
|
@ -333,9 +333,9 @@ def _calculate_allocation_pools(subnet):
|
||||||
ip_set.remove(netaddr.IPAddress(subnet.get('gateway')))
|
ip_set.remove(netaddr.IPAddress(subnet.get('gateway')))
|
||||||
ip_set.remove(netaddr.IPNetwork(CONF.local_ip).ip)
|
ip_set.remove(netaddr.IPNetwork(CONF.local_ip).ip)
|
||||||
ip_set.remove(netaddr.IPNetwork(utils.get_single_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(
|
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
|
# Remove dns nameservers
|
||||||
for addr in subnet.get('dns_nameservers', []):
|
for addr in subnet.get('dns_nameservers', []):
|
||||||
ip_set.remove(netaddr.IPAddress(addr))
|
ip_set.remove(netaddr.IPAddress(addr))
|
||||||
|
@ -682,10 +682,13 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
|
||||||
|
|
||||||
if (CONF.get('generate_service_certificate') or
|
if (CONF.get('generate_service_certificate') or
|
||||||
CONF.get('undercloud_service_certificate')):
|
CONF.get('undercloud_service_certificate')):
|
||||||
|
local_net = netaddr.IPNetwork(CONF.get('local_ip'))
|
||||||
|
|
||||||
endpoint_environment = _get_tls_endpoint_environment(
|
endpoint_environment = _get_tls_endpoint_environment(
|
||||||
CONF.get('undercloud_public_host'), tht_templates)
|
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)
|
public_ip = netaddr.IPAddress(public_host)
|
||||||
deploy_args += ['--public-virtual-ip', public_host]
|
deploy_args += ['--public-virtual-ip', public_host]
|
||||||
|
|
||||||
|
@ -694,11 +697,11 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=True,
|
||||||
extra_host = public_host + ' ' + CONF.get('undercloud_public_host')
|
extra_host = public_host + ' ' + CONF.get('undercloud_public_host')
|
||||||
env_data['ExtraHostFileEntries'] = extra_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)
|
admin_ip = netaddr.IPAddress(admin_host)
|
||||||
deploy_args += ['--control-virtual-ip', 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 CONF.get('net_config_override', None):
|
||||||
if (admin_ip not in local_net.cidr):
|
if (admin_ip not in local_net.cidr):
|
||||||
LOG.warning('You may need to specify a custom '
|
LOG.warning('You may need to specify a custom '
|
||||||
|
|
Loading…
Reference in New Issue