args.extend(['-o', 'StrictHostKeyChecking=no'])
if gw:
- if gwuser:
- proxycommand = 'ProxyCommand=ssh -q %s@%s -W %%h:%%p' % (gwuser, gw)
- else:
- proxycommand = 'ProxyCommand=ssh -q %%r@%s -W %%h:%%p' % gw
+ proxycommand = _proxy_command(gw, gwuser, identity)
args.extend(['-o', proxycommand])
if agent:
args.append('-P%d' % port)
if gw:
- if gwuser:
- proxycommand = 'ProxyCommand=ssh -q %s@%s -W %%h:%%p' % (gwuser, gw)
- else:
- proxycommand = 'ProxyCommand=ssh -q %%r@%s -W %%h:%%p' % gw
+ proxycommand = _proxy_command(gw, gwuser, identity)
args.extend(['-o', proxycommand])
if recursive:
:param sudo: Flag forcing execution with sudo user
:type sudo: bool
- :rtype: touple
+ :rtype: tuple
(stdout, stderr), process
proc.wait()
return (stdout, stderr)
+def _proxy_command(gw, gwuser, gwidentity):
+ """
+ Constructs the SSH ProxyCommand option to add to the SSH command to connect
+ via a proxy
+ :param gw: SSH proxy hostname
+ :type gw: str
+
+ :param gwuser: SSH proxy username
+ :type gwuser: str
+
+ :param gwidentity: SSH proxy identity file
+ :type gwidentity: str
+
+
+ :rtype: str
+
+ returns the SSH ProxyCommand option.
+ """
+
+ proxycommand = 'ProxyCommand=ssh -q '
+ if gwidentity:
+ proxycommand += '-i %s ' % os.path.expanduser(gwidentity)
+ if gwuser:
+ proxycommand += '%s' % gwuser
+ else:
+ proxycommand += '%r'
+ proxycommand += '@%s -W %%h:%%p' % gw
+
+ return proxycommand