Add COMMAND arg for ssh commands

This commit is contained in:
Fred Park 2017-04-30 14:22:13 -07:00
Родитель 9acdc2e000
Коммит c8f7521196
8 изменённых файлов: 44 добавлений и 27 удалений

Просмотреть файл

@ -14,6 +14,9 @@ working directory. Please see the usage guide for more information about
this command.
### Changed
- Added optional `COMMAND` argument to `pool ssh` and `fs cluster ssh`
commands. If `COMMAND` is specified, the command is run non-interactively
with SSH on the target node.
- Added some additional sanity checks in the node prep script
- Updated TensorFlow-CPU and TensorFlow-GPU recipes to 1.1.0. Removed
specialized Docker build for TensorFlow-GPU. Added `jobs-tb.json` files

Просмотреть файл

@ -1583,10 +1583,10 @@ def action_fs_cluster_status(
def action_fs_cluster_ssh(
compute_client, network_client, config, storage_cluster_id,
cardinal, hostname):
cardinal, hostname, command):
# type: (azure.mgmt.compute.ComputeManagementClient,
# azure.mgmt.network.NetworkManagementClient, dict, str, int,
# str) -> None
# str, tuple) -> None
"""Action: Fs Cluster Ssh
:param azure.mgmt.compute.ComputeManagementClient compute_client:
compute client
@ -1596,6 +1596,7 @@ def action_fs_cluster_ssh(
:param str storage_cluster_id: storage cluster id
:param int cardinal: cardinal number
:param str hostname: hostname
:param tuple command: command
"""
if cardinal is not None and hostname is not None:
raise ValueError('cannot specify both cardinal and hostname options')
@ -1608,7 +1609,7 @@ def action_fs_cluster_ssh(
raise ValueError('invalid cardinal option value')
remotefs.ssh_storage_cluster(
compute_client, network_client, config, storage_cluster_id,
cardinal, hostname)
cardinal, hostname, command)
def action_keyvault_add(keyvault_client, config, keyvault_uri, name):
@ -1923,14 +1924,15 @@ def action_pool_dsu(batch_client, config):
batch.del_ssh_user(batch_client, config)
def action_pool_ssh(batch_client, config, cardinal, nodeid):
# type: (batchsc.BatchServiceClient, dict, int, str) -> None
def action_pool_ssh(batch_client, config, cardinal, nodeid, command):
# type: (batchsc.BatchServiceClient, dict, int, str, tuple) -> None
"""Action: Pool Ssh
:param azure.batch.batch_service_client.BatchServiceClient batch_client:
batch client
:param dict config: configuration dict
:param int cardinal: cardinal node num
:param str nodeid: node id
:param tuple command: command to execute
"""
if cardinal is not None and nodeid is not None:
raise ValueError('cannot specify both cardinal and nodeid options')
@ -1953,11 +1955,13 @@ def action_pool_ssh(batch_client, config, cardinal, nodeid):
batch_client, config, cardinal, nodeid)
logger.info('connecting to node {}:{} with key {}'.format(
ip, port, ssh_private_key))
util.subprocess_with_output(
['ssh', '-o', 'StrictHostKeyChecking=no', '-o',
ssh_cmd = ['ssh', '-o', 'StrictHostKeyChecking=no', '-o',
'UserKnownHostsFile={}'.format(os.devnull),
'-i', str(ssh_private_key), '-p', str(port),
'{}@{}'.format(pool.ssh.username, ip)])
'{}@{}'.format(pool.ssh.username, ip)]
if util.is_not_empty(command):
ssh_cmd.extend(command)
util.subprocess_with_output(ssh_cmd)
def action_pool_delnode(batch_client, config, nodeid):

Просмотреть файл

@ -215,7 +215,7 @@ def tunnel_tensorboard(batch_client, config, jobid, taskid, logdir, image):
'\n\n>> Terminate your session with CTRL+C'
'\n\n>> If you cannot terminate your session cleanly, run:'
'\n shipyard pool ssh --nodeid {} '
'\n sudo docker kill {}\n').format(
'sudo docker kill {}\n').format(
tb[2], task.node_info.node_id, name))
tb_proc.wait()
finally:

Просмотреть файл

@ -2253,10 +2253,11 @@ def _get_ssh_info(
def ssh_storage_cluster(
compute_client, network_client, config, sc_id, cardinal, hostname):
compute_client, network_client, config, sc_id, cardinal, hostname,
command):
# type: (azure.mgmt.compute.ComputeManagementClient,
# azure.mgmt.network.NetworkManagementClient, dict, str, int,
# str) -> None
# str, tuple) -> None
"""SSH to a node in storage cluster
:param azure.mgmt.compute.ComputeManagementClient compute_client:
compute client
@ -2266,6 +2267,7 @@ def ssh_storage_cluster(
:param str sc_id: storage cluster id
:param int cardinal: cardinal number
:param str hostname: hostname
:param tuple command: command to execute
"""
ssh_priv_key, port, username, ip = _get_ssh_info(
compute_client, network_client, config, sc_id, cardinal, hostname)
@ -2278,8 +2280,10 @@ def ssh_storage_cluster(
logger.info(
('connecting to storage cluster {} virtual machine {}:{} with '
'key {}').format(sc_id, ip, port, ssh_priv_key))
util.subprocess_with_output(
['ssh', '-o', 'StrictHostKeyChecking=no',
ssh_cmd = ['ssh', '-o', 'StrictHostKeyChecking=no',
'-o', 'UserKnownHostsFile={}'.format(os.devnull),
'-i', str(ssh_priv_key), '-p', str(port),
'{}@{}'.format(username, ip)])
'{}@{}'.format(username, ip)]
if util.is_not_empty(command):
ssh_cmd.extend(command)
util.subprocess_with_output(ssh_cmd)

Просмотреть файл

@ -286,6 +286,9 @@ specified in the configuration. This is an experimental feature.
* `ssh` will interactively log into a virtual machine in the storage cluster.
If neither `--cardinal` or `--hostname` are specified, `--cardinal 0` is
assumed.
* `COMMAND` is an optional argument to specify the command to run. If your
command has switches, preface `COMMAND` with double dash as per POSIX
convention, e.g., `fs cluster ssh mycluster -- df -h`.
* `--cardinal` is the zero-based cardinal number of the virtual machine in
the storage cluster to connect to.
* `--hostname` is the hostname of the virtual machine in the storage cluster
@ -456,6 +459,9 @@ configuration file
* `--wait` will wait for resize to complete
* `ssh` will interactively log into a compute node via SSH. If neither
`--cardinal` or `--nodeid` are specified, `--cardinal 0` is assumed.
* `COMMAND` is an optional argument to specify the command to run. If your
command has switches, preface `COMMAND` with double dash as per POSIX
convention, e.g., `pool ssh -- sudo docker ps -a`.
* `--cardinal` is the zero-based cardinal number of the compute node in
the pool to connect to as listed by `grls`
* `--nodeid` is the node id to connect to in the pool

Просмотреть файл

@ -59,8 +59,7 @@ Which will output some text similar to the following:
>> Terminate your session with CTRL+C
>> If you cannot terminate your session cleanly, run:
shipyard pool ssh --nodeid tvm-1518333292_4-20170428t151941z
sudo docker kill 9e7879b8
shipyard pool ssh --nodeid tvm-1518333292_4-20170428t151941z sudo docker kill 9e7879b8
```
With a web browser, navigate to http://localhost:6006/ where Tensorboard

Просмотреть файл

@ -68,8 +68,7 @@ Which will output some text similar to the following:
>> Terminate your session with CTRL+C
>> If you cannot terminate your session cleanly, run:
shipyard pool ssh --nodeid tvm-1518333292_4-20170428t151941z
sudo docker kill 9e7879b8
shipyard pool ssh --nodeid tvm-1518333292_4-20170428t151941z sudo docker kill 9e7879b8
```
With a web browser, navigate to http://localhost:6006/ where Tensorboard

Просмотреть файл

@ -822,17 +822,18 @@ def fs_cluster_status(ctx, storage_cluster_id, detail, hosts):
type=int)
@click.option(
'--hostname', help='Hostname of remote fs vm to connect to')
@click.argument('command', nargs=-1)
@common_options
@fs_cluster_options
@aad_options
@pass_cli_context
def fs_cluster_ssh(ctx, storage_cluster_id, cardinal, hostname):
def fs_cluster_ssh(ctx, storage_cluster_id, cardinal, hostname, command):
"""Interactively login via SSH to a filesystem storage cluster virtual
machine in Azure"""
ctx.initialize_for_fs()
convoy.fleet.action_fs_cluster_ssh(
ctx.compute_client, ctx.network_client, ctx.config,
storage_cluster_id, cardinal, hostname)
storage_cluster_id, cardinal, hostname, command)
@fs.group()
@ -1157,16 +1158,17 @@ def pool_dsu(ctx):
type=int)
@click.option(
'--nodeid', help='NodeId of compute node in pool to connect to')
@click.argument('command', nargs=-1)
@common_options
@batch_options
@keyvault_options
@aad_options
@pass_cli_context
def pool_ssh(ctx, cardinal, nodeid):
def pool_ssh(ctx, cardinal, nodeid, command):
"""Interactively login via SSH to a node in the pool"""
ctx.initialize_for_batch()
convoy.fleet.action_pool_ssh(
ctx.batch_client, ctx.config, cardinal, nodeid)
ctx.batch_client, ctx.config, cardinal, nodeid, command)
@pool.command('delnode')