Forum Discussion
DarioGB_339840
Altostratus
Aug 27, 2018Updating DataGroup using F5 SDK
Hello.
I'm trying to add a new datagroup record, to do so I use next code:
from f5.bigip import ManagementRoot
session = ManagementRoot("10.1.1.1","admin","mypass",token=True)
datagroup = session.tm.ltm.data_group.internals.internal.load(name='test', partition='Common')
datagroup.records = ["4.4.4.4/32", "4.4.4.5/32"]
datagroup.update()
datagroup = session.tm.ltm.data_group.internals.internal.load(name='test', partition='Common')
print(datagroup.records)
Having next result:
[{'name': '4.4.4.4/32', 'data': ''}, {'name': '4.4.4.5/32', 'data': ''}]
This is OK for updating address datagroups, but now I'm trying to modify strings datagroups with name and data fields. Do you know how should I write the variable in this case?
I can do it using REST without problem, but not using SDK. Any idea?
PUT https://localhost/mgmt/tm/ltm/data-group/internal/~Common~test
Header: "Content-type: application/json"
Payload: '{"records": [{"name": "mydomain1","data": "4.4.4.4/32"}, {"name": "mydomain2","data": "4.4.4.5/32"}]}'
Thanks in advance.
KR, Dario.
- Dario_Garrido
Noctilucent
I found a solution:
from f5.bigip import ManagementRoot session = ManagementRoot("10.1.1.1","admin","mypass",token=True) datagroup = session.tm.ltm.data_group.internals.internal.load(name='test', partition='Common') CREATE NEW ITEMS DICT item1 = dict([("name", "1.1.1.1/32"),("data", "domain1.com")]) item2 = dict([("name", "2.2.2.2/32"),("data", "domain2.com")]) GENERATE A LIST FROM THOSE ITEMS newitems = [item1, item2] APPEND ITEMS TO THE CURRENT DATAGROUP datagroup.records = datagroup.records + newitems datagroup.update()
KR, Dario.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects