From 559b88ff12426b9eae3585464ee2d8d4e2b8d5b5 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 16 Sep 2017 21:51:50 +0530 Subject: [PATCH] ssh: Support specifying the port too. --- mitogen/ssh.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/mitogen/ssh.py b/mitogen/ssh.py index 250a13f1..3fed607f 100644 --- a/mitogen/ssh.py +++ b/mitogen/ssh.py @@ -13,10 +13,14 @@ class Stream(mitogen.master.Stream): #: The path to the SSH binary. ssh_path = 'ssh' - def construct(self, hostname, username=None, ssh_path=None, **kwargs): + port = None + + def construct(self, hostname, username=None, ssh_path=None, port=None, + **kwargs): super(Stream, self).construct(**kwargs) self.hostname = hostname self.username = username + self.port = port if ssh_path: self.ssh_path = ssh_path @@ -24,6 +28,8 @@ class Stream(mitogen.master.Stream): bits = [self.ssh_path] if self.username: bits += ['-l', self.username] + if self.port is not None: + bits += ['-p', str(self.port)] bits.append(self.hostname) base = super(Stream, self).get_boot_command() return bits + map(commands.mkarg, base) @@ -31,3 +37,5 @@ class Stream(mitogen.master.Stream): def connect(self): super(Stream, self).connect() self.name = 'ssh.' + self.hostname + if self.port: + self.name += ':%s' % (self.port,)