summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2015-03-24 20:01:44 +0200
committerLars Wirzenius <liw@liw.fi>2015-03-24 20:01:44 +0200
commit8025fd6198bd9a5ff40cb3acd110408c5e7b27be (patch)
tree63acba2100a7b6e760f7c3bccfa085b3d2f69057
parent569df8a5959cd8ef46f78c9497461240a5aa1123 (diff)
parent17eb28a1cd1c20fd304361b24eb6e20dfe9c8ebe (diff)
downloadcliapp-8025fd6198bd9a5ff40cb3acd110408c5e7b27be.tar.gz
Add ssh_options to ssh_runcmd
-rw-r--r--NEWS6
-rw-r--r--cliapp/runcmd.py26
2 files changed, 23 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index f600b9c..7c1e324 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,12 @@
NEWS for cliapp
===============
+Version 1.UNRELEASED
+------------------
+
+* Lars Wirzenius added the `ssh_options` keyword argument to
+ `cliapp.ssh_runcmd`.
+
Version 1.20150305
------------------
diff --git a/cliapp/runcmd.py b/cliapp/runcmd.py
index 5ac8da5..2780755 100644
--- a/cliapp/runcmd.py
+++ b/cliapp/runcmd.py
@@ -293,6 +293,11 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover
``cliapp.ssh_runcmd('user@host', ['sudo', 'ls'], tty=True)``
which is more intuitive.
+ Arbitrary command line options to the ssh command can be given
+ with the ``ssh_options`` argument. For example:
+ ``cliapp.ssh_runcmd(
+ 'user@host', ['sudo', 'ls'], ssh_options=['-oStrictHostChecking=no'])``
+
The target is given as-is to ssh, and may use any syntax ssh
accepts.
@@ -305,16 +310,19 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover
'''
- tty = kwargs.get('tty', None)
+ ssh_argv = ['ssh']
+
+ tty = kwargs.pop('tty', None)
if tty:
- ssh_cmd = ['ssh', '-tt', target, '--']
+ ssh_argv.append('-tt')
elif tty is False:
- ssh_cmd = ['ssh', '-T', target, '--']
- else:
- ssh_cmd = ['ssh', target, '--']
- if 'tty' in kwargs:
- del kwargs['tty']
+ ssh_argv.append('-T')
- local_argv = ssh_cmd + map(shell_quote, argv)
- return runcmd(local_argv, **kwargs)
+ more_options = kwargs.pop('ssh_options', [])
+ ssh_argv.extend(more_options)
+
+ ssh_argv.append(target)
+ ssh_argv.append('--')
+ local_argv = ssh_argv + map(shell_quote, argv)
+ return runcmd(local_argv, **kwargs)