Forum Discussion
dvalve_376192
Nov 05, 2018Nimbostratus
python show running-config
I am trying to get a Python script to output the running config of my F5, to show everything from authentication to pools to ntp settings. With TMSH/SSH it's so easy doing 'show running-config' and t...
- 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)
omkar1
Nimbostratus
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
ngcarabajal
Apr 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
DevCentral Quicklinks
* 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
Discover DevCentral Connects