Merge "Filter nameservers for undercloud networks"

This commit is contained in:
Zuul 2019-08-29 14:20:27 +00:00 committed by Gerrit Code Review
commit fc0bbd0e70

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)