13-Jan-2017 13:36
Is it possible to read/edit the contents of an external datagroup file via iControlREST directly without downloading the file?
https://{{big_ip_a_mgmt}}/mgmt/tm/ltm/data-group/external/my_sample_class gives me the properties of the file but not the contents.
For internal datagroups this works as expected using the following: https://{{big_ip_a_mgmt}}/mgmt/tm/ltm/data-group/internal/my_sample_class
23-Jan-2017 12:54
The process for uploading external dg is typically
If you query that object file object, you end up with many attributes, none of which include the filename created in the filestore. But one attribute is sourcePath
and as long as you are not cleaning up in between posts, you could potentially download that file, edit, re-upload, and then update the file object. Or, just make sure the source of truth is where your script is running, then you just update from there without being concerned what's in the current live version.
To answer your question, it IS possible to read the file, but you will need to do some bash calesthenics to interrogate the filestore to get the filename, but even then you still need to download the file to edit it.
07-Jun-2018
15:44
- last edited on
21-Nov-2022
21:48
by
JimmyPackets
Jason, as you have always been very helpful ... Would you please guide me here too. As per above post, I able to read the list of data group files using python SDK.
BigIP Version : 12.1.2 HF2
Now I am trying to read contents of each file. Below is my code but it is erroring out :
dglist = mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs='-c "ls /config/filestore/files_d/Common_d/data_group_d"')
Write to a file and then read it line by line
dgfile = open("dgfilelist","w")
dgfile.write(dglist.commandResult)
dgfile.close()
dgfile = open("dgfilelist","r")
for line in dgfile:
print ("File name is : "+line)
cmdargs = "'run',"+" utilCmdArgs="+"'-c "+"\"cat /config/filestore/files_d/Common_d/data_group_d/"+line+"\"\'"
print ("CmdArgs are : "+ cmdargs )
dgshow = mgmt.tm.util.bash.exec_cmd(cmdargs)
print ("File Contents are :")
print (dgshow.commandResult)
Here is the Output :
Shoaib-Mac:f5-sdk mshoaib$ ./p get-datagroup.py
File name is : :Common:testvip_PH_16641_18
CmdArgs are : 'run', utilCmdArgs='-c "cat /config/filestore/files_d/Common_d/data_group_d/:Common:testvip_PH_16641_18
"'
Traceback (most recent call last):
File "get-datagroup.py", line 31, in
dgshow = mgmt.tm.util.bash.exec_cmd(cmdargs)
File "/Users/mshoaib/anaconda3/lib/python3.6/site-packages/f5_sdk-3.0.14-py3.6.egg/f5/bigip/tm/util/bash.py", line 50, in exec_cmd
self._is_allowed_command(command)
File "/Users/mshoaib/anaconda3/lib/python3.6/site-packages/f5_sdk-3.0.14-py3.6.egg/f5/bigip/mixins.py", line 218, in _is_allowed_command
raise InvalidCommand(error_message)
f5.sdk_exception.InvalidCommand: The command value 'run', utilCmdArgs='-c "cat /config/filestore/files_d/Common_d/data_group_d/:Common:testvip_PH_16641_18
"' does not exist. Valid commands are ['run']
Shoaib-Mac:f5-sdk mshoaib$
I have tried different iterations to supply a file name to the "exec_cmd" function but it's always angry ...
I appreciate any help or pointers to do it correctly.
Thank you, Muhammad
10-Jul-2018 01:15
The entries in the list which iterate as line contain a carriage return at the end which is making it puke.
09-Jul-2018 23:08
dgshow = mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs='-c "cat /config/filestore/files_d/Common_d/data_group_d/{0}"'.format(file_name))
11-Jul-2018 22:28
Thank you Kailas ... it worked. Below is my working script to read the contents of all the data groups and display its contents.
dglist = mgmt.tm.util.bash.exec_cmd(
'run', utilCmdArgs='-c "ls /config/filestore/files_d/Common_d/data_group_d"')
Write to a file and then read it line by line
dgfile = open("dgfilelist", "w")
dgfile.write(dglist.commandResult)
dgfile.close()
dgfile = open("dgfilelist", "r")
for file in dgfile:
dgshow = mgmt.tm.util.bash.exec_cmd('run', utilCmdArgs='-c "cat /config/filestore/files_d/Common_d/data_group_d/{0} " '.format(file))
print file contents
print (dgshow.commandResult)
print ("========")
21-Apr-2022 13:45
I hope its ok to bring this thread back to the top. I am new to rest and I can't figure out how to just read the contents of the external data group file. I can do it fine for internal but seem I can't do exactly the same for external. Any help is much appreciated.