Forum Discussion
Python code using Parallel-SSH library to connect to F5 BigIP
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)
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:
- python: 3.11.2
- ssh-python: 1.0.0
- ssh2-python: 1.0.0
- parallel-ssh: 2.12.0
- BIG-IP: 15.1.8.1
- EljayMar 13, 2023Cirrus
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.- JRahmMar 15, 2023Admin
any luck? Wondering if you're using root or an alternative account?
- EljayMar 22, 2023Cirrus
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.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com