You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mitogen/mitogen/ssh.py

50 lines
1.3 KiB
Python

7 years ago
"""
Functionality to allow establishing new slave contexts over an SSH connection.
"""
import commands
import mitogen.master
class Stream(mitogen.master.Stream):
python_path = 'python'
#: The path to the SSH binary.
ssh_path = 'ssh'
port = None
def construct(self, hostname, username=None, ssh_path=None, port=None,
check_host_keys=True, **kwargs):
7 years ago
super(Stream, self).construct(**kwargs)
self.hostname = hostname
self.username = username
self.port = port
self.check_host_keys = check_host_keys
7 years ago
if ssh_path:
self.ssh_path = ssh_path
def get_boot_command(self):
bits = [self.ssh_path]
bits += ['-o', 'BatchMode yes']
7 years ago
if self.username:
bits += ['-l', self.username]
if self.port is not None:
bits += ['-p', str(self.port)]
if not self.check_host_keys:
bits += [
'-o', 'StrictHostKeyChecking no',
'-o', 'UserKnownHostsFile /dev/null',
]
7 years ago
bits.append(self.hostname)
base = super(Stream, self).get_boot_command()
return bits + map(commands.mkarg, base)
def connect(self):
super(Stream, self).connect()
self.name = 'ssh.' + self.hostname
if self.port:
self.name += ':%s' % (self.port,)