Is there a way using the API to add a single key to a data group without needing to POST/PATCH the entire existing list with the single new addition?
In other words if I have a data group that looks like this:
{
"name": "key1",
"data": "value1"
},
{
"name": "key2",
"data": "value2"
}
and I want to add the following:
{
"name": "key3",
"data": "value3"
}
When using the CLI or GUI I can do this one at a time. Using the REST API it does not appear that I can just add a single new key to the list without having to GET the existing list and manually add the new one to the body before POSTing back to the LTM. Is there a way to do this that I am missing?
Hello,
I workaround this with options parameter:
e.g.
?options=records add { key3 { data value3 } }
curl -ku "admin:admin" -X PATCH -H 'Content-type: application/json' -d '{ "name":"my_datagroup" }' https://localhost/mgmt/tm/ltm/data-group/internal/my_datagroup?options=records%20add%20%7b%20key3%20%7b%20data%20value3%20%7d%20%7d |jq .
Best regards.
This is exactly what I am looking for, thank you! Where can I find more info about the options(i.e. add) available with data groups? I would also like to do the same thing removing a single record as well and see what else is available.
Hi,
You can find a generic explanation in user guide about options parameter.
"options:
Specifies the options to a query request. This parameter takes values that are compatible with the tmsh command-line options."
In this case, “PATCH” runs “modify” and “options” completes the tmsh command:
e.g.
modify ltm data-group internal my_datagroup records add { key3 { data value3 } }
So, to delete a record, change operation to “delete”:
?options=records delete { key1 }
curl -ku "admin:admin" -X PATCH -H 'Content-type: application/json' -d '{ "name":"my_datagroup" }' https://localhost/mgmt/tm/ltm/data-group/internal/my_datagroup?options=records%20delete%20%7B%20key1%20%7D |jq .
Full docs:
Data-group docs:
Regards
Excellent. Add and deletes are both working. Thanks again!
JRahm
January 12, 2021, 5:34pm
6
this is cool, and I had no idea this worked. What versions have you confirmed this on?
cjunior
January 12, 2021, 10:24pm
7
Hi ,
I just ran a test on versions 14.1.2.2 and 13.1.3.2 successfully.
Best regards.
[root@bigipdelta:Active:Standalone] config # tmsh list ltm data-group internal dg_devcentral
ltm data-group internal dg_devcentral {
records {
key1 {
data value1
}
key2 {
data value2
}
key3 {
data value3
}
key4 {
data value4
}
key5 {
data value5
}
}
type string
}
[root@bigipdelta:Active:Standalone] config # curl -k -su "admin" -X PATCH -H 'Content-type: application/json' -d '{ "name":"dg_devcentral" }' https://localhost/mgmt/tm/ltm/data-group/internal/dg_devcentral?options=records%20delete%20%7B%20key1%20%7D |jq .
Enter host password for user 'admin':
{
"kind": "tm:ltm:data-group:internal:internalstate",
"name": "dg_devcentral",
"fullPath": "dg_devcentral",
"generation": 499,
"selfLink": "https://localhost/mgmt/tm/ltm/data-group/internal/dg_devcentral?options=records+delete+%7B+key1+%7D&ver=14.1.2.2",
"type": "string",
"records": [
{
"name": "key2",
"data": "value2"
},
{
"name": "key3",
"data": "value3"
},
{
"name": "key4",
"data": "value4"
},
{
"name": "key5",
"data": "value5"
}
]
}
[root@bigipdelta:Active:Standalone] config # curl -k -su "admin" -X PATCH -H 'Content-type: application/json' -d '{ "name":"dg_devcentral" }' https://localhost/mgmt/tm/ltm/data-group/internal/dg_devcentral?options=records%20add%20%7b%20key1%20%7b%20data%20value1%20%7d%20%7d |jq .
Enter host password for user 'admin':
{
"kind": "tm:ltm:data-group:internal:internalstate",
"name": "dg_devcentral",
"fullPath": "dg_devcentral",
"generation": 500,
"selfLink": "https://localhost/mgmt/tm/ltm/data-group/internal/dg_devcentral?options=records+add+%7B+key1+%7B+data+value1+%7D+%7D&ver=14.1.2.2",
"type": "string",
"records": [
{
"name": "key1",
"data": "value1"
},
{
"name": "key2",
"data": "value2"
},
{
"name": "key3",
"data": "value3"
},
{
"name": "key4",
"data": "value4"
},
{
"name": "key5",
"data": "value5"
}
]
}
JRahm
January 12, 2021, 10:41pm
8
nice! I’ll test 12.1, 15.1 and 16.1 and then call it good. I appreciate you!
JRahm
January 13, 2021, 3:55am
9
Here’s a python script alternative to using curl on the cli.
jba3126
January 13, 2022, 7:20pm
10
were you able to confirm the versions? About to test 15.1.3.x.
/jeff
Edit: In order to select a different partition than Common send this as the body:
{“partition”: “NAME_OF_THE_PARTITION”}
Do you know if this is possible to use this solution when the Data Group is located in a partition other than Common?
Kind Regards
// M
Thanks for confirming. So for the delete, you can just give the key or the entire key value pair?
Okay, seems this one is using options to add, but I read its using tmsh commands to fulfil the same. but when we migrate to NEXT there would be no TMSH, what would be the best way to achieve to add a name and data to a data-group using iControl REST API?
JRahm
February 13, 2024, 5:56pm
14
there won’t be an iControl REST as is in BIG-IP Next. Data-groups are not yet supported in Next, when those are added we’ll have a better idea on how it will be supported, whether those will be expected to be part of the application declaration or a shared object that is versioned like iRules in CM. If I had to guess, it will be a versioned shared object that can then be deployed/rolled-back, but given the size of some data-groups, there may be incremental diffs supported. Time will tell.
Got it, We are building a pool/class maintenance page based on API, hope it wont break when we migrate to NEXT. :)
Thank you again.