Filter nameservers for undercloud networks

We can have both ipv4 and ipv6 networks defined and could end up having
a mix of addresses passed into the undercloud configuration. Neutron
throws an error if the ip address type doesn't match the network being
created (e.g. ipv4 nameserver for ipv6 cidr and vice versa). Let's
filter the nameservers to ensure we only set the appropriate ip version
nameserver for the network.

Change-Id: I184797270dbb6c70cae11bc98128890529035690
Closes-Bug: #1841805
This commit is contained in:
Alex Schultz 2019-08-28 10:20:43 -06:00
parent 8ab702a94f
commit b96f83dfa1
1 changed files with 11 additions and 4 deletions

View File

@ -61,6 +61,9 @@ def _ensure_neutron_network(sdk):
return network
def _get_nameservers_for_version(servers, ipversion):
"""Get list of nameservers for an IP version"""
return [s for s in servers if netaddr.IPAddress(s).version == ipversion]
def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes,
allocation_pools, name, segment_id, dns_nameservers):
@ -77,7 +80,8 @@ def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes,
allocation_pools=allocation_pools,
network_id=network_id,
segment_id=segment_id,
dns_nameservers=dns_nameservers)
dns_nameservers=_get_nameservers_for_version(dns_nameservers,
6))
else:
subnet = sdk.network.create_subnet(
name=name,
@ -89,7 +93,8 @@ def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes,
allocation_pools=allocation_pools,
network_id=network_id,
segment_id=segment_id,
dns_nameservers=dns_nameservers)
dns_nameservers=_get_nameservers_for_version(dns_nameservers,
4))
print('INFO: Subnet created %s' % subnet)
except Exception:
print('ERROR: Create subnet %s failed.' % name)
@ -107,7 +112,8 @@ def _neutron_subnet_update(sdk, subnet_id, cidr, gateway, host_routes,
name=name,
gateway_ip=gateway,
allocation_pools=allocation_pools,
dns_nameservers=dns_nameservers)
dns_nameservers=_get_nameservers_for_version(dns_nameservers,
6))
else:
subnet = sdk.network.update_subnet(
subnet_id,
@ -115,7 +121,8 @@ def _neutron_subnet_update(sdk, subnet_id, cidr, gateway, host_routes,
gateway_ip=gateway,
host_routes=host_routes,
allocation_pools=allocation_pools,
dns_nameservers=dns_nameservers)
dns_nameservers=_get_nameservers_for_version(dns_nameservers,
4))
print('INFO: Subnet updated %s' % subnet)
except Exception:
print('ERROR: Update of subnet %s failed.' % name)