From 344246096d270d6cea555d6213d7de7fa2c2a498 Mon Sep 17 00:00:00 2001 From: troymc Date: Wed, 27 Apr 2016 11:57:19 +0200 Subject: [PATCH] Give IP address to socket.connect, rather than DNS name --- deploy-cluster-aws/launch_ec2_nodes.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/deploy-cluster-aws/launch_ec2_nodes.py b/deploy-cluster-aws/launch_ec2_nodes.py index 7db71adc..868a732c 100644 --- a/deploy-cluster-aws/launch_ec2_nodes.py +++ b/deploy-cluster-aws/launch_ec2_nodes.py @@ -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