Forum Discussion
Searching and Filtering Objects by Metadata
I am not familiar with the GTM data structure, but generally speaking, you need to come up with a programmatic solution to selectively obtain the element inside the array (from your example, the value of metadata is an array of dict elements).
Allow me to talk about LTM's datagroup because it has a similar data structure to metadata. Assume that I am looking for the datagroup name that has the records (metadata equivalent) containing the name 'age'.
Here's how you get a list of all the datagroup names:
curl -sku : https:///mgmt/tm/ltm/data-group/internal?\$select=name \
| python -m json.tool | grep name\"
"name": "aol"
"name": "images"
"name": "private_net"
"name": "sys_APM_MS_Office_OFBA_DG"
"name": "test"
So, there are five datagroups on this box. The list of records in 'test' looks like this:
curl -sku : https:///mgmt/tm/ltm/data-group/internal/test?\$select=records
{"records":[{"name":"addKey","data":"addVal"},{"name":"age","data":"100"},{"name":"name","data":"Satoshi"}]}
So the correct answer is "the name 'age' is in the 'test' datagroup and its value is 100". A python code to achieve this goal is below:
from f5.bigip import ManagementRoot
mgmt = ManagementRoot('host', 'user', 'pass')
Get all the datagroup names
dataGroupAll = mgmt.tm.ltm.data_group.internals.get_collection()
names = [d.name for d in dataGroupAll]
print('List of internal dgs[{}]: {}'.format(len(names), ', '.join(names)))
Scan all the records in all the datagroups until it finds the matching value in the name field
dataFound = None
dataIn = None
for dgName in names:
print 'Checking ', dgName
dg =mgmt.tm.ltm.data_group.internals.internal.load(name=dgName)
for ddg in dg.records:
if ddg['name'] == :
dataFound = ddg['data']
dataIn = dgName
break
if dataIn != None:
break
print('key {}, value {} found in {}'.format(, dataFound, dataIn))
Example output below:
Checking aol
Checking images
Checking private_net
Checking sys_APM_MS_Office_OFBA_DG
Checking test
key age, value 100 found in test
I hope you can tailor the code to suit your needs.
See also F5 Python SDK Documentation.
Recent Discussions
Related Content
* 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