Multihost iRule backup-script

Problem this snippet solves:

This script makes a backup of all iRules of every host in the tuple. It will create a folder with the hostname/partition and there a file for every iRule.

How to use this snippet:

Change parameters in multi-backup.py

host:$ python ./multi-backup.py

Code :

#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
Used to backup iRules on all F5 Loadbalancers
"""

__author__ = "Yannic Schneider"
__license__ = "WTFPL"
__email__ = "v@vendetta.ch"

###############################################################################
# CODE
###############################################################################

import bigsuds
import sys
import os

# Globals
hosts = ('10.x.x.1','10.x.x.2',)
user = ''
password = ''

# Loop trough hosts
for host in hosts:
    try:
        b = bigsuds.BIGIP(
            hostname=host,
            debug=True,
            username=user,
            password=password
        )
        print('Debug: Backup of host='+host)
    except Exception, e:
        print e

    # Set system partition
    b.System.Session.set_active_folder("/Common")

    # Get all rules
    allr = b.LocalLB.Rule.query_all_rules()

    if not os.path.isdir('./'+host):
        os.mkdir('./'+host)

    if not os.path.isdir('./'+host+'/Common'):
        os.mkdir('./'+host+'/Common')

    for rule in allr:
        f = open("./"+host+rule['rule_name'],'w+')
        f.write(rule['rule_definition'])
        f.close

Tested this on version:

11.0
Published May 09, 2017
Version 1.0

Was this article helpful?

No CommentsBe the first to comment