Forum Discussion

Jae_Hong_Kim_32's avatar
Jae_Hong_Kim_32
Icon for Nimbostratus rankNimbostratus
May 24, 2017

F5 SDK usage with ASM

Where can I get sample code for using ASM with F5 SDK I ran the following code.

 

from import BigIP import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning

 

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

 

mgmt = BigIP("192.168.199.241", "admin", "admin")

 

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()

 

I got the following result.

 

Traceback (most recent call last): File "test.py", line 10, in pools = mgmt.tm.ltm.pools.get_collection() File "/usr/lib/python2.7/site-packages/f5/bigip/mixins.py", line 102, in getattr raise AttributeError(error_message) AttributeError: 'f5.bigip.BigIP'>' object has no attribute 'tm'

 

4 Replies

  • Anesh's avatar
    Anesh
    Icon for Cirrostratus rankCirrostratus

    For code examples using REST API, you can take a look at this article and and you can use this SDK

     

  • Anesh's avatar
    Anesh
    Icon for Cirrostratus rankCirrostratus

    can you provide the output of the below code

     

    from f5.bigip import ManagementRoot
    mgmt = ManagementRoot("192.168.199.241", "admin", "admin")
    
    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

    Also when pasting code, please ensure to keep formatting for readability

     

  • I executed the following code

    import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning

     

    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

     

    from import ManagementRoot

     

    mgmt = ManagementRoot("70.60.207.94", "admin", "admin")

     

    collection = mgmt.tm.asm.get_collection()

     

    for anobject in collection:

     

    print anobject

    p_collections = mgmt.tm.asm.policies_s.get_collection() for p_object in p_collections:

     

    print p_object.name
    print p_object.id
    print p_object.kind
    print p_object.selfLink
    print p_object.allowedResponseCodes
    policy=mgmt.tm.asm.policies_s.policy.load(id=p_object.id)

    I got the following results

     

    {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} {u'reference': {u'link': u''}} rest-api-07 pwlpR2LJzxplAjAR3lp10g tm:asm:policies:policystate [400, 401, 404, 407, 417, 503]

     

    All is good so far.

     

    The following REST API would pass the Request data for arguments. I am trying to figure out how to the equivalent (pass arguments) the using using the F5 SDK

     

    https://{{big_ip_a_mgmt}}/mgmt/tm/asm/policies?ver=12.1.0 Request Data { "fullPath":"/Common/rest-api_12", "active":"true", "virtualServers":[], "enforcementMode": "transparent", "description":"none", "applicationLanguage":"utf-8", "policy-builder":"disabled", "learningMode":"manual", "stagingSettings": { "signatureStaging": true, "placeSignaturesInStaging": false, "enforcementReadinessPeriod": 7 } }

     

  • Anesh's avatar
    Anesh
    Icon for Cirrostratus rankCirrostratus

    That would be a new question don't you think, as i already helped with the error you are facing in your code which was the original question, Please accept the answer and open a new question