Forum Discussion

Saverio_180237's avatar
Saverio_180237
Icon for Nimbostratus rankNimbostratus
Dec 30, 2014

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

  • 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

  • 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's avatar
      Saverio_180237
      Icon for Nimbostratus rankNimbostratus
      The final solution here: https://gist.github.com/zioproto/4b93e0e80f2a5d680dd2file-create_external_datagroup_file_bigip_f5_bigsuds-py
  • Final solution here: https://gist.github.com/zioproto/4b93e0e80f2a5d680dd2file-create_external_datagroup_file_bigip_f5_bigsuds-py