def create_worker(host): config = SSHConfig() proxy = None if os.path.exists(os.path.expanduser('~/.ssh/config')): with open(os.path.expanduser('~/.ssh/config')) as f: config.parse(f) if host.hostname is not None and 'proxycommand' in config.lookup( host.hostname): proxy = ProxyCommand(config.lookup(host.hostname)['proxycommand']) worker = SSHClient() worker.load_system_host_keys() worker.set_missing_host_key_policy(AutoAddPolicy()) # store data for later reference worker.host = host.hostname worker.username = host.username worker.password = host.password worker.key_filename = host.key_filename worker.connect(hostname=host.hostname, username=host.username, password=host.password, key_filename=host.key_filename, sock=proxy) return worker