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