Merge "Filter nameservers for undercloud networks" into stable/stein

This commit is contained in:
Zuul 2019-08-30 21:54:22 +00:00 committed by Gerrit Code Review
commit 4e2dddb524
1 changed files with 11 additions and 4 deletions

View File

@ -61,6 +61,9 @@ def _ensure_neutron_network(sdk):
return network 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, def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes,
allocation_pools, name, segment_id, dns_nameservers): 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, allocation_pools=allocation_pools,
network_id=network_id, network_id=network_id,
segment_id=segment_id, segment_id=segment_id,
dns_nameservers=dns_nameservers) dns_nameservers=_get_nameservers_for_version(dns_nameservers,
6))
else: else:
subnet = sdk.network.create_subnet( subnet = sdk.network.create_subnet(
name=name, name=name,
@ -89,7 +93,8 @@ def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes,
allocation_pools=allocation_pools, allocation_pools=allocation_pools,
network_id=network_id, network_id=network_id,
segment_id=segment_id, segment_id=segment_id,
dns_nameservers=dns_nameservers) dns_nameservers=_get_nameservers_for_version(dns_nameservers,
4))
print('INFO: Subnet created %s' % subnet) print('INFO: Subnet created %s' % subnet)
except Exception: except Exception:
print('ERROR: Create subnet %s failed.' % name) print('ERROR: Create subnet %s failed.' % name)
@ -107,7 +112,8 @@ def _neutron_subnet_update(sdk, subnet_id, cidr, gateway, host_routes,
name=name, name=name,
gateway_ip=gateway, gateway_ip=gateway,
allocation_pools=allocation_pools, allocation_pools=allocation_pools,
dns_nameservers=dns_nameservers) dns_nameservers=_get_nameservers_for_version(dns_nameservers,
6))
else: else:
subnet = sdk.network.update_subnet( subnet = sdk.network.update_subnet(
subnet_id, subnet_id,
@ -115,7 +121,8 @@ def _neutron_subnet_update(sdk, subnet_id, cidr, gateway, host_routes,
gateway_ip=gateway, gateway_ip=gateway,
host_routes=host_routes, host_routes=host_routes,
allocation_pools=allocation_pools, allocation_pools=allocation_pools,
dns_nameservers=dns_nameservers) dns_nameservers=_get_nameservers_for_version(dns_nameservers,
4))
print('INFO: Subnet updated %s' % subnet) print('INFO: Subnet updated %s' % subnet)
except Exception: except Exception:
print('ERROR: Update of subnet %s failed.' % name) print('ERROR: Update of subnet %s failed.' % name)