fir3net
PPS-Firenetbanner-780.5x190-30-03-17

F5 - Interacting with iControl's get_instance method via BigSuds

In order to interact with the F5 via Python the best option available is bigsuds. This is a Python module allows you to interact with the F5 API iControl via a set of Python classes.

Typically you will normally find all the methods you need to interact with your F5 without issues. However, there are times that you may be unable to find the required method in order to obtain the information you require.  This is were the get_instance method comes into play. get_instance allows you to return the configuration as a string. 

Within this article we will provide the steps to obtain the network failover configuration as there is no direct method for obtaining this configuration via iControl in v10.2.4.

Import/Build Connection

First of all we import the bigsuds module and also build a connection to our F5.

>>> import bigsuds
>>> import pprint
>>> b = bigsuds.BIGIP(hostname = '10.1.1.10',username = "admin", password = "#####")

Classes

We next perform a look up through our classes to confirm the class we are interested in. Add the nessacary strings to the filter key to filter the results.

>>> pprint.pprint([x['name'] for x in b.Management.ChangeControl.get_class_info(filter="")])
['Local Traffic / Profiles / profile_mblb',
'Local Traffic / Profiles / profile_ntlm',
'System / dns',
'System / httpd',
'System / logrotate',
'System / ntp',
'System / password_policy',
'System / sshd',
'System / remote_users',
'System / syslog',
'System / ltm', 
....

Instances

Once we have our class we next to obtain the instances for the class.

>>> b.Management.ChangeControl.get_instance_info(classes=[{"name":"System / failover","transaction_id":0}])
[[{'name': 'System / failover / failover', 'transaction_id': 55485}]]

Get Config

Now that we have our instance. We can pass this to the F5 so that the configuration is returned.

>>> b.Management.ChangeControl.get_instance(instance_names=["System / failover / failover"],instance_format="FORMAT_SHELL")
[{'info': {'name': 'System / failover / failover', 'transaction_id': 55485}, 'data': 'failover {\n   network failover enable\n   peer mgmt addr 8.8.8.8\n   redundant enable\n   standby link down time 0\n   unit 2\n   unicast peer FAILOVER {\n         dest addr 8.8.8.8\n         port 1026\n         source addr 8.8.8.7\n      }\n}', 'format': 'FORMAT_SHELL'}]

Tags: BIG-IP F5, iControl

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001