Forum Discussion
python show running-config
- Nov 21, 2018
I was able to get the running config to show with Python, please see the code below:
from f5.bigip import ManagementRoot mgmt = ManagementRoot("your_f5_ip", 'username', 'password') x = mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs='-c "tmsh show running-config"') print(x.commandResult)
It aint pretty , but it should do the trick, one possible improvment would be implementing list with all commands you need and for loop
import paramiko,time
device_1 = '172.16.1.53'
devices = [device_1]
username = 'cisco'
password = 'cisco'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for device in devices:
ssh.connect(device, username=username, password=password,allow_agent=False,look_for_keys=False)
file_template = 'output.{}.txt'.format(device)
with open(file_template, 'wb') as file_handler:
channel = ssh.invoke_shell()
channel.send('term length 0\n')
time.sleep(2)
out = channel.recv(9999)
channel.send('show running-config\n')
time.sleep(15)
out = channel.recv(9999)
file_handler.write(out)
file_handler.close()
ssh.close()
If you want to do bunch of "show's" on your F5 devices this will do the trick,sadly new library netmiko (from Kirk Byers) doesnt provide much methods for F5 , but if you would like to do some configuration based on templates i strongly suggest using terraform from Hashicorp (LTM) https://www.hashicorp.com/blog/new-terraform-providers-f5-nutanix-tencent-helm.
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