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 : 6a0e3b9c90f6caff94290125072d50fe97aa312emaster
parent
5ff79e49ba
commit
84b66c8411
|
@ -123,20 +123,17 @@ def wait_for(host, port, timeout=None):
|
||||||
else:
|
else:
|
||||||
keep_going = lambda: True
|
keep_going = lambda: True
|
||||||
while keep_going():
|
while keep_going():
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
||||||
s.settimeout(1)
|
|
||||||
try:
|
try:
|
||||||
log.debug('Attempting connection to {0}:{1}'.format(host, port))
|
log.debug('Attempting connection to {0}:{1}'.format(host, port))
|
||||||
s.connect((host, port))
|
s = socket.create_connection((host, port), 1)
|
||||||
except:
|
except:
|
||||||
log.debug('Connection failed')
|
log.debug('Connection failed')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
else:
|
else:
|
||||||
log.debug('Connection succeeded')
|
log.debug('Connection succeeded')
|
||||||
s.shutdown(socket.SHUT_RDWR)
|
s.shutdown(socket.SHUT_RDWR)
|
||||||
break
|
|
||||||
finally:
|
|
||||||
s.close()
|
s.close()
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
raise Timeout('Timed out waiting for port {port} on {host}'.format(
|
raise Timeout('Timed out waiting for port {port} on {host}'.format(
|
||||||
port=port,
|
port=port,
|
||||||
|
|
Loading…
Reference in New Issue