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)
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)
- omkar1Apr 25, 2020Nimbostratus
hey mike did you ever get a chance to modify data in a cleaner fashion.
I am trying to do the same thing as you are
- ngcarabajalApr 28, 2020Nimbostratus
It worked well for me. What do you mean to "modify the data".
- omkar1Apr 28, 2020Nimbostratus
i am trying to get the data in json or csv format
i have stumbled upon rest api but that i don't have access to get the data using restapi
- ngcarabajalApr 28, 2020Nimbostratus
Hey! I am actually working on that too. I don't have it JSON yet. Gonna work with a co-worker later on to do that but below is what I have that writes it to a file and parsed with a python library called ciscoconfparse. Documentation is in the comments. Hope this helps! I will reply later on when I get in JSON.
#!/usr/bin/env python3 from f5.bigip import ManagementRoot import sys from ciscoconfparse import CiscoConfParse #https://devcentral.f5.com/s/question/0D51T00006i7jW8SAI/python-show-runningconfig #https://f5-sdk.readthedocs.io/en/latest/ F5 SDK documentation #https://pypi.org/project/ciscoconfparse/ ciscoconfparse documentation mgmt = ManagementRoot('IP', 'USERNAME', 'PASSWORD') x = mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs='-c "tmsh running-config"') output = x.commandResult with open('output.conf', 'w') as f: print(output, file=f) parse = CiscoConfParse('pathtofile/output.conf', syntax='junos', comment='#') for intf_obj in parse.find_objects('auth ldap system-auth'): samaccount = intf_obj.re_match_iter_typed('\s+login-attribute\s(.*)', default="") print(samaccount) if samaccount == 'samaccountname': print("Woohoo")
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