Forum Discussion

syncretism's avatar
syncretism
Icon for Nimbostratus rankNimbostratus
Aug 06, 2018

Handling Differences in v11/v12 in Python SDK for iControl REST

We're interested in using the f5 SDK (version: 3.0.18) to replace several cURL scripts that manage our LTM and GTM pools. One of the major draws here is that the SDK provides sufficient abstraction to work with the target API irrespective of iControl REST version (my cURL scripts need separate methods for v11 and v12 destinations):

$1

(https://f5-sdk.readthedocs.io/en/latest/apidoc/f5.bigip.tm.gtm.htmlf5.bigip.tm.gtm.pool.Pools)

In practice, we haven't seen this autonegotiation. Using the SDK, we've still had to employ different code to list pool and members, eg, in v11 and v12:

v11 code:

from f5.bigip import ManagementRoot
 This first block works in v11, but not v12.
print ("Getting pools with v11 syntax...")
mgmt = ManagementRoot('@option.GTM_Server@', '@option.F5_User@', '@option.F5_Password@')
api_ver = mgmt.tmos_version
pool_collection = mgmt.tm.gtm.pools.get_collection()
pools = mgmt.tm.gtm.pools

for pool in pool_collection:
    print ("Querying state of pool %s members...") % (pool.name)
    for member in pool.members_s.get_collection():
        print ("Pool member name: %s") % (member.name)
        print ("Ratio: %d") % (member.ratio)

Executing v11 code against a v12 API returns expected errors:

Getting pools with v11 syntax...
Traceback (most recent call last):

    print ("Querying state of pool %s members...") % (pool.name)
AttributeError: 'dict' object has no attribute 'name'`

v12 code:

from f5.bigip import ManagementRoot
 This first block works in v12, but not v11.
print ("Getting pools with v12 syntax...")
mgmt = ManagementRoot('@option.GTM_Server@', '@option.F5_User@', '@option.F5_Password@')
api_ver = mgmt.tmos_version
pools = mgmt.tm.gtm.pools.a_s.get_collection()

for pool in pools:
    print ("Querying state of pool %s members...") % (pool.name)
    for member in pool.members_s.get_collection():
        print ("Pool member name: %s") % (member.name)
        print ("Ratio: %d") % (member.ratio)

Executing v12 code against a v11 API returns expected errors:

pools = mgmt.tm.gtm.pools.a_s.get_collection()
  File "/usr/local/lib/python2.7/site-packages/f5/bigip/mixins.py", line 102, in __getattr__
    raise AttributeError(error_message)
AttributeError: '' object has no attribute 'a_s'

I'm not a Python programmer and will readily accept the likelihood that I'm just doing it wrong in code. Can we use the same code against different versions of the API using the SDK?

Thanks.

1 Reply

  • Hi @syncretism, this is honestly an area where I think we made it harder for the end user by sticking to the sdk design requirements of honoring the REST API endpoints. Because they changed so dramatically between v11 and v12, it's going to require using both methods to interact with the different TMOS versions. So for v11, it would be:

     

    mgmt_root.tm.gtm.pools.pool.create(name=....)

     

    and for v12 (for an a record):

     

    mgmt_root.tm.gtm.a_s.a.create(name=...)

     

    you can substitute the other methods as necessary.