Forum Discussion
Assuming you have both data-group file object (tmsh list sys file data-group <object>) and external data-group ltm object (tmsh list ltm data-group external <object>), then sending a PATCH request to the file object would override the file contents. The ltm object is just a reference to the file, hence the new data becomes automatically available from iRule.
For example,
1) Before the change, the external data-group file contained the following data (see the bottom for the test iRule code)
# Edited for readability
16:02:19 /Common/ExternalDg <HTTP_REQUEST>: {Shota} Short
16:02:19 /Common/ExternalDg <HTTP_REQUEST>: {Ochako} Uravity
16:02:19 /Common/ExternalDg <HTTP_REQUEST>: {Izuku} Deku
16:02:19 /Common/ExternalDg <HTTP_REQUEST>: {Tenya} Ingenium
2) Update the file by calling PATCH /mgmt/tm/sys/file/data-group/<object>.
curl -sku $PASS \
https://$HOST/mgmt/tm/sys/file/data-group/dg-testMHA.txt \
-X PATCH -H "Content-type: application/json" \
-d '{"sourcePath":"http://172.16.10.10/dg-testMHA.txt"}'
where dg-testHMA.txt is the existing file object. Note that the file contains all the records. When the call successfully completes, you will see the following messages in the ltm log:
# Edited. The same messages repeat because I have two TMMs.
16:04:24 tmm1 External Datagroup (/Common/dg-testMHA) queued for update.
16:04:24 tmm External Datagroup (/Common/dg-testMHA) queued for update.
16:04:25 tmm1 External Datagroup (/Common/dg-testMHA) update finished.
16:04:25 tmm External Datagroup (/Common/dg-testMHA) update finished.
3) Check the data contents again. New data is added.
# Edited. I do not know why the order is different.
16:04:35 /Common/ExternalDg <HTTP_REQUEST>: {Tsuyu} Floppy
16:04:35 /Common/ExternalDg <HTTP_REQUEST>: {Tenya} Ingenium
16:04:35 /Common/ExternalDg <HTTP_REQUEST>: {Ochako} Uravity
16:04:35 /Common/ExternalDg <HTTP_REQUEST>: {Shota} Short
16:04:35 /Common/ExternalDg <HTTP_REQUEST>: {Izuku} Deku
Appendix: Test iRule code
when HTTP_REQUEST {
foreach {record} [class get dg-testMHA] {
log local0. "$record"
}
}
- Bill_HomanMay 02, 2020Nimbostratus
Thanks Satoshi! I was able to employ patch as you suggested using this Python code:
def update_edg_file(rq, url, fileserver, newfilename, dgfname): path = fileserver + "/" + newfilename payload = {} payload['sourcePath'] = path req = '{}/sys/file/data-group/{}'.format(url, dgfname) resp = rq.patch(req, json.dumps(payload)) print("update_edg_file, name: {}, PATCH response: {}".format(dgfname, resp)) # in main ... url_base = 'https://%s/mgmt/tm' % hostname rs = requests.session() rs.auth = (username, password) rs.verify = False rs.headers.update({'Content-Type':'application/json'}) .... update_edg_file(rs, url_base, external_file_server, filename, edg_file_name)
The update is pretty quick.