Skip to content

Instantly share code, notes, and snippets.

@stobias123
Created March 5, 2019 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stobias123/0bef6c933f97c4a8f9d212af5cda68da to your computer and use it in GitHub Desktop.
Save stobias123/0bef6c933f97c4a8f9d212af5cda68da to your computer and use it in GitHub Desktop.
Exports all policies from an F5 Server
from f5.bigip import ManagementRoot
from time import sleep
def task_checker(task):
while True:
task.refresh()
if task.status in ['COMPLETED', 'FAILURE']:
break
sleep(1)
assert task.status == 'COMPLETED' # this will raise assertion error if export task fails
return True
def download(mgmt, path=None):
"""This will download to the script directory,
specify path to place it somewhere else
"""
if path:
filename = path+name
else:
filename = name
mgmt.tm.asm.file_transfer.downloads.download_file(filename)
def iterate_policies(mgmt):
policies = mgmt.tm.asm.policies_s.get_collection()
for policy in policies:
yield policy.name, policy.selfLink
def export(mgmt, filepath=None):
path = filepath
for name, link in iterate_policies(mgmt):
task = mgmt.tm.asm.tasks.export_policy_s.export_policy.create(
filename=name + '.xml',
policyReference={"link": link}
)
if task_checker(task):
download(mgmt, name)
emgmt = ManagementRoot('server','username','password')
export(emgmt)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment