Forum Discussion
iControl library for Python
Is there a python library available for iControl REST calls?
6 Replies
- John_Gruber_432Historic F5 Account
Michael,
Short answer.. not to my knowledge.
Long answer... Python requests package has everything you need to make REST calls and fully interogate the the response from the BIG-IP. Using iControl REST with python requests is really easy. You'll need the json package too, but that comes with pythong 2.7+, otherwise simplejson is available via pip or typically your OS's package management.
Basic workflow is:
1) create a requests session 2) get the REST URI to manage your object 3) call the get (list), post (create), put (update), or delete (delete) request method for URI on your requests session
Here is a quick barebone example off the top of my head:
import json import requests username = [your BIG-IP user] password = [your BIG-IP password] hostname = [your BIG-IP host] setup up a requests session icr_session = requests.session() icr_session.auth = (username, password) not going to validate the HTTPS certifcation of the iControl REST service icr_session.verify = False we'll use JSON in our request body and expect it back in the responses icr_session.headers.update({'Content-Type': 'application/json'}) this is the base URI for iControl REST icr_url = '' % hostname Simple example - get all LTM pool attributes folder = [your folder name] pool_name = [your pool name] add the module URI parts request_url += icr_url + '/ltm/pool/' here is an example of calling an object explicitly. request_url += '~' + folder + '~' + pool_name call the get method on your requests session response = icr_session.get(request_url) look at the response if response.status_code < 400: response_obj = json.loads(response.text) print "response %s" % response_objIf you learn how to use the '$filter=partition eq ' + folder' query varibale to limit the query scope to a specific folder and the '$select=name,description...' to limit the attributes returned on your BIG-IP objects, you will be off and running.
I typically prototyping my REST calls in Google Chrome browser POSTMAN application. You'll see the URI, query variables, JSON inputs and outputs required to get exactly what you want from the BIG-IP. Makes it nice, simple, and quick.
- Michael_A__Wood
Nimbostratus
Thank you John. Good information.... - IRONMAN_183357
Nimbostratus
Nice info,
I will try
- IRONMAN_183357
Nimbostratus
Hi,
Can you help me, i am getting below error when i try to connect the F5 box
username= 'admin' password= 'admin' hostname= '35.154.69.72' icr_session = requests.session() icr_session.auth = (username, password) icr_session.verify = False icr_session.headers.update({'Content-Type': 'application/json'})
icr_url = '' % hostname Traceback (most recent call last): File "", line 1, in icr_url = '' % hostnameTypeError: not enough arguments for format string
- shaggy
Nimbostratus
For future finders of this post:
F5 Friday: Python SDK for BIG-IP
https://github.com/F5Networks/f5-common-python
- rathid
Nimbostratus
what is folder name refer to ?
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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