Forum Discussion

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

how to use REST API using F5 SDK

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 I tried using the update method but I get an error, shown at the bottom

 

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 } }

 

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

 

p_collections = mgmt.tm.asm.policies_s.get_collection() for p_object in p_collections: policy=mgmt.tm.asm.policies_s.policy.load(id=p_object.id) policy.update(description="bar", learningMode="automatic")

 

UnsupportedOperation Traceback (most recent call last) /home/jaekim711/f5/test2.py in () 21 print p_object.allowedResponseCodes 22 policy=mgmt.tm.asm.policies_s.policy.load(id=p_object.id) ---> 23 policy.update(description="bar", learningMode="automatic") 24 25

 

 

/usr/lib/python2.7/site-packages/f5/bigip/resource.pyc in update(self, **kwargs) 1286 """ 1287 raise UnsupportedOperation( -> 1288 "%s does not support the update method" % self.__class__.__name__ 1289 ) 1290

 

UnsupportedOperation: Policy does not support the update method

 

3 Replies

  • 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)
    policy.update(description="bar", learningMode="automatic")
    
  • [root@localhost f5] ipython test2.py {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]

    UnsupportedOperation Traceback (most recent call last) /home/jaekim711/f5/test2.py in () 21 print p_object.allowedResponseCodes 22 policy=mgmt.tm.asm.policies_s.policy.load(id=p_object.id) ---> 23 policy.update(description="bar", learningMode="automatic") 24 25

     

     

    /usr/lib/python2.7/site-packages/f5/bigip/resource.pyc in update(self, **kwargs) 1286 """ 1287 raise UnsupportedOperation( -> 1288 "%s does not support the update method" % self.__class__.__name__ 1289 ) 1290

     

    UnsupportedOperation: Policy does not support the update method

     

  • Hi Jae,

     

    I was able to modify the ASM policy using the modify method - I use Python 3.6 so my code is slightly different

     

    Here's the code I used

     

    from f5.bigip import ManagementRoot
    bigip = ManagementRoot('ipaddress', 'admin', 'admin')
    
    asm = bigip.tm.asm.policies_s
    
    for policy in asm.get_collection():
        print('Before policy description change: ' + policy.description)
        print('Before policy description change: ' + policy.learningMode)
        policy.modify(description='test')
        policy.modify(learningMode='manual')
        print('After policy description change: ' + policy.description)
        print('After policy description change: ' + policy.learningMode)

    Here's the output of the script the first time it is run

     

    Before policy description change: myasmpolicy
    Before policy description change: automatic
    After policy description change: test
    After policy description change: manual

    Here's the output of the script the second time it is run - You can notice the values in the policy are now different

     

    Before policy description change: test
    Before policy description change: manual
    After policy description change: test
    After policy description change: manual

    Hope this helps

     

    Also I would advise not to post public IP Addresses on public forums