Browse Source

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
changes/56/746656/1
Harald Jensås 1 year ago
parent
commit
1fd42a85da
  1. 5
      tripleoclient/utils.py
  2. 13
      tripleoclient/v1/undercloud_config.py

5
tripleoclient/utils.py

@ -772,7 +772,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
@ -787,7 +787,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)

13
tripleoclient/v1/undercloud_config.py

@ -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))
@ -682,10 +682,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]
@ -694,11 +697,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…
Cancel
Save