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

This commit is contained in:
Zuul 2019-09-05 01:28:21 +00:00 committed by Gerrit Code Review
commit a0f6a5fc27
1 changed files with 11 additions and 4 deletions

View File

@ -70,6 +70,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_pool, name, segment_id, dns_nameservers): allocation_pool, name, segment_id, dns_nameservers):
@ -86,7 +89,8 @@ def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes,
allocation_pools=allocation_pool, allocation_pools=allocation_pool,
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,
@ -98,7 +102,8 @@ def _neutron_subnet_create(sdk, network_id, cidr, gateway, host_routes,
allocation_pools=allocation_pool, allocation_pools=allocation_pool,
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)
@ -116,7 +121,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_pool, allocation_pools=allocation_pool,
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,
@ -124,7 +130,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_pool, allocation_pools=allocation_pool,
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)