Forum Discussion
Upload data group file list with Python Bigsuds iControl
Hello,
Short version: What is the correct way to upload an external data group file using the python bigsuds API ?
Long version:
I am trying to use python and bigsuds to create Data Groups based on external files.
I managed to create the data group using the following method:
b.LocalLB.Class.create_external_class_v2(["datagroup_name_test"],["file_name_test"])
It works but the file_name_test must be already there, uploaded before via web interface. I created a file dg.txt with the following content:
"name1" := "value1",
"name2" := "value2",
"name3" := "value3",
And I wrote the following function to upload it:
def uploadfile(bigip,filename):
fileobj = open(filename,'r')
DF_CHUNK_SIZE = 1024
done = False
first = True
while not done:
text = base64.b64encode(fileobj.read(DF_CHUNK_SIZE))
if first:
chain_type = 'FILE_FIRST'
first = False
else:
if len(text) < DF_CHUNK_SIZE:
chain_type = 'FILE_LAST'
done = True
else:
chain_type = 'FILE_MIDDLE'
bigip.System.ConfigSync.upload_file(file_name="/config/filestore/files_d/Common_d/data_group_d/"+filename,file_context=dict(file_data=text,chain_type=chain_type))
I cant upload the file, I get this error:
ServerError: Server raised fault: 'Exception caught in System::urn:iControl:System/ConfigSync::upload_file()
Exception: Common::OperationFailed
primary_error_code : 16908289 (0x01020001)
secondary_error_code : 0
error_string : Error opening file for write operations'
I feel I am doing it in the wrong way. What is the correct way to upload an external data group file using the python bigsuds API ?
7 Replies
- Matt_Dierick
Employee
Hi Saverio,
Did you have a look on this article? https://community.f5.com/t5/technical-articles/icontrol-101-06-file-transfer-apis/ta-p/283245
- Saverio_180237
Nimbostratus
Hello Matthieu, thanks for you answer.
Yes I read it. I found it very usefull, and I used it to write the code that is in the question.
However the article does not provide an example of uploading an "external data group file". The examples are for "upload configuration"
I will try to explain my self better. If you use the web interface and you go to this path:
System -> File Management -> Data Group File List -> Import
In this screen there are several option, for example "Key / Value Pair Separator"
I just dont get how I can use the generic upload_file function to upload a "external data group file" in the right folder on the file system
- Saverio_180237
Nimbostratus
I did more tests. If I try to upload to `/tmp` or to `/config/` it works and I have the file to the remote IP. Here is the updated code: https://gist.github.com/zioproto/4b93e0e80f2a5d680dd2 However still I cant make the upload file be recognized as an External Data Group File - Saverio_180237
Nimbostratus
I think I found the way to the solution:
b.LocalLB.DataGroupFile.create()
- Saverio_180237
Nimbostratus
The final solution here: https://gist.github.com/zioproto/4b93e0e80f2a5d680dd2file-create_external_datagroup_file_bigip_f5_bigsuds-py - Matt_Dierick
Employee
Good :)
- Saverio_180237
Nimbostratus
Final solution here: https://gist.github.com/zioproto/4b93e0e80f2a5d680dd2file-create_external_datagroup_file_bigip_f5_bigsuds-py
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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