From 84b66c8411bcf5efe9ecb24dfd8d05b3d956c223 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Wed, 3 Dec 2014 21:43:21 -0600 Subject: [PATCH] startvms: Support IPv6 services as well Using the `socket.create_connection` function to attempt to connect to the network service allows both IPv4 and IPv6 support, as the function tries both families internally and returns the first socket to succeed. --HG-- extra : amend_source : 6a0e3b9c90f6caff94290125072d50fe97aa312e --- startvms.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/startvms.py b/startvms.py index 937e217..84a5565 100644 --- a/startvms.py +++ b/startvms.py @@ -123,20 +123,17 @@ def wait_for(host, port, timeout=None): else: keep_going = lambda: True while keep_going(): - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.settimeout(1) try: log.debug('Attempting connection to {0}:{1}'.format(host, port)) - s.connect((host, port)) + s = socket.create_connection((host, port), 1) except: log.debug('Connection failed') time.sleep(1) else: log.debug('Connection succeeded') s.shutdown(socket.SHUT_RDWR) - break - finally: s.close() + break else: raise Timeout('Timed out waiting for port {port} on {host}'.format( port=port,