Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zioproto/4b93e0e80f2a5d680dd2 to your computer and use it in GitHub Desktop.
Save zioproto/4b93e0e80f2a5d680dd2 to your computer and use it in GitHub Desktop.
Upload a file to F5 BIGIP using bigsuds
"""
This script will create an external file datagroup.
This is the same of creating the data group from the web interface at:
System -> File Management -> Data Group File List
Create on your computer a file called datagroup.txt with the following content:
"name1" := "value1",
"name2" := "value2",
"name3" := "value3",
"""
import bigsuds
import base64
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:
if len(text) < DF_CHUNK_SIZE:
chain_type = 'FILE_FIRST_AND_LAST'
else:
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="/tmp/"+filename,file_context=dict(file_data=text,chain_type=chain_type))
b = bigsuds.BIGIP(hostname="192.168.1.1", debug=True, username="", password="")
uploadfile(b,'datagroup.txt')
b.LocalLB.DataGroupFile.create(['datagroup_myname'],['/tmp/datagroup.txt'],['DATA_GROUP_STRING'])
'''
if later you want to update the file, just edit the new version of datagroup.txt and then use:
'''
#uploadfile(b,'datagroup.txt')
#b.LocalLB.DataGroupFile.set_local_path(['datagroup_myname'],['/tmp/datagroup.txt'])
import bigsuds
import base64
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:
if len(text) < DF_CHUNK_SIZE:
chain_type = 'FILE_FIRST_AND_LAST'
else:
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="/tmp/"+filename,file_context=dict(file_data=text,chain_type=chain_type))
b = bigsuds.BIGIP(hostname="192.168.1.1", debug=True, username="", password="")
uploadfile(b,'class.txt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment