def layer_2(): """Gets layer two information from the device""" cdp = GetInfo.get_cdp_neighbors(netmiko_session) vlans = GetInfo.get_netmiko_vlans(netmiko_session) spanning_tree = GetInfo.get_span_root(netmiko_session) mac_to_arp = GetInfo.get_mac_arp_table(netmiko_session) trunks = GetInterfacesInfo.get_trunk_ports(netconf_session) access_ports = GetInterfacesInfo.get_access_ports(netconf_session) port_channels = GetInterfacesInfo.get_port_channels(netconf_session) return render_template('get_layer_two.html', neighbors=cdp, vlans=vlans, trunks=trunks, access_ports=access_ports, port_chan=port_channels, roots=spanning_tree, mac_arp=mac_to_arp)
def clear_counters(netmiko_connection, interface, netconf_session): """Clears interface counters""" send_command(netmiko_connection, f"clear counters {interface}", expect_string="[confirm]") send_command(netmiko_connection, "\n", expect_string="#") refresh_interfaces = GetInterfacesInfo.get_ip_interfaces(netconf_session) return refresh_interfaces[0]
def modify_inteface(interface): """POST BGP configuration from form data""" reformat_interface = interface.replace('%2f', '/') vrfs = GetInfo.get_vrfs(netmiko_session) mac = GetInterfacesInfo.get_single_interfaces(netconf_session, reformat_interface) return render_template('modify_interface.html', interface=reformat_interface, vrfs=vrfs, mgmt_int=management_int, mac=mac[0].get(reformat_interface).get('MAC'))
def submit_inteface(): """POST interface configuration from form data""" global unassigned_ints, interface_nums ip = None mask = None status = None descr = None vrf = None negotiation = None int_num = [ i for i in request.form.get("interface") if i not in string.ascii_letters ] int_type = [ i for i in request.form.get("interface") if i in string.ascii_letters ] interface = BuildInterface.Templates(''.join(int_type), ''.join(int_num)) if request.form.get('ip') and request.form.get('mask'): ip = request.form.get('ip') mask = request.form.get('mask') if request.form.get('status'): status = request.form.get('status') if request.form.get('description'): descr = request.form.get('description') if request.form.get('vrf'): vrf = request.form.get('vrf') if request.form.get('negotiation'): negotiation = request.form.get('negotiation') if request.form.get('vlan'): negotiation = request.form.get('negotiation') config = interface.build_interface(ip, mask, status, descr, vrf, negotiation) status = SendConfig.send_configuration(netconf_session, config) if status == 'Success': show_interfaces = GetInterfacesInfo.get_ip_interfaces(netconf_session) unassigned_ints = show_interfaces[2] interface_nums = show_interfaces[3] return jsonify({ 'data': render_template('interface_table.html', interfaces=show_interfaces[0]) }) else: return jsonify( {'data': render_template('config_failed.html', status=status)})
def get_routing(): """Gets all things routing, arp, interfaces, routing protocols""" global get_interfaces, local_as, netconf_session, management_int, unassigned_ints, interface_nums netconf_session = ConnectWith.create_netconf_connection(username, password, device) get_interfaces = GetInterfacesInfo.get_ip_interfaces(netconf_session, device) management_int = get_interfaces[1] unassigned_ints = get_interfaces[2] interface_nums = get_interfaces[3] bgp_status = GetInfo.get_bgp_status(netmiko_session) local_as = bgp_status[1][0] ospf_status = GetInfo.get_ospf_status(netmiko_session) arp_table = GetInfo.get_arp(netmiko_session) return render_template('routing.html', interfaces=get_interfaces[0], bgp=bgp_status[0], ospf=ospf_status, arp=arp_table, intial='yes')
def table_refresh(): """Used for table refreshes""" action = request.form.get('action') # Used for refreshing tables without page reload, return data to call wich is js/ajax if action == 'arp': clear = GetInfo.clear_arp(netmiko_session) return jsonify( {'data': render_template('refresh_arp.html', arps=clear)}) elif action == 'bgp': get_status = GetInfo.get_bgp_status(netmiko_session) return jsonify( {'data': render_template('refresh_bgp.html', bgp=get_status[0])}) elif action == 'ospf': get_status = GetInfo.get_ospf_status(netmiko_session) return jsonify( {'data': render_template('refresh_ospf.html', ospf=get_status)}) elif action == 'clearInt': clear = GetInfo.clear_counters(netmiko_session, request.form.get('interface'), netconf_session) return jsonify( {'data': render_template('refresh_table.html', interfaces=clear)}) elif action == 'mac': mac_to_arp = GetInfo.get_mac_arp_table(netmiko_session) return jsonify( {'data': render_template('refresh_mac.html', mac_arp=mac_to_arp)}) elif action == 'cdp': cdp = GetInfo.get_cdp_neighbors(netmiko_session) return jsonify( {'data': render_template('refresh_cdp.html', neighbors=cdp)}) elif action == 'access': access_ports = GetInterfacesInfo.get_access_ports(netconf_session) return jsonify({ 'data': render_template('refresh_access.html', access_ports=access_ports) }) elif action == 'span': spanning_tree = GetInfo.get_span_root(netmiko_session) return jsonify({ 'data': render_template('refresh_span.html', roots=spanning_tree) })