A
A
Andrey Andryushchenko2018-11-28 20:50:17
Python
Andrey Andryushchenko, 2018-11-28 20:50:17

What is the best lib to use for asynchronous access to hosts via ssh?

There are several hosts that you need to visit periodically and do various things according to a certain algorithm. I tried to do this using the parallel-ssh library , but I didn’t quite like it, because it works according to the following principle: a connection is created with all hosts at once and then commands are executed simultaneously on all hosts, but often situations arise when you do not need to thoughtlessly run several commands, but you need to run different actions depending on the response on the hosts, but firstly it is inconvenient to go through the array of responses each time, and secondly, this lib launches actions on all hosts.
I also want to support asyncio, because the whole project rests on it.
The ideal option for me seems to be using a regular lib on asyncio to execute commands via ssh, just write a coroutine that would go to the host and do the necessary actions (including depending on the response to previous commands) and then asyncio.gather coroutines for each host. I tried to use this asyncssh library for this , but either I'm stupid and couldn't figure it out, or it doesn't hold a session for every command. I tried the following: I did cd /some_dirit, then pwdit returned the default directory (user directory), of course you can do this every time cd /some_dir && some-command, but this is some kind of crutch.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question