cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.
Justin_Cook_433
Nimbostratus
Nimbostratus

Problem this snippet solves:

The following code takes a connected pycontrol.pycontrol.BIGIP object and uploads a file:

Code :

def send_file(obj, local_file):
    import io, base64
    ctx = obj.System.ConfigSync.typefactory.create(
                           'System.ConfigSync.FileTransferContext')
    poll = True
    chunk_size = 64*768
    ctx.chain_type = 'FILE_FIRST'
    tsent = 0
    try:
        f = io.open(local_file, 'rb')
    except IOError, e:
        print >> sys.stderr, e
        sys.exit(1)
    while poll:
        fdata = f.read(chunk_size)
        if len(fdata) != chunk_size:
            if tsent == 0:
                ctx.chain_type = 'FILE_FIRST_AND_LAST'
            else:
                ctx.chain_type = 'FILE_LAST'
            poll = False
        ctx.file_data = base64.b64encode(fdata)
        obj.System.ConfigSync.upload_configuration(local_file, ctx)
        tsent += 1
        ctx.chain_type = 'FILE_MIDDLE'
Version history
Last update:
‎09-Mar-2015 13:56
Updated by:
Contributors