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
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
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
def populate_infodict(request, netbox, interfaces): """Populate a dictionary used in every http response""" allowed_vlans = [] voice_vlan = None readonly = False handler = None try: handler = get_and_populate_livedata(netbox, interfaces) allowed_vlans = find_and_populate_allowed_vlans( request.account, netbox, interfaces, handler) voice_vlan = fetch_voice_vlan_for_netbox(request, handler) if voice_vlan: if CONFIG.is_cisco_voice_enabled() and is_cisco(netbox): set_voice_vlan_attribute_cisco(voice_vlan, interfaces, handler) else: set_voice_vlan_attribute(voice_vlan, interfaces) mark_detained_interfaces(interfaces) if CONFIG.is_dot1x_enabled(): add_dot1x_info(interfaces, handler) except NoResponseError: readonly = True messages.error( request, "%s did not respond within the set timeouts. Values displayed are from database" % netbox.sysname, ) if isinstance(handler, SNMPHandler) and not netbox.read_only: messages.error(request, "Read only community not set") except ProtocolError: readonly = True messages.error( request, "Protocol error when contacting %s. Values displayed are from database" % netbox.sysname, ) except DeviceNotConfigurableError as error: readonly = True messages.error(request, str(error)) if handler and not handler.is_configurable(): add_readonly_reason(request, handler) readonly = True ifaliasformat = CONFIG.get_ifaliasformat() 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({ 'handlertype': type(handler).__name__, 'interfaces': interfaces, 'netbox': netbox, 'voice_vlan': voice_vlan, 'allowed_vlans': allowed_vlans, 'readonly': readonly, 'aliastemplate': aliastemplate, 'trunk_edit': CONFIG.get_trunk_edit(), 'auditlog_api_parameters': json.dumps(auditlog_api_parameters), }) return info_dict