Give IP address to socket.connect, rather than DNS name

This commit is contained in:
troymc 2016-04-27 11:57:19 +02:00
parent 774454e475
commit 344246096d

View File

@ -195,21 +195,25 @@ with open('hostlist.py', 'w') as f:
# For each node in the cluster, check port 22 (ssh) until it's reachable
for public_dns_name in public_dns_names:
# Create an INET, STREAMing socket
for instance in instances_with_tag:
ip_address = instance.public_ip_address
# Create a socket
# Address Family: AF_INET (means IPv4)
# Type: SOCK_STREAM (means connection-oriented TCP protocol)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print('Attempting to connect to {} on port 22 (ssh)...'.
format(public_dns_name))
format(ip_address))
unreachable = True
while unreachable:
try:
# Open a TCP connection to the remote node on port 22
s.connect((public_dns_name, 22))
print(' Port 22 is reachable!')
s.shutdown(socket.SHUT_WR)
s.close()
unreachable = False
# Open a connection to the remote node on port 22
s.connect((ip_address, 22))
except socket.error as e:
print(' Socket error: {}'.format(e))
print(' Trying again in 3 seconds')
time.sleep(3.0)
else:
print(' Port 22 is reachable!')
s.shutdown(socket.SHUT_WR)
s.close()
unreachable = False