return ' '.join(_quote(args))
-def execute(client, args):
+def execute(client, args, name=None):
"""
Execute a command remotely.
:param client: SSHConnection to run the command with
:param args: command to run
+ :param name: name of client (optional)
:type args: string or list of strings
Returns a RemoteProcess, where exitstatus is a callable that will
cmd = args
else:
cmd = quote(args)
- (host, port) = client.get_transport().getpeername()
- log.debug('Running [{h}]: {cmd!r}'.format(h=host, cmd=cmd))
+
+ if name:
+ host = name
+ else:
+ (host, port) = client.get_transport().getpeername()
+ log.info('Running [{h}]: {cmd!r}'.format(h=host, cmd=cmd))
+
(in_, out, err) = client.exec_command(cmd)
def get_exitstatus():
:param wait: Whether to wait for process to exit. If False, returned ``r.exitstatus`` s a `gevent.event.AsyncResult`, and the actual status is available via ``.get()``.
:param name: Human readable name (probably hostname) of the destination host
"""
- r = execute(client, args)
+ (host, port) = client.get_transport().getpeername()
+
+ if name is None:
+ name = host
+
+ r = execute(client, args, name=name)
r.stdin = KludgeFile(wrapped=r.stdin)
if logger is None:
logger = log
- (host, port) = client.get_transport().getpeername()
-
- if name is None:
- name = host
g_err = None
if stderr is not PIPE: