cancel
Showing results for 
Search instead for 
Did you mean: 
Lori_MacVittie
F5 Employee
F5 Employee

0151T000003d5rOQAQ.png

We know programmability is important. Whether we’re talking about networking and SDN, or DevOps and APIs and templates, the most impactful technologies and trends today are those involving programmability. 0151T000003d6nmQAA.png

F5 is, as you’re no doubt aware, no stranger to programmability. Since 2001 when we introduced iControl (API) and iRules (data path programmability) we’ve continued to improve, enhance, and expand the ability of partners, customers, and our own engineers and architects to programmatically control and redefine the application delivery experience.

With the emphasis today on automation and orchestration as a means for ops (and through it, the business) to scale more quickly and efficiently, programmability has never before been so critical to both operational and business success.

Which means we can’t stop improving and expanding the ways in which you (and us, too) can manage, extend, and deliver the app services everyone needs to keep their apps secure, fast, and available.

Now, iControl and iControl REST are both APIs built on open standards like SOAP, JSON, and HTTP. That means anyone who knows how to use an API can sit down and start coding up scripts that automate provisioning, configuration, and general management of not just BIG-IP (the platform) but the app services that get deployed on that platform.

And we’re not against that at all. But we also recognize that not everyone has the time to get intimately familiar with iControl in either of its forms. So we’re pretty much always actively developing new (and improving existing) software development kits (SDKs) that enable folks to start doing more faster. But so are you. We’ve got a metric ton of code samples, libraries, and solutions here on DevCentral that have been developed by customers and partners alike. They’re freely available and are being updated, optimized, extended and re-used every single day. We think that’s a big part of what an open community is – it’s about developing and sharing solutions to some of the industry’s greatest challenges.

And that’s what brings us to today’s exciting news. Well, exciting if you’re a Python user, at least, because we’re happy to point out the availability of the F5 BIG-IP Python SDK. And not just available to download and use, but available as an open source project that you can actively add, enhance, fork, and improve. Because open source and open communities produce some amazing things.

This project implements an SDK for the iControl REST interface for BIG-IP, which lets you create, edit, update, and delete (CRUD) configuration objects on a BIG-IP. Documentation is up to date and available here.

The BIG-IP Python SDK layers an object model over the API and makes it simpler to develop scripts or integrate with other Python-based frameworks. The abstraction is nice (and I say that with my developer hat on) and certainly makes the code more readable (and maintainable, one would assume) which should help eliminate some of the technical debt that’s incurred whenever you write software,  including operational scripts and software. 

Seriously, here’s a basic sample from the documentation:

from f5.bigip import BigIP

# Connect to the BigIP
bigip = BigIP("bigip.example.com", "admin", "somepassword")

# Get a list of all pools on the BigIP and print their name and their
# members' name
pools = bigip.ltm.pools.get_collection()
for pool in pools:
    print pool.name
    for member in pool.members:
        print member.name

# Create a new pool on the BigIP
mypool = bigip.ltm.pools.pool.create(name='mypool', partition='Common')

# Load an existing pool and update its description
pool_a = bigip.ltm.pools.pool.load(name='mypool', partition='Common')
pool_a.description = "New description"
pool_a.update()

# Delete a pool if it exists
if bigip.ltm.pools.pool.exists(name='mypool', partition='Common'):
    pool_b = bigip.ltm.pools.pool.load(name='oldpool', partition='Common')
    pool_b.delete()

Isn’t that nice? Neat, understandable, readable. That’s some nice code right there (and I’m not even a Python fan, so that’s saying something). Don’t let the OpenStack reference fool you. While the first “user” of the SDK is OpenStack, it is stand-alone and can be used on its own or incorporated into other Python-based frameworks.

So if you’re using Python (or were thinking about) to manage, manipulate, or monitor your BIG-IPs, check this one out. Use it, extend it, improve it, and share it. 

Happy scripting!

Comments
Great to see. Will BIG-IQ get a similar SDK?
JRahm
Community Manager
Community Manager
Not a python fan?!? We might not be able to be friends any longer...I'll consult myself over the weekend and let you know.
thanks for sharing
does it work with python 3?
JG
Cumulonimbus
Cumulonimbus

I have just tried some of this code, but got the following error:

 

Traceback (most recent call last): File "./f5_icontrolREST_test.py", line 20, in for member in pool.members: File "/usr/local/lib/python2.7/dist-packages/f5/bigip/mixins.py", line 82, in __getattr__ raise AttributeError(error_message) AttributeError: '' object has no attribute 'members'

and I am pretty sure that pool has a member defined. I am on v11.6.1.

 

JG
Cumulonimbus
Cumulonimbus

I have found out what went wrong now. This works:

 

pools = mgmt.tm.ltm.pools.get_collection() for pool in pools: print pool.name for member in pool.members_s.get_collection(): print member.name
Eric_Chen
F5 Employee
F5 Employee

Updated example. Previous example from the article reflects an earlier release of the F5 Python SDK:

 

from f5.bigip import ManagementRoot Connect to the BigIP mgmt = ManagementRoot("bigip.example.com", "admin", "somepassword") Get a list of all pools on the BigIP and print their names and their members' names pools = mgmt.tm.ltm.pools.get_collection() for pool in pools: print pool.name for member in pool.members_s.get_collection(): print member.name Create a new pool on the BIG-IP mypool = mgmt.tm.ltm.pools.pool.create(name='mypool', partition='Common') Load an existing pool and update its description pool_a = mgmt.tm.ltm.pools.pool.load(name='mypool', partition='Common') pool_a.description = "New description" pool_a.update() Delete a pool if it exists if mgmt.tm.ltm.pools.pool.exists(name='mypool', partition='Common'): pool_b = mgmt.tm.ltm.pools.pool.load(name='mypool', partition='Common') pool_b.delete()
Hannes_Rapp
Nimbostratus
Nimbostratus

@Sebastian. You can use it with Python 3. (Have tested with Py 3.4.3)

 

"pip3 install f5-sdk"

 

michaelc0n_6121
Nimbostratus
Nimbostratus

What about py 2.7 support? (Just asking ) thx!

 

Ed_Summers
Nimbostratus
Nimbostratus

Has this been updated to enable token authentication when using v12 or later with an external authentication source? Are examples available for that scenario?

 

David_Carlson
Nimbostratus
Nimbostratus

I'm trying part of the sample code to learn this and I'm getting security warnings.

 

InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.htmlssl-warnings

 

After reading the information listed and applying the code cited I still get the same error. I've tried disabling warnings as well as verifying the certs but neither works. Anyone have any ideas as to what I'm doing wrong? Thank you..

 

import urllib3 urllib3.disable_warnings() import certifi import urllib3 http = urllib3.PoolManager( cert_reqs='CERT_REQUIRED', ca_certs=certifi.where()) import requests from f5.bigip import BigIP Connect to the BigIP bigip = BigIP("address", "admin", "pw") Get a list of all pools on the BigIP and print their name and their members' name pools = bigip.ltm.pools.get_collection() for pool in pools: print (pool.name) for member in pool.members_s.get_collection(): print (member.name)

David:

 

Try adding these lines:

 

from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
David_Carlson
Nimbostratus
Nimbostratus

That did it.. Thank you..

 

__J___262279
Nimbostratus
Nimbostratus

Nice, why did this just pop up in my top search when I just finished writing almost the exact same module for powershell? This could have saved me some long weeks! But nice to see more lang SDKs popping up and growing.

 

Eljay
Altostratus
Altostratus

I get an SDK-error in Python 3 (AttributeError: 'dict' object has no attribute 'iteritems') when I use "....ltm.virtuals.virtual.load(partition=virtual.partition, name=virtual.name)". I googled it and a user on Stackoverflow.com says that "iteritems()" has been removed in Python 3. Is there a way to make a workaround or do I have to downgrade Python from v3 to v2.x? I'm a Python noob, so please bear with me.

 

David_Carlson
Nimbostratus
Nimbostratus

Try the update listed in this thread. https://github.com/F5Networks/f5-common-python/issues/869issuecomment-271106043 I'm not a programmer, just learning Python 3 and had a similar issue. The explanation of how to get the update is toward the bottom.

 

Eljay
Altostratus
Altostratus

Thanks a lot, David.

 

Just for the record, all I did was running this command and my problem was solved: "pip install --upgrade git+;

 

David_Carlson
Nimbostratus
Nimbostratus

Yes they fixed the code but being a newbie myself I didn't know I needed to install git as well. That was the thread I started so as you can see I am learning 🙂

 

Kurt_Kite_11866
Nimbostratus
Nimbostratus

First, thanks very much for the SDK! It is very useful. I have been playing around with creating pools and virtual servers. I have run into the following error when trying to add profiles to a virtual server. The code is as follows:

 

myvirtual = bigip.ltm.virtuals.virtual.create(name="testvirtual", destination="10.25.32.53:443", ipProtocol="tcp", pool="testpool") profiles = myvirtual.profiles_s profile = myvirtual.profiles_s.profiles myvirtual.profiles_s.profiles.create(partition="Common",name="tcp-lan-optimized")

 

The error:

 

raise iControlUnexpectedHTTPError(error_message, response=response)

icontrol.exceptions.iControlUnexpectedHTTPError: 400 Unexpected Error: Bad Request for uri: https://10.25.46.19:443/mgmt/tm/ltm/virtual/~Common~testvirtual/profiles/ Text: u'{"code":400,"message":"01070097:3: Virtual server /Common/testvirtual lists duplicate profiles.","errorStack":[],"apiError":3}'

 

If I get the virtual details I see that there is a tcp profile assigned, I assume by default, when the virtual is created. Do I need to remove this default profile before I create the one that I want? I am able to create "http" and "oneconnect" profiles using the above method without any issues.

 

Kurt_Kite_11866
Nimbostratus
Nimbostratus

I figured out that I had to delete tcp profile before I created the tcp-lan-optimized profile and both had to be wrapped in a transaction.

 

Now, I'm stuck on how to assign iRules to the virtual. Anybody have an example of that? I am not able to figure it out from the API documentation.

 

Joel_Breton
Nimbostratus
Nimbostratus

Hi Kurt,

 

Could you past an example of the code you used to delete and create profiles in a transaction.

 

I figured out that I had to delete tcp profile before I created the tcp-lan-optimized profile and both had to be wrapped in a transaction.

Thanks

 

Kurt_Kite_11866
Nimbostratus
Nimbostratus

Hi Joel,

 

You can find the code in this thread:

 

https://tstdmzdevcentral.olympus.f5net.com/questions/python-sdk-assign-irules-to-a-virtual-server-51...

 

Best Regards, Kurt

 

IRONMAN
Cirrostratus
Cirrostratus

Hi All,

 

Any one brief me, How i Create SDK for my F5 pair box . I am new to python, i am leaning it I am new to SDK and Icontrol rest

 

Brief me, what all things i do and create SDk and how to use it? Thanks Saravanan K

 

Lee_He_332377
Nimbostratus
Nimbostratus

I used the F5BIGIPv10.1,but the API interface is . I want to use python to write the code to disabled a Pool Member. Can anyone tell me how to use the old API??

 

Peter_Brehaut2
Nimbostratus
Nimbostratus

Is it possible to authenticate using tokens without using an admin account using the SDK? I want to give access to an application team to control their nodes without handing out the admin password.

 

sagil_351004
Nimbostratus
Nimbostratus

I am looking for an option to format the raw output. The below output that my scrpt delivers is in a very scrambled format, Any suggestions ?

 

pool2.raw

 

.Pools object at 0x0342C730>, 'minimum_additional_parameters': set([]), 'exclusi ve_attributes': [], 'allowed_commands': [], 'read_only_attributes': [], 'allowed _lazy_attributes': [f5.bigip.tm.ltm.pool.Members_s'>, f5.bigip.r esource.Stats'>], 'uri': u'https://192.168.45.128:443/mgmt/tm/ltm/pool/~Common~L B-POOL-210/', 'required_json_kind': 'tm:ltm:pool:poolstate', 'bigip': <.

 

m9maganti_36891
Nimbostratus
Nimbostratus

Hi All, I am trying to get the pools members and their current state from GTM. I tried the code which is given on the site…… but it didn’t work. Code: from import BigIP

 

Connect to the BigIP

bigip = BigIP("bigip.example.com", "admin", "somepassword")

 

Get a list of all pools on the BigIP and print their name and their members' name

pools = bigip.gtm.pools.get_collection() for pool in pools: print pool.name for member in pool.members: print member.name Error: print pool.name AttributeError: there is no name element in the dict

 

Apparently F5 sdk is not working as expected. gym pools.pool doesn’t work neither I am not able to fetch the names of the pool. Can someone help?

 

Cameron_Merrick
Altostratus
Altostratus

Hello!

 

I am wondering what sort of use cases exist for using this SDK, iControl REST, and even programmatic interfacing with BIG-IP's in general. In my environment we have a few F5s, but it seems like the prospect of deploying another one seems unlikely and if so it would only be one or two at the most, so automating deployments is the obvious thing that comes to mind but what is the use case for needing that?

 

The only other use case that seems self evident to me involves using programmatic means to print out the config for a BIG-IP (the pools, nodes, etc) in order to examine the diff with another config side by side which is easier to do in a text based environment rather than manually clicking through a GUI.

 

I am sure there are tons of use cases I am not thinking of or not aware of, so please let me know what sort of practical things can be built with this because I would love to use it in my production environment.

 

Regards, -cmm-

 

Naumin_Dave_144
Nimbostratus
Nimbostratus

is there a way to detach ssl profile from virtual server configuration?

 

Kurt_Kite_11866
Nimbostratus
Nimbostratus

Hi Dave,

 

What do you mean by detach? Do you want to remove/delete the SSL profile from the virtual? I have not done that via the API for a profile, but I have done it for policies and since they are both collections I assume that the process is the same. 1. Load the virtual 2. Load the profile collection 3. Delete the SSL profile 4. Update the virtual.

 

Best Regards, Kurt

 

Naumin_Dave_144
Nimbostratus
Nimbostratus

Hi Kurt,

 

Thanks for your response. Yes i want to remove SSL profile from VS configuration.

 

Thats the exact flow i am going to follow but can i have a REST API code logic for this?

 

Kurt_Kite_11866
Nimbostratus
Nimbostratus

I'm traveling today. I can post it later tonight or tomorrow.

 

/Kurt

 

Kurt_Kite_11866
Nimbostratus
Nimbostratus

Hi,

 

You can try this:

 

virtual = bigip.ltm.virtuals.virtual.load(partition="Common",name="") for profile in virtual.profiles_s.get_collection(): if profile.name == "": profile.delete()

 

Kurt_Kite_11866
Nimbostratus
Nimbostratus

Oops, noticed the formatting screwed up some of the statements.

 

You need to insert the name of the virtual server on line 1 and the name of the profile on line 3.

 

For example: name="virtual name"

 

/Kurt

 

Mohammed_M_Irfa
Nimbostratus
Nimbostratus

Hi,

 

Can any one help me to deploy the F5 Python SDK, as i am new!

 

I am working on F5 appliance, like: LTM, GTM.

 

  1. How to install and use F5 python SDK?

     

  2. I have setup BIG-IP F5 vLab locally for my practise and knowledge, on VMware i have installed F5, Backend Servers.

     

After gone through the above article, i found an interested.

 

Please guide me to enter in this technology. As i finding for but fails to find.

 

Thanks

 

Mohammed

 

fanta_377379
Nimbostratus
Nimbostratus

Hello Mohammed, I know it is super late You need to install f5-sdk first: run pip in command line: 1- pip install f5-sdk 2- import at the beginning of your script: from import ManagementRoot 3- Connect to your bigip mgmt = ManagementRoot ("bigip-IPaddress", "username", "password")

 

Version history
Last update:
‎11-Mar-2016 07:00
Updated by:
Contributors