Support both IPv4 and IPv6 DNS servers when creating networks

Change-Id: I3214703956d98860bd791d1ee4cfb96e08de3408
This commit is contained in:
Yichen Wang 2019-12-11 14:31:50 -08:00
parent 822e7c5fe4
commit 34a82c9f35
1 changed files with 9 additions and 2 deletions

View File

@ -14,6 +14,7 @@
#
import time
import ipaddress
from .log import LOG
# Module containing a helper class for operating on OpenStack networks
@ -166,6 +167,11 @@ class Network(object):
LOG.info('Found existing internal network: %s', network_name)
return network
ipv4_dns = [x for x in dns_nameservers
if type(ipaddress.ip_address(u'%s' % x)).__name__ == 'IPv4Address']
ipv6_dns = [x for x in dns_nameservers
if type(ipaddress.ip_address(u'%s' % x)).__name__ == 'IPv6Address']
body = {
'network': {
'name': network_name,
@ -180,7 +186,7 @@ class Network(object):
'network_id': network['id'],
'enable_dhcp': True,
'ip_version': 4,
'dns_nameservers': dns_nameservers
'dns_nameservers': ipv4_dns
}
}
if not enable_dhcp:
@ -199,7 +205,8 @@ class Network(object):
'enable_dhcp': True,
'ip_version': 6,
'ipv6_ra_mode': ipv6_mode,
'ipv6_address_mode': ipv6_mode
'ipv6_address_mode': ipv6_mode,
'dns_nameservers': ipv6_dns
}
}
if not enable_dhcp: