Replace hostnames with numerical IP addresses in redis address. (#1177)

* Replace hostnames with numerical IP addresses in redis address.

* Also do conversion for node_ip_address. Add test.

* Simplifications.
This commit is contained in:
Robert Nishihara
2017-11-01 17:13:22 -07:00
committed by Philipp Moritz
parent 202e7bf19a
commit 3317d38278
4 changed files with 49 additions and 0 deletions
+6
View File
@@ -81,6 +81,12 @@ def start(node_ip_address, redis_address, redis_port, num_redis_shards,
# temporary fix. We should actually redirect stdout and stderr to Redis in
# some way.
# Convert hostnames to numerical IP address.
if node_ip_address is not None:
node_ip_address = services.address_to_ip(node_ip_address)
if redis_address is not None:
redis_address = services.address_to_ip(redis_address)
if head:
# Start Ray on the head node.
if redis_address is not None:
+19
View File
@@ -165,6 +165,25 @@ def all_processes_alive(exclude=[]):
return True
def address_to_ip(address):
"""Convert a hostname to a numerical IP addresses in an address.
This should be a no-op if address already contains an actual numerical IP
address.
Args:
address: This can be either a string containing a hostname (or an IP
address) and a port or it can be just an IP address.
Returns:
The same address but with the hostname replaced by a numerical IP
address.
"""
address_parts = address.split(":")
ip_address = socket.gethostbyname(address_parts[0])
return ":".join([ip_address] + address_parts[1:])
def get_node_ip_address(address="8.8.8.8:53"):
"""Determine the IP address of the local node.
+6
View File
@@ -1359,6 +1359,12 @@ def init(redis_address=None, node_ip_address=None, object_id_seed=None,
Exception: An exception is raised if an inappropriate combination of
arguments is passed in.
"""
# Convert hostnames to numerical IP address.
if node_ip_address is not None:
node_ip_address = services.address_to_ip(node_ip_address)
if redis_address is not None:
redis_address = services.address_to_ip(redis_address)
info = {"node_ip_address": node_ip_address,
"redis_address": redis_address}
return _init(address_info=info, start_ray_local=(redis_address is None),