From cfe96890447dba97d660a06255b1be52d506363b Mon Sep 17 00:00:00 2001 From: "ChangBo Guo(gcb)" Date: Tue, 23 Dec 2014 15:20:38 +0800 Subject: [PATCH] Use is_valid_ipv6 from oslo.utils Remove _is_valid_ipv6 from Cinder and replace it's usages by usages of is_valid_ipv6 from netutils, because this methods implements the same functionality. Change-Id: Ica16f0a34abc2f0c6f7240fe553a494d77dedc16 --- cinder/tests/integrated/api/client.py | 4 ++-- cinder/volume/drivers/vmware/read_write_util.py | 11 ++--------- cinder/volume/drivers/vmware/vim_util.py | 4 ++-- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/cinder/tests/integrated/api/client.py b/cinder/tests/integrated/api/client.py index d22f78aa1..1c16306c9 100644 --- a/cinder/tests/integrated/api/client.py +++ b/cinder/tests/integrated/api/client.py @@ -12,8 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. -import netaddr from oslo.serialization import jsonutils +from oslo.utils import netutils import requests import six.moves.urllib.parse as urlparse @@ -88,7 +88,7 @@ class TestOpenStackClient(object): hostname = parsed_url.hostname scheme = parsed_url.scheme - if netaddr.valid_ipv6(hostname): + if netutils.is_valid_ipv6(hostname): hostname = "[%s]" % hostname relative_url = parsed_url.path diff --git a/cinder/volume/drivers/vmware/read_write_util.py b/cinder/volume/drivers/vmware/read_write_util.py index 38957fc35..86351713d 100644 --- a/cinder/volume/drivers/vmware/read_write_util.py +++ b/cinder/volume/drivers/vmware/read_write_util.py @@ -23,7 +23,7 @@ import httplib import urllib import urllib2 -import netaddr +from oslo.utils import netutils import six.moves.urllib.parse as urlparse from cinder.i18n import _, _LI @@ -102,16 +102,9 @@ class VMwareHTTPFile(object): """Get size of the file to be read.""" raise NotImplementedError() - def _is_valid_ipv6(self, address): - """Whether given host address is a valid IPv6 address.""" - try: - return netaddr.valid_ipv6(address) - except Exception: - return False - def get_soap_url(self, scheme, host): """return IPv4/v6 compatible url constructed for host.""" - if self._is_valid_ipv6(host): + if netutils.is_valid_ipv6(host): return '%s://[%s]' % (scheme, host) return '%s://%s' % (scheme, host) diff --git a/cinder/volume/drivers/vmware/vim_util.py b/cinder/volume/drivers/vmware/vim_util.py index 948773243..97861d8b2 100644 --- a/cinder/volume/drivers/vmware/vim_util.py +++ b/cinder/volume/drivers/vmware/vim_util.py @@ -17,7 +17,7 @@ The VMware API utility module. """ -import netaddr +from oslo.utils import netutils def get_soap_url(protocol, host, path='sdk'): @@ -28,7 +28,7 @@ def get_soap_url(protocol, host, path='sdk'): :param path: path part of the SOAP URL :return: URL to SOAP services for ESX/VC server """ - if netaddr.valid_ipv6(host): + if netutils.is_valid_ipv6(host): return '%s://[%s]/%s' % (protocol, host, path) return '%s://%s/%s' % (protocol, host, path) -- 2.45.2