07-Mar-2023 02:06
Hi,
I'm trying to use Parallel-SSH (Python library) to connect to F5 BigIP.
08-Mar-2023 14:16
This seems like a question @JRahm may be able to answer!
08-Mar-2023 15:36 - edited 08-Mar-2023 16:08
For anyone else trying to get this to work on Mac...first:
Will post back on details if I can get it talking to BIG-IP. Just took a minute to get through the pip errors for this module.
UPDATE: Got it working. Works with password or key file if you copied your ssh keys to BIG-IP.
from pssh.clients import ParallelSSHClient
hosts = ['ltm1.test.local', 'ltm2.test.local']
#client = ParallelSSHClient(hosts, user='root', password='default')
client = ParallelSSHClient(hosts, user='root', pkey='/Users/justme/.ssh/id_rsa')
cmd = 'tmsh list ltm pool'
output = client.run_command(cmd)
for host_out in output:
for line in host_out.stdout:
print(line)
### One output for brevity ###
/Users/justme/PycharmProjects/playground/venv/bin/python /Users/justme/PycharmProjects/playground/sshtest.py
ltm pool nginx-pool {
members {
172.16.102.5:http {
address 172.16.102.5
session monitor-enabled
state up
}
}
monitor http
}
Process finished with exit code 0
09-Mar-2023 00:15
Thanks, @JRahm. Now I see that I wasn't crystal clear, I was using the single host client in Parallel-SSH. See examples for both single and multi host here: https://pypi.org/project/parallel-ssh/
I can adapt my code to this solution as well. But I still wonder if it's a problem with the single host client in the Parallel-SSH library.
Here's an example that works in Paramiko:
from paramiko.client import SSHClient
p = SSHClient()
p.load_system_host_keys()
p.connect('<IP>', username=<username>, password=<password>)
stdin, stdout, stderr = p.exec_command('uname')
print(stdout.read().decode())
And here's the code using single host client in Parallel-SSH that fails:
import pssh.exceptions
from pssh.clients import SSHClient
s = SSHClient('<IP>',user=<username>, password=<password>, timeout=5, num_retries=1)
res = s.run_command("uname")
print(res)
for line in res.stdout:
print(line)
09-Mar-2023 14:21
Hi @Eljay ... This also works just fine for me (both with key or password):
from pssh.clients import SSHClient
host = 'ltm15.test.local'
s = SSHClient(host, user='root', password='default')
# s = SSHClient(host, user='root', pkey='/Users/justme/.ssh/id_rsa')
cmd = 'tmsh list ltm pool'
res = s.run_command(cmd)
print(res)
for line in res.stdout:
print(line)
Output:
/Users/justme/PycharmProjects/playground/venv/bin/python /Users/justme/PycharmProjects/playground/sshtest.py
host=ltm15.test.local
alias=None
exit_code=None
channel=<ssh2.channel.Channel object at 0x107c46ef0>
exception=None
encoding=utf-8
read_timeout=None
ltm pool nginx-pool {
members {
172.16.102.5:http {
address 172.16.102.5
session monitor-enabled
state up
}
}
monitor http
}
Process finished with exit code 0
My versions:
13-Mar-2023 04:56
Thanks, @JRahm. There's hardly any difference between your and my code.
My Python version is 3.9, the libraries are the same as yours and I have tested toward BigIP v151.5.1, v15.1.6 (Eng hotfix) and v16.1.x. Still the same problem. I'll try to upgrade Python and reinstall the libraries.
15-Mar-2023 12:28
any luck? Wondering if you're using root or an alternative account?
22-Mar-2023 06:14
No, I haven't got this working yet. I'll make a workaround with Paramiko because I know that works. I will finish this project first, and try again Parallell-SSH later.
I use the root user. It works with Paramiko, but fails with Paralllell-SSH.