From fc2affa832c155cb04207af38d90aec583bb5c6d Mon Sep 17 00:00:00 2001 From: Yichen Wang Date: Wed, 11 Dec 2019 14:31:50 -0800 Subject: [PATCH] Support both IPv4 and IPv6 DNS servers when creating networks Change-Id: I3214703956d98860bd791d1ee4cfb96e08de3408 --- vmtp/network.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vmtp/network.py b/vmtp/network.py index 2d929df..861e276 100644 --- a/vmtp/network.py +++ b/vmtp/network.py @@ -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(unicode(x))).__name__ == 'IPv4Address'] + ipv6_dns = [x for x in dns_nameservers + if type(ipaddress.ip_address(unicode(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: