diff --git a/cli/dcoscli/data/help/node.txt b/cli/dcoscli/data/help/node.txt index daf2e00..aaca47b 100644 --- a/cli/dcoscli/data/help/node.txt +++ b/cli/dcoscli/data/help/node.txt @@ -13,7 +13,7 @@ Usage: dcos node list-components [--leader --mesos-id= --json] dcos node log [--follow --lines=N --leader --master --mesos-id= --slave=] [--component= --filter=...] - dcos node ssh (--leader | --master | --mesos-id= | --slave=) + dcos node ssh (--leader | --master | --mesos-id= | --private-ip= | --slave=) [--config-file=] [--user=] [--master-proxy] @@ -78,6 +78,8 @@ Options: --option SSHOPT=VAL The SSH options. For more information, enter `man ssh_config` in your terminal. + --private-ip= + Agent node with the provided private IP. --proxy-ip= Proxy the SSH connection through a different IP address. --slave= diff --git a/cli/dcoscli/node/main.py b/cli/dcoscli/node/main.py index bb6edc2..19566e6 100644 --- a/cli/dcoscli/node/main.py +++ b/cli/dcoscli/node/main.py @@ -81,7 +81,8 @@ def _cmds(): cmds.Command( hierarchy=['node', 'ssh'], arg_keys=['--leader', '--mesos-id', '--option', '--config-file', - '--user', '--master-proxy', '--proxy-ip', ''], + '--user', '--master-proxy', '--proxy-ip', '--private-ip', + ''], function=_ssh), cmds.Command( @@ -735,7 +736,7 @@ def _mesos_files(leader, slave_id): def _ssh(leader, slave, option, config_file, user, master_proxy, proxy_ip, - command): + private_ip, command): """SSH into a DC/OS node using the IP addresses found in master's state.json @@ -754,6 +755,8 @@ def _ssh(leader, slave, option, config_file, user, master_proxy, proxy_ip, :type master_proxy: bool | None :param proxy_ip: If set, SSH-hop from this IP address :type proxy_ip: str | None + :param private_ip: The private IP address of the node we want to SSH to. + :type private_ip: str | None :param command: Command to run on the node :type command: str | None :rtype: int @@ -765,6 +768,8 @@ def _ssh(leader, slave, option, config_file, user, master_proxy, proxy_ip, if leader: host = mesos.MesosDNSClient().hosts('leader.mesos.')[0]['ip'] + elif private_ip: + host = private_ip else: summary = dcos_client.get_state_summary() slave_obj = next((slave_ for slave_ in summary['slaves'] diff --git a/cli/tests/integrations/test_node.py b/cli/tests/integrations/test_node.py index 28c7322..b3cccb7 100644 --- a/cli/tests/integrations/test_node.py +++ b/cli/tests/integrations/test_node.py @@ -101,6 +101,13 @@ def test_node_ssh_slave(): _node_ssh(['--mesos-id={}'.format(slave_id), '--master-proxy']) +@pytest.mark.skipif(sys.platform == 'win32', + reason='No pseudo terminal on windows') +def test_node_ssh_slave_with_private_ip(): + slave_ip = mesos.DCOSClient().get_state_summary()['slaves'][0]['hostname'] + _node_ssh(['--private-ip={}'.format(slave_ip), '--master-proxy']) + + @pytest.mark.skipif(sys.platform == 'win32', reason='No pseudo terminal on windows') def test_node_ssh_option(): @@ -184,7 +191,7 @@ def test_node_ssh_with_command(): def test_node_ssh_slave_with_command(): slave = mesos.DCOSClient().get_state_summary()['slaves'][0] _node_ssh(['--mesos-id={}'.format(slave['id']), '--master-proxy', - '/opt/mesosphere/bin/detect_ip'], 0, slave['hostname']) + '/opt/mesosphere/bin/detect_ip'], 0, slave['hostname']) def _node_ssh_output(args):