impossible It is very difficult to ensure that the command runs on all servers at the same time.
But since this is an external resource, you can use the asyncio
module to manage tasks through corotines. In this way, your code will tend to run faster than you do sequentially.
If you have a list of servers, with username and password, you can do something like this:
import asyncio, asyncssh
async def update_image_force(host, user, pass):
async with asyncssh.connect(host, username=user, password=pass) as ssh:
await ssh.run('update image force http://link_FTP')
commands = asyncio.gather(*[update_image_force(server_data) for server_data in server_list])
loop = asyncio.get_event_loop()
loop.run_until_complete(commands)
The AsyncSSH documentation can be viewed here: link
The asyncio
module is native to Python for versions greater than 3.6.