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
This commit is contained in:
Sudipta Biswas
2014-07-27 01:07:20 +05:30
parent d833006bd4
commit 44948533e1

View File

@@ -265,7 +265,18 @@ class VerifiedHTTPSConnection(HTTPSConnection):
Connect to an SSL port using the OpenSSL library and apply Connect to an SSL port using the OpenSSL library and apply
per-connection parameters. 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: if self.timeout is not None:
# '0' microseconds # '0' microseconds
sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO,