For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Only1masterbla1's avatar
Oct 26, 2016

How to change datagroup value by using pyhthon script (f5-sdk 1.6.0)

Hi,

 

My aim is to change data group value of /Common/zol from 'on' to 'off' by using python script. I am unable to update/set values. Please help.

 

datagroups in /Common partition aol images private_net zol

 

My sample code (basic) and output is shown below:

 

Sample script

! datagroup.py import json from import ManagementRoot import requests from requests.packages.urllib3.exceptions import InsecureRequestWarning requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

 

! Connect to the BIG-IP mgmt = ManagementRoot("192.168.1.1", "admin", "admin1")

 

! Read data group value (Local Traffic -> iRules -> Data Group List) datagroups = mgmt.tm.ltm.data_group.get_collection() print (datagroups) print ("\n") ! dg = mgmt.tm.ltm.data_group.internals.get_collection() print (dg) print ("\n")

 

for dg1 in dg: print (dg1.name) print (dg1.partition) print (dg1.records) print ("\n") dg1.records = "[{'name': 'off'}]" print (dg1.records) print ("\n") dg[3].update()

 

Output

E:\LAB\python> E:\LAB\python>python datagroup.py [{'reference': {'link': ' 1.5.3'}}, {'reference': {'link': ' nal?ver=11.5.3'}}]

 

[< object at 0x028ECD90>, < ta_group.Internal object at 0x028ECF90>, < ob ject at 0x028ECF10>, < object at 0x029120F0>]

 

aol Common [{'name': '64.12.96.0/19'}, {'name': '195.93.16.0/20'}, {'name': '195.93.48.0/22 '}, {'name': '195.93.64.0/19'}, {'name': '195.93.96.0/19'}, {'name': '198.81.0.0 /22'}, {'name': '198.81.8.0/23'}, {'name': '198.81.16.0/20'}, {'name': '202.67.6 5.128/25'}, {'name': '205.188.112.0/20'}, {'name': '205.188.146.144/30'}, {'name ': '205.188.192.0/20'}, {'name': '205.188.208.0/23'}, {'name': '207.200.112.0/21 '}]

 

images Common [{'name': '.bmp'}, {'name': '.gif'}, {'name': '.jpg'}]

 

private_net Common [{'name': '10.0.0.0/8'}, {'name': '172.16.0.0/12'}, {'name': '192.168.0.0/16'}]

 

zol Common [{'name': 'on'}]

 

[{'name': 'off'}]

 

Traceback (most recent call last): File "datagroup.py", line 28, in dg[3].update() File "C:\Program Files (x86)\Python35-32\lib\site-packages\f5\bigip\tm\ltm\dat a_group.py", line 69, in update return self._update(**kwargs) File "C:\Program Files (x86)\Python35-32\lib\site-packages\f5\bigip\resource.p y", line 511, in _update response = session.put(update_uri, json=data_dict, **requests_params) File "C:\Program Files (x86)\Python35-32\lib\site-packages\icontrol\session.py ", line 241, in wrapper raise iControlUnexpectedHTTPError(error_message, response=response) icontrol.exceptions.iControlUnexpectedHTTPError: 400 Unexpected Error: Bad Reque st for uri: https://192.168.100.1:443/mgmt/tm/ltm/data-group/internal/~Common~zo l/ Text: '{"code":400,"message":"the \"create\" command does not accept wildcard configuration identifiers","errorStack":[]}'

 

 

E:\LAB\python>