Skip to content

Commit

Permalink
Only request node IPs to the cloud provider if they're unknown.
Browse files Browse the repository at this point in the history
This allows running, e.g., `elasticluster ssh cluster` without valid
cloud credentials (e.g., in OpenStack you do not need to load the
`OS_*` env vars in the current environemnt), and generally speeds up
the connection process.
  • Loading branch information
riccardomurri committed Sep 16, 2019
1 parent 2b3706b commit 103a6ec
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions elasticluster/subcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,20 +755,25 @@ def execute(self):
# XXX: the default value of `self.params.ssh_to` should = the
# default value for `ssh_to` in `Cluster.get_ssh_to_node()`
frontend = cluster.get_ssh_to_node(self.params.ssh_to)
log.debug("Updating the ip addresses of `%s`.", frontend.name)
frontend.update_ips()

# ensure we can connect to the host
try:
if not frontend.preferred_ip:
if not frontend.connection_ip():
log.info(
"No connection address known for node `%s`,"
" updating list of IP addresses ...", frontend.name)
frontend.update_ips()
log.debug(
"Checking that SSH connection to node `%s` works..",
frontend.name)
# Ensure we can connect to the node, and save the value of `preferred_ip`
ssh = frontend.connect(keyfile=cluster.known_hosts_file)
if ssh:
ssh.close()
cluster.repository.save_or_update(cluster)
except NodeNotFound as ex:
log.error("Unable to connect to the frontend node: %s", ex)
sys.exit(1)
except Exception as err:
log.error("Unable to connect to the frontend node: %s", err)
sys.exit(os.EX_TEMPFAIL)

# now delegate real connection to `ssh`
host = frontend.connection_ip()
Expand Down

0 comments on commit 103a6ec

Please sign in to comment.