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

Filter by:
  • Solution
  • Technology
Answers

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 f5.bigip 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

0
Rate this Question
Comments on this Question
Comment made 24-May-2017 by Jae Hong Kim 74

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

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

from f5.bigip 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")
0
Comment made 24-May-2017 by Jae Hong Kim 74

[root@localhost f5]# ipython test2.py {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/policies?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/signatures?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/violations?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/signature-statuses?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/refinements?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/signature-systems?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/file-transfer?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/attack-types?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/sub-violations?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/tasks?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/scraping-extensions?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/signature-update?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/search-engines?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/policy-templates?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/http-methods?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/signature-sets?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/events?ver=12.1.0'}} {u'reference': {u'link': u'https://localhost/mgmt/tm/asm/file-content-detection-formats?ver=12.1.0'}} rest-api-07 pwlpR2LJzxplAjAR3lp10g tm:asm:policies:policystate https://localhost/mgmt/tm/asm/policies/pwlpR2LJzxplAjAR3lp10g?ver=12.1.0

[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

0

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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

0