From 44948533e12e7e3e9bcab66a0b9b5eff032bfe51 Mon Sep 17 00:00:00 2001 From: Sudipta Biswas Date: Sun, 27 Jul 2014 01:07:20 +0530 Subject: [PATCH] Fix glance-client to work with IPv6 controllers Currently the glance client can't operate on IPv6 address based openstack controller IPs. The reason for this is the absence of creation of a IPv6 socket in the glance client code (in https.py). The glance client is trying to create sockets from the AF_INET socket family but this will lead to errors when glance client makes a call on the IPv6 IP addresses. In order to fix this limitation, we ensure that if the hostname resolves to IPv6 or an explicit IPv6 address is used to configure the openstack controller - glance client shall be able to detect that and then create a AF_INET6 socket family. In all other cases a AF_INET socket is created. We default to IPv4 sockets in all other cases. Change-Id: I7d5a09675cd5dab2e39f0faeaa7c169291eedac6 Closes-bug: #1348030 --- glanceclient/common/https.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/glanceclient/common/https.py b/glanceclient/common/https.py index 6416c191..93c6e6aa 100644 --- a/glanceclient/common/https.py +++ b/glanceclient/common/https.py @@ -265,7 +265,18 @@ class VerifiedHTTPSConnection(HTTPSConnection): Connect to an SSL port using the OpenSSL library and apply per-connection parameters. """ - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + result = socket.getaddrinfo(self.host, self.port, 0, + socket.SOCK_STREAM) + if result: + socket_family = result[0][0] + if socket_family == socket.AF_INET6: + sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + else: + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + else: + # If due to some reason the address lookup fails - we still connect + # to IPv4 socket. This retains the older behavior. + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) if self.timeout is not None: # '0' microseconds sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO,