Exemple #1
0
def populate_infodict(request, account, netbox, interfaces):
    """Populate a dictionary used in every http response"""

    allowed_vlans = []
    voice_vlan = None
    readonly = False
    try:
        fac = get_and_populate_livedata(netbox, interfaces)
        allowed_vlans = find_and_populate_allowed_vlans(
            account, netbox, interfaces, fac)
        voice_vlan = fetch_voice_vlan_for_netbox(request, fac)
        mark_detained_interfaces(interfaces)
    except TimeOutException:
        readonly = True
        messages.error(
            request, "Timeout when contacting %s. Values displayed "
            "are from database" % netbox.sysname)
        if not netbox.read_only:
            messages.error(request, "Read only community not set")
    except SnmpError:
        readonly = True
        messages.error(
            request, "SNMP error when contacting %s. Values "
            "displayed are from database" % netbox.sysname)

    if check_read_write(netbox, request):
        readonly = True

    ifaliasformat = get_ifaliasformat()
    aliastemplate = ''
    if ifaliasformat:
        tmpl = get_aliastemplate()
        aliastemplate = tmpl.render(Context({'ifaliasformat': ifaliasformat}))

    save_to_database(interfaces)

    if voice_vlan:
        set_voice_vlan_attribute(voice_vlan, interfaces)

    info_dict = get_base_context([(netbox.sysname, )])
    info_dict.update({
        'interfaces': interfaces,
        'netbox': netbox,
        'voice_vlan': voice_vlan,
        'allowed_vlans': allowed_vlans,
        'account': account,
        'readonly': readonly,
        'aliastemplate': aliastemplate
    })
    return info_dict
Exemple #2
0
def populate_infodict(request, account, netbox, interfaces):
    """Populate a dictionary used in every http response"""

    allowed_vlans = []
    voice_vlan = None
    readonly = False
    try:
        fac = get_and_populate_livedata(netbox, interfaces)
        allowed_vlans = find_and_populate_allowed_vlans(account, netbox,
                                                        interfaces, fac)
        voice_vlan = fetch_voice_vlan_for_netbox(request, fac)
        mark_detained_interfaces(interfaces)
    except TimeOutException:
        readonly = True
        messages.error(request, "Timeout when contacting %s. Values displayed "
                                "are from database" % netbox.sysname)
        if not netbox.read_only:
            messages.error(request, "Read only community not set")
    except SnmpError:
        readonly = True
        messages.error(request, "SNMP error when contacting %s. Values "
                                "displayed are from database" % netbox.sysname)

    if check_read_write(netbox, request):
        readonly = True

    ifaliasformat = get_ifaliasformat()
    aliastemplate = ''
    if ifaliasformat:
        tmpl = get_aliastemplate()
        aliastemplate = tmpl.render(Context({'ifaliasformat': ifaliasformat}))

    save_to_database(interfaces)

    if voice_vlan:
        set_voice_vlan_attribute(voice_vlan, interfaces)

    info_dict = get_base_context([(netbox.sysname, )])
    info_dict.update({'interfaces': interfaces,
                      'netbox': netbox,
                      'voice_vlan': voice_vlan,
                      'allowed_vlans': allowed_vlans,
                      'account': account,
                      'readonly': readonly,
                      'aliastemplate': aliastemplate})
    return info_dict
Exemple #3
0
def populate_infodict(request, netbox, interfaces):
    """Populate a dictionary used in every http response"""
    allowed_vlans = []
    voice_vlan = None
    readonly = False
    config = read_config()

    try:
        fac = get_and_populate_livedata(netbox, interfaces)
        allowed_vlans = find_and_populate_allowed_vlans(
            request.account, netbox, interfaces, fac)
        voice_vlan = fetch_voice_vlan_for_netbox(request, fac, config)
        if voice_vlan:
            if is_cisco_voice_enabled(config) and is_cisco(netbox):
                set_voice_vlan_attribute_cisco(voice_vlan, interfaces, fac)
            else:
                set_voice_vlan_attribute(voice_vlan, interfaces)
        mark_detained_interfaces(interfaces)
        if is_dot1x_enabled(config):
            add_dot1x_info(interfaces, fac)
    except TimeOutException:
        readonly = True
        messages.error(
            request, "Timeout when contacting %s. Values displayed "
            "are from database" % netbox.sysname)
        if not netbox.read_only:
            messages.error(request, "Read only community not set")
    except SnmpError:
        readonly = True
        messages.error(
            request, "SNMP error when contacting %s. Values "
            "displayed are from database" % netbox.sysname)

    if check_read_write(netbox, request):
        readonly = True

    ifaliasformat = get_ifaliasformat(config)
    aliastemplate = ''
    if ifaliasformat:
        tmpl = get_aliastemplate()
        aliastemplate = tmpl.render({'ifaliasformat': ifaliasformat})

    save_to_database(interfaces)

    auditlog_api_parameters = {
        'object_model': 'interface',
        'object_pks': ','.join([str(i.pk) for i in interfaces]),
        'subsystem': 'portadmin'
    }

    info_dict = get_base_context([(netbox.sysname, )], form=get_form(request))
    info_dict.update({
        'interfaces':
        interfaces,
        'netbox':
        netbox,
        'voice_vlan':
        voice_vlan,
        'allowed_vlans':
        allowed_vlans,
        'readonly':
        readonly,
        'aliastemplate':
        aliastemplate,
        'trunk_edit':
        get_trunk_edit(config),
        'auditlog_api_parameters':
        json.dumps(auditlog_api_parameters)
    })
    return info_dict