Created
March 5, 2019 02:15
-
-
Save stobias123/0bef6c933f97c4a8f9d212af5cda68da to your computer and use it in GitHub Desktop.
Exports all policies from an F5 Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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