diff --git a/lib/http/__init__.py b/lib/http/__init__.py index a42c496ef50024151d8da162e69e291dfaab9bdb..203e0d54c0d28d7d7dd3153f4caeff13924446e0 100644 --- a/lib/http/__init__.py +++ b/lib/http/__init__.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2007, 2008 Google Inc. +# Copyright (C) 2007, 2008, 2010 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -570,7 +570,7 @@ class HttpBase(object): self._ssl_key = None self._ssl_cert = None - def _CreateSocket(self, ssl_params, ssl_verify_peer): + def _CreateSocket(self, ssl_params, ssl_verify_peer, family): """Creates a TCP socket and initializes SSL if needed. @type ssl_params: HttpSslParams @@ -578,11 +578,14 @@ class HttpBase(object): @type ssl_verify_peer: bool @param ssl_verify_peer: Whether to require client certificate and compare it with our certificate + @type family: int + @param family: socket.AF_INET | socket.AF_INET6 """ - self._ssl_params = ssl_params + assert family in (socket.AF_INET, socket.AF_INET6) - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self._ssl_params = ssl_params + sock = socket.socket(family, socket.SOCK_STREAM) # Should we enable SSL? self.using_ssl = ssl_params is not None diff --git a/lib/http/server.py b/lib/http/server.py index 2e444dc3c536984bcd07edb6a3f0eafa2038d780..7a46af650f14085c359b437acae7dd793ed1810b 100644 --- a/lib/http/server.py +++ b/lib/http/server.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2007, 2008 Google Inc. +# Copyright (C) 2007, 2008, 2010 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -33,6 +33,7 @@ import asyncore from ganeti import http from ganeti import utils +from ganeti import netutils WEEKDAYNAME = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] @@ -478,8 +479,8 @@ class HttpServer(http.HttpBase, asyncore.dispatcher): self.mainloop = mainloop self.local_address = local_address self.port = port - - self.socket = self._CreateSocket(ssl_params, ssl_verify_peer) + family = netutils.IPAddress.GetAddressFamily(local_address) + self.socket = self._CreateSocket(ssl_params, ssl_verify_peer, family) # Allow port to be reused self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)