Example #1
0
def running_config_snmp(context, config, words):
    s_obj_type  = 'snmp-server-config'

    snmp_config = context.get_table_from_store(s_obj_type)
    if len(snmp_config) > 1:
        print 'running_config_snmp: more than one snmp record'
    if len(snmp_config) == 0:
        return

    snmp_config = snmp_config[0]


    s_config = []
    if run_config.not_default_value(s_obj_type, 'community', snmp_config.get('community')):
        s_config.append('snmp-server community ro %s\n' %
                        utif.quote_string(snmp_config['community']))

    if run_config.not_default_value(s_obj_type, 'location', snmp_config.get('location')):
        s_config.append('snmp-server location %s\n' %
                        utif.quote_string(snmp_config['location']))

    if run_config.not_default_value(s_obj_type, 'contact', snmp_config.get('contact')):
        s_config.append('snmp-server contact %s\n' %
                        utif.quote_string(snmp_config['contact']))
    if run_config.not_default_value(s_obj_type, 'server-enable', snmp_config['server-enable']):
        s_config.append('snmp-server enable\n')

    if len(s_config):   
        config.append('!\n')
        config += s_config
def running_config_forwarding(context, config, words):
    t_obj_type = 'forwarding-config'

    forwarding_table = context.get_table_from_store(t_obj_type)
    if len(forwarding_table) > 1:
        print 'running_config_forwarding: more than one forwarding record'
    if len(forwarding_table) == 0:
        return

    forwarding_config = forwarding_table[0]
    newline_printed = False
    if run_config.not_default_value(
            t_obj_type, 'access-priority',
            forwarding_config.get('access-priority')):
        if newline_printed is False:
            newline_printed = True
            config.append("!\n")
        config.append(
                'forwarding access-priority %s\n' %
                forwarding_config.get('access-priority'))
    if run_config.not_default_value(
            t_obj_type, 'core-priority',
            forwarding_config.get('core-priority')):
        if newline_printed is False:
            newline_printed = True
            config.append("!\n")
        config.append(
                'forwarding core-priority %s\n' %
                forwarding_config.get('core-priority'))
def running_config_tacacs(context, config, words):
    t_obj_type  = 'tacacs-plus-config'
    th_obj_type = 'tacacs-plus-host'

    tacacs = context.get_table_from_store(t_obj_type)
    if len(tacacs) > 1:
        print 'running_config_tacacs: more than one tacacs record'

    tacacs_host = context.rest_query_objects(th_obj_type,
                                             {'orderby' : 'timestamp'})


    t_config = []

    if tacacs:
        tacacs = tacacs[0]

        if run_config.not_default_value(t_obj_type, 'tacacs-plus-authn', tacacs['tacacs-plus-authn']) and \
           run_config.not_default_value(t_obj_type, 'local-authn', tacacs['local-authn']):
            t_config.append('aaa authentication login default group tacacs+\n')
        elif run_config.not_default_value(t_obj_type, 'tacacs-plus-authn', tacacs['tacacs-plus-authn']):
            t_config.append('aaa authentication login default group tacacs+ local\n')

        if run_config.not_default_value(t_obj_type, 'tacacs-plus-authz', tacacs['tacacs-plus-authz']) and \
           run_config.not_default_value(t_obj_type, 'local-authz', tacacs['local-authz']):
            t_config.append('aaa authorization exec default group tacacs+\n')
        elif run_config.not_default_value(t_obj_type, 'tacacs-plus-authz', tacacs['tacacs-plus-authz']):
            t_config.append('aaa authorization exec default group tacacs+ local\n')

        if run_config.not_default_value(t_obj_type, 'tacacs-plus-acct', tacacs['tacacs-plus-acct']):
            t_config.append('aaa accounting exec default start-stop group tacacs+\n')

        if run_config.not_default_value(t_obj_type, 'key', tacacs['key']):
            t_config.append('tacacs server key %s\n' % tacacs['key'])

        if run_config.not_default_value(t_obj_type, 'timeout', tacacs['timeout']):
            t_config.append('tacacs server timeout %s\n' % tacacs['timeout'])

    for h in tacacs_host:
        if run_config.not_default_value(th_obj_type, 'key', h['key']):
            key = ' key %s' %  utif.quote_string(h['key'])
        else:
            key = ''

        t_config.append('tacacs server host %s%s\n' % (h['ip'], key))

    if len(t_config):   
        config.append('!\n')
        config += t_config
def running_config_forwarding(context, config, words):
    t_obj_type = "forwarding-config"

    forwarding_table = context.get_table_from_store(t_obj_type)
    if len(forwarding_table) > 1:
        print "running_config_forwarding: more than one forwarding record"
    if len(forwarding_table) == 0:
        return

    forwarding_config = forwarding_table[0]
    newline_printed = False
    if run_config.not_default_value(t_obj_type, "access-priority", forwarding_config.get("access-priority")):
        if newline_printed is False:
            newline_printed = True
            config.append("!\n")
        config.append("forwarding access-priority %s\n" % forwarding_config.get("access-priority"))
    if run_config.not_default_value(t_obj_type, "core-priority", forwarding_config.get("core-priority")):
        if newline_printed is False:
            newline_printed = True
            config.append("!\n")
        config.append("forwarding core-priority %s\n" % forwarding_config.get("core-priority"))
Example #5
0
def running_config_topology(context, config, words):
    t_obj_type = 'topology-config'
    
    topology_config = context.get_table_from_store(t_obj_type)
    if len(topology_config) > 1:
        print 'running_config_topology: more than one topology record'
    if len(topology_config) == 0:
        return

    topology_config = topology_config[0]

    if run_config.not_default_value(t_obj_type, 'autoportfast',
                                topology_config.get('autoportfast')):
        config.append('\nno topology autoportfast\n')