Пример #1
0
def main():
    """Evalutes irules in subdirs, tests them individually on the
    load balancer before collating rules and pushing to f5"""

    f5 = f5utility.f5Connection()

    # Fetching a list of subdirectories which we need to process

    subdirs = os.listdir('./irules')
    for dirs in subdirs:
        if dirs == 'CVS':
            continue
        print " "
        print "------------------------------"
        print " Processing subdirectory %s" % dirs
        print "------------------------------"
        print " "
        full_path = './irules/'+dirs
        if os.path.isdir(full_path):

            # Build the rule

            rule_def = f5.irule.rule_build(full_path, dirs)

            # Check the rule for basic errors

            print "Built rules for "+dirs

            # Check if the rule exists, create if it doesn't

            try:
                rule = f5.irule.rule.query_rule(rule_names=[dirs+"_rule"])
            except:
                rule = f5.irule.rule.create(rules=[rule_def])

            # Modify the rule if it exists already

            try:
                rule = f5.irule.rule.modify_rule(rules=[rule_def])
            except suds.WebFault as detail:
                print "Failed to update the rule, probably due to a syntax error"
                sys.exit(detail)
            f = open(dirs+"_rule",'w')
            f.write(str(rule_def))
            f.close()

            print "Rules uploaded to f5"

    print " "
    print "------------------------------"
    print " Syncing Changes"
    print "------------------------------"
    print " "

    # sync the F5s
    f5.config_sync.sync_all()
Пример #2
0
def main():
    """Evalutes irules in subdirs, tests them individually on the
    load balancer before collating rules and pushing to f5"""

    f5 = f5utility.f5Connection()

    # Fetching a list of subdirectories which we need to process

    subdirs = os.listdir('./irules')
    for dirs in subdirs:
        if dirs == 'CVS':
            continue
        print " "
        print "------------------------------"
        print " Processing subdirectory %s" % dirs
        print "------------------------------"
        print " "
        full_path = './irules/' + dirs
        if os.path.isdir(full_path):

            # Build the rule

            rule_def = f5.irule.rule_build(full_path, dirs)

            # Check the rule for basic errors

            print "Built rules for " + dirs

            # Check if the rule exists, create if it doesn't

            try:
                rule = f5.irule.rule.query_rule(rule_names=[dirs + "_rule"])
            except:
                rule = f5.irule.rule.create(rules=[rule_def])

            # Modify the rule if it exists already

            try:
                rule = f5.irule.rule.modify_rule(rules=[rule_def])
            except suds.WebFault as detail:
                print "Failed to update the rule, probably due to a syntax error"
                sys.exit(detail)
            f = open(dirs + "_rule", 'w')
            f.write(str(rule_def))
            f.close()

            print "Rules uploaded to f5"

    print " "
    print "------------------------------"
    print " Syncing Changes"
    print "------------------------------"
    print " "

    # sync the F5s
    f5.config_sync.sync_all()
Пример #3
0
def main():

    #Create Connection to the f5
    f5 = f5utility.f5Connection()
    print " "
    print "------------------------------"
    print " Syncing Changes"
    print "------------------------------"
    print " "

    # sync the F5s
    f5.config_sync.sync_all()

    print " "
    print "done."
Пример #4
0
def main():
    """Create pools from pool config files"""

    #Set directory for pool conf files
    src_dir = 'pools/'

    #Create Connection to the f5
    f5 = f5utility.f5Connection()

    print " "
    print "------------------------------"
    print " Checking Configuration"
    print "------------------------------"
    print " "

    #Create empty queue for pool create/changes
    queue = []

    for infile in sorted(glob.glob(os.path.join(src_dir, '*_pool'))):

        #Build a pool from the config file and check that its valid
        pool = f5.pool.build(infile)

        name = pool['name']

        # Check if the pool already exists
        if f5.pool.exists(name):

            # Check if the pool has changed
            if f5.pool.changed(pool):

                # if the pool is valid add it to the queue
                # if the pool is not valid this will fail and exit the script
                if f5.pool.test(pool):

                    print "Marking pool %s for modification" % name
                    pool['operation'] = 'modify'
                    queue.append(pool)

            else:
                print "No Changes made to %s" % name
        else:
            # Check if there is a monitor available for the pool, exit if not.
            monitor_name = f5utility.swap_suffix("_health", name)
            if f5.monitor.exists(monitor_name):

                # Add pool to queue for creation
                print "Marking pool %s for creation" % name
                pool['operation'] = 'create'
                queue.append(pool)

            else:
                print "NO Monitor exists for %s ... STOPPING!" % name
                sys.exit("exit.")

    #Process the queue and commit changes to f5
    print " "
    print "------------------------------"
    print " Committing Changes"
    print "------------------------------"
    print " "

    # If the queue is empty print message, otherwise commit items in queue
    if queue == []:

        print "No Changes to Commit."

    else:

        for pool in queue:
            f5.pool.commit(pool)
            sleep(5)

        print " "
        print "------------------------------"
        print " Syncing Changes"
        print "------------------------------"
        print " "

        # sync the F5s
        f5.config_sync.sync_all()

    print " "
    print "done."
Пример #5
0
def main():

    """Create Monitors from config files"""

    #Set directory for monitor conf files
    src_dir = 'monitors/'

    #Create Connection to the f5
    f5 = f5utility.f5Connection()

    print " "
    print "------------------------------"
    print " Checking Configuration"
    print "------------------------------"
    print " "

    #Create empty queue for monitor create/changes
    queue = []

    for infile in sorted(glob.glob(os.path.join(src_dir, '*_health'))):

        #Build a monitor from the config file and check that its valid
        monitor = f5.monitor.build(infile)

        name = monitor['monitor_template'].template_name

        # Check if the monitor already exists
        if f5.monitor.exists(name):

            # Check if the monitor has changed
            changed = f5.monitor.changed(monitor)
            if (changed == 2):
                if f5.monitor.test(monitor):
                    print "Marking monitor %s for re-creation" % name
                    monitor['operation'] = 'recreate'
                    queue.append(monitor)

            elif (changed == 1):

                # if the monitor is valid add it to the queue
                # if the monitor is not valid this will fail and exit the script
                if f5.monitor.test(monitor):

                    print "Marking monitor %s for modification" % name
                    monitor['operation'] = 'modify'
                    queue.append(monitor)

            else:
                print "No Changes made to %s" % name
        else:

            # Add monitor to queue for creation
            print "Marking monitor %s for creation" % name
            monitor['operation'] = 'create'
            queue.append(monitor)


    #Process the queue and commit changes to f5
    print " "
    print "------------------------------"
    print " Committing Changes"
    print "------------------------------"
    print " "

    # If the queue is empty print message, otherwise commit items in queue
    if queue == []:

        print "No Changes to Commit."

    else:

        for monitor in queue:
            f5.monitor.commit(monitor)

        print " "
        print "------------------------------"
        print " Syncing Changes"
        print "------------------------------"
        print " "

        # sync the F5s
        f5.config_sync.sync_all()

    print " "
    print "done."
Пример #6
0
def main():
    """Create Monitors from config files"""

    #Set directory for monitor conf files
    src_dir = 'monitors/'

    #Create Connection to the f5
    f5 = f5utility.f5Connection()

    print " "
    print "------------------------------"
    print " Checking Configuration"
    print "------------------------------"
    print " "

    #Create empty queue for monitor create/changes
    queue = []

    for infile in sorted(glob.glob(os.path.join(src_dir, '*_health'))):

        #Build a monitor from the config file and check that its valid
        monitor = f5.monitor.build(infile)

        name = monitor['monitor_template'].template_name

        # Check if the monitor already exists
        if f5.monitor.exists(name):

            # Check if the monitor has changed
            changed = f5.monitor.changed(monitor)
            if (changed == 2):
                if f5.monitor.test(monitor):
                    print "Marking monitor %s for re-creation" % name
                    monitor['operation'] = 'recreate'
                    queue.append(monitor)

            elif (changed == 1):

                # if the monitor is valid add it to the queue
                # if the monitor is not valid this will fail and exit the script
                if f5.monitor.test(monitor):

                    print "Marking monitor %s for modification" % name
                    monitor['operation'] = 'modify'
                    queue.append(monitor)

            else:
                print "No Changes made to %s" % name
        else:

            # Add monitor to queue for creation
            print "Marking monitor %s for creation" % name
            monitor['operation'] = 'create'
            queue.append(monitor)

    #Process the queue and commit changes to f5
    print " "
    print "------------------------------"
    print " Committing Changes"
    print "------------------------------"
    print " "

    # If the queue is empty print message, otherwise commit items in queue
    if queue == []:

        print "No Changes to Commit."

    else:

        for monitor in queue:
            f5.monitor.commit(monitor)

        print " "
        print "------------------------------"
        print " Syncing Changes"
        print "------------------------------"
        print " "

        # sync the F5s
        f5.config_sync.sync_all()

    print " "
    print "done."
Пример #7
0
def main():

    """Create pools from pool config files"""

    #Set directory for pool conf files
    src_dir = 'pools/'

    #Create Connection to the f5
    f5 = f5utility.f5Connection()

    print " "
    print "------------------------------"
    print " Checking Configuration"
    print "------------------------------"
    print " "

    #Create empty queue for pool create/changes
    queue = []

    for infile in sorted(glob.glob(os.path.join(src_dir, '*_pool'))):

        #Build a pool from the config file and check that its valid
        pool = f5.pool.build(infile)

        name = pool['name']
        
        # Check if the pool already exists
        if f5.pool.exists(name):

            # Check if the pool has changed
            if f5.pool.changed(pool):

                # if the pool is valid add it to the queue
                # if the pool is not valid this will fail and exit the script
                if f5.pool.test(pool):

                    print "Marking pool %s for modification" % name
                    pool['operation'] = 'modify'
                    queue.append(pool)

            else:
                print "No Changes made to %s" % name
        else:
            # Check if there is a monitor available for the pool, exit if not.
            monitor_name = f5utility.swap_suffix("_health", name)
            if f5.monitor.exists(monitor_name):

                # Add pool to queue for creation
                print "Marking pool %s for creation" % name
                pool['operation'] = 'create'
                queue.append(pool)

            else:
                print "NO Monitor exists for %s ... STOPPING!" % name
                sys.exit("exit.")


    #Process the queue and commit changes to f5
    print " "
    print "------------------------------"
    print " Committing Changes"
    print "------------------------------"
    print " "

    # If the queue is empty print message, otherwise commit items in queue
    if queue == []:

        print "No Changes to Commit."

    else:

        for pool in queue:
            f5.pool.commit(pool)
            sleep(5)

        print " "
        print "------------------------------"
        print " Syncing Changes"
        print "------------------------------"
        print " "

        # sync the F5s
        f5.config_sync.sync_all()

    print " "
    print "done."