Forum Discussion
Steve_Brown_882
Feb 16, 2011Historic F5 Account
pyControl download_file
Has anyone used the config sync download file functionality in python. I have gotten the command to work as follows, but I am not really sure what I need to do to get the resulting data into a file on...
L4L7_53191
Mar 01, 2011Nimbostratus
Steve: Wow this is odd - I'm getting some really puzzling results, all surrounding the chunk sizing. I can pull in and unpack an archive (mostly), but it's not complete. Here's the code, in the hopes that you or someone else can see an obvious error in my ways. If I tickle that chunk_size variable to 8k, 16k, 32, 64, etc. they all seem to return an different final file size. Weird.
!/bin/env python
import base64
import array
import binascii
def pc_downloader(b,remote_file,local_file):
'''
Handles downloading files via System.ConfigSync
Args:
b -- a pycontrol client object
remote_file -- the name of the file to fetch from BigIP
local_file -- the local file to write to.
'''
dl = b.System.ConfigSync
local_file = open(local_file, 'ab')
poll = True
chunk_size = 8*1024
foffset = 0
a = array.array('c')
while poll:
res = dl.download_file('/var/tmp/test-ucs.tgz',chunk_size = chunk_size,file_offset = foffset)
fdata = getattr(res,'return').file_data
foffset = long(res.file_offset)
chain_type = getattr(res, 'return').chain_type
if (chain_type == 'FILE_LAST') or (chain_type == 'FILE_FIRST_AND_LAST'):
poll = False
local_file.close()
else:
local_file.write(binascii.a2b_base64(fdata))
if __name__ == '__main__':
import pycontrol.pycontrol as pc
b = pc.BIGIP(hostname='192.168.1.245',username='admin',password='admin',fromurl=True,wsdls=['System.ConfigSync'])
pc_downloader(b,'/var/tmp/testucs.tgz','/var/tmp/testucs.tgz')
Give this a try and see if you get the same results. If so, I think it's worth opening a case.
-Matt
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects