Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

iControl library for Python

Is there a python library available for iControl REST calls?

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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 = '<a href="https://%s/mgmt/tm">https://%s/mgmt/tm</a>' % 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_obj

If 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.

3
Comments on this Answer
Comment made 15-Dec-2014 by Michael A. Wood 1
Thank you John. Good information....
0
Comment made 21-Aug-2017 by IRONMAN 197

Nice info,

I will try

0
Comment made 09-Oct-2017 by IRONMAN 197

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 = 'https://%s/mgmt/tm' % hostname Traceback (most recent call last): File "<pyshell#16>", line 1, in icr_url = 'https://%s/mgmt/tm' % hostnameTypeError: not enough arguments for format string

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

what is folder name refer to ?

0