diff options
author | Sudipta Biswas <sbiswas7@in.ibm.com> | 2014-07-27 01:07:20 +0530 |
---|---|---|
committer | Sudipta Biswas <sbiswas7@in.ibm.com> | 2014-08-06 22:19:22 +0530 |
commit | 44948533e12e7e3e9bcab66a0b9b5eff032bfe51 (patch) | |
tree | a4d31bc5c66270072665cdb18e96da7a49fedba6 | |
parent | d833006bd4c2430d286905bc3a22004754739c98 (diff) | |
download | python-glanceclient-44948533e12e7e3e9bcab66a0b9b5eff032bfe51.tar.gz |
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
-rw-r--r-- | glanceclient/common/https.py | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/glanceclient/common/https.py b/glanceclient/common/https.py index 6416c19..93c6e6a 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, |