AVX::CONFIG

This command is used when other commands like AVX::CMD, AVX::REST and AVX::JSON are used within a workflow task such as Script. AVX::CONFIG is used to assign the commands generated script under a specific key in a python dictionary or a variable. In a workflow, the commands to be generated can be assigned using AVX::CONFIG (within a single script) and can be referred anywhere across the workflow.

Usage:

AVX::CMD(“testdevice”+':@'+”implementation command 1”)
AVX::CMD(“testdevice”+':@'+”implementation command 2”)
commands ={}
commands[“implementation”] = AVX::CONFIG
  • Commands 1 and 2 will get added to the implementation key.

  • This will add up the commands generated in the script to the provided key.

Example: Generating F5 VIP prevalidation commands
AVX::CMD(device + ':@' + 'tmsh')
AVX::CMD(device + ':@' + 'list ltm pool ' + pool_name)
AVX::CMD(device + ':@' + 'list ltm virtual ' + vip_name)
AVX::CMD(device + ':@' + 'quit')

config = {}
config['prevalidation_config'] = AVX::CONFIG
AVX::LOG('Configurations generated successfully.')
  • AVX::CONFIG within script

Create F5 Sample Config:
import sys
import json
sys.path.insert(0,AVX::DEPENDENCIES)
sys.path.insert(0,AVX::HELPER)
import os
import f5
import appviewx
import Decrypt_Python3 as Decrypt
from f5 import *
from Decrypt_Python3 import getpassword, getencoded
import paramiko
null=None
connect_db=appviewx.db_connection()
db = connect_db.appviewx
vendor = 'F5'
device_name = '<%Device%>'
fqdn = '<%AppName%>'.lstrip('www.').split('.')[0]
vip_ip = '<%IP%>'
vip_port = '<%Port%>'
persistence = '<%Persistence%>'
create_http_profile = '<%CreateHTTPProfile%>'
create_http_monitor = '<%CreateHTTPMonitor%>'
lb_method = '<%LoadBalancingMethod%>'
defaults_from = '<%DefaultsFrom%>'
ratio = '<%Ratio%>'
interval = '<%Interval%>'
timeout = '<%Timeout%>'
send_string = '<%SendString%>'
receive_string = '<%ReceiveString%>'
existing_monitor = '<%ExistingMonitor%>'
irulecheck = '<%irulecheck%>'
irulefile = '<%uploadedfile%>'
pool_members = <%PoolMembers%>
partition='Common'
output_dict = {}
cmd2 = []
deviceInfo = db.device
devVersion = deviceInfo.find_one({'name':device_name})['version']
device_ip = deviceInfo.find_one({'name':device_name} , {"ip": 1})['ip']
username, password = Decrypt.getpassword(device_name)
try:
    tmos_version =deviceInfo.find_one({"name": device_name}, {'detailedVersion': 1})['detailedVersion'].split(" ")[0]
except  Exception:
    tmos_version = None
def connect_remote(IP,username,password):
    try:
        remote_conn=paramiko.SSHClient()
        remote_conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        remote_conn.connect(IP,username=username,password=password,look_for_keys=False,allow_agent=False)
        return remote_conn
    except Exception as e:
        print (str(e))
def check_bash_mode(connection) :
    stdin, stdout, err=connection.exec_command('echo "testing"')
    err = err.read().decode()
    if "Error" not in err:
        return True
    else:
        return False    
def create_f5():
    '''
    Create F5 vip
    '''
    monitors = []
    cmd = []
    connection = connect_remote(device_ip, username, password)
    bash_mode = check_bash_mode(connection)
    if bash_mode:
        cmd.append('tmsh')
        cmd2.append('tmsh')
    if tmos_version and tmos_version not in ('11.4.1','11.4.3'):
        cmd.append("create cli transaction")
        cmd2.append("create cli transaction")
    if devVersion in ['v11', 'v12']:
        cmd.append('cd /{0}'.format(partition))
        cmd2.append('cd /{0}'.format(partition))
    else:
        cmd.append('modify cli admin-partitions update-partition {0}'.format(partition))
        cmd2.append('modify cli admin-partitions update-partition {0}'.format(partition))        
    if create_http_monitor == 'Yes':
        http_mon = F5Monitor(**{'type': 'http',
                      'app_name': fqdn,
                      'vip_port': vip_port,
                      'interval': interval,
                      'timeout': timeout,
                      'send': send_string,
                      'recv': receive_string})
        cmd.append(http_mon.create)
        cmd2.append(http_mon.delete)
        mon_index = len(cmd2) - 1
        monitors.append(http_mon)
        output_dict['monitor'] = http_mon.name
    if existing_monitor != 'None':
        ex_mon = F5Monitor(**{'type': existing_monitor,
                            'associate': True})
        monitors.append(ex_mon)
        output_dict['monitor'] = ex_mon.name
    profile_list = []
    if create_http_profile == 'Yes':
        prof = F5Profile(**{'type': 'http',
                       'app_name': fqdn,
                       'vip_port': vip_port,
                       'defaults-from': defaults_from})
        if defaults_from and defaults_from.lower() != "select" and defaults_from.lower() != "none":
            prof_create_cmd = prof.create
        else:
            prof_create_cmd = prof.create.split("defaults-from")[0]
        cmd.append(prof_create_cmd)
        cmd2.append(prof.delete)
        profile_list.append(prof)
        output_dict['profile'] = prof.name
    else:
        output_dict['profile'] = ''
    pool = F5Pool(**{'lb_mode': lb_method,
                   'app_name': fqdn,
                   'port': vip_port,
                   'ratio': ratio,
                   'monitors': monitors,
                   'pool_members': {'keys': ['PoolMemberIP', 'PoolMemberPort', 'Ratio'],
                                    'values': pool_members}})
    cmd.append(pool.create)
    cmd2.append(pool.delete)
    output_dict['pool'] = pool.name
    per = F5Persistence(**{'persistence': persistence})
    output_dict['persistance'] = per.name
    vip = F5VirtualServer(**{'app_name': fqdn,
                 'vip_ip': vip_ip,
                 'vip_port': vip_port,
                 'pool': pool,
                 'profiles': profile_list,
                 'persistence': per})
    cmd.append(vip.create)
    cmd2.append(vip.delete)
    vip_index = len(cmd2) - 1
    try:
        cmd2[vip_index], cmd2[mon_index] = cmd2[mon_index], cmd2[vip_index]
    except:
        pass
    output_dict['vip'] = vip.name    
    if irulecheck == "Yes":
        # AVX::LOG(str(type(irulefile))+" "+str(irulefile))
        fileName = irulefile['fileName']
        #filename = 'irulee1.txt'
        try:
            # file_location = '/home/'+username+os.sep
            file_location = '/config/'
            destination_json = AVX::JSONCONVERTER(device_name,'$$username$$', '$$password$$', file_location)
            AVX::PUSH('N/A','None', destination_json,'sftp', irulefile)
            # AVX::LOG("iRule Successfully pushed to device")
        except:
            pass    
    if tmos_version and tmos_version not in ('11.4.1','11.4.3'):
        cmd.append('submit cli transaction')
        cmd2.append('submit cli transaction')        
    if irulecheck == 'Yes':
        # fileName = irulefile['fileName']
        # file_location = '/home/'+username+os.sep
        cmd.append("load sys config file "+file_location+fileName+" merge")        
    cmd.extend(['save sys config', 'quit'])
    cmd2.extend(['save sys config', 'quit'])            
    for c in cmd:
        AVX::CMD(device_name+':@'+c)
def main():
    '''
    Main method
    '''
            if vendor == 'F5':
        create_f5()
    
    output_dict['Implementation']=AVX::CONFIG
    
    for c in cmd2:
        AVX::CMD(device_name+':@'+c)
        
    output_dict['Rollback']=AVX::CONFIG
    
    AVX::OUTPUT(output_dict)

if __name__ == '__main__':
    '''
    Main function
    '''
main()