Exemplo n.º 1
0
def ping(source):
    """Renders ping form and sends ping"""

    if not request.form:
        return render_template('ping.html',
                               source=source.replace('%2f', '/'),
                               vrfs=QueryDbFor.query_vrfs(device))
    else:
        if request.form.get('vrf') == 'none':
            ping = GetNetmiko.send_ping(netmiko_session, netmiko_session,
                                        username, password, device,
                                        request.form.get('dest'),
                                        request.form.get('source'),
                                        request.form.get('count'))
        else:
            ping = GetNetmiko.send_ping(netmiko_session,
                                        username,
                                        password,
                                        device,
                                        request.form.get('dest'),
                                        request.form.get('source'),
                                        request.form.get('count'),
                                        vrf=request.form.get('vrf'))

        return render_template('ping.html',
                               source=source.replace('%2f', '/'),
                               vrfs=QueryDbFor.query_vrfs(device),
                               results=ping)
Exemplo n.º 2
0
def modify_inteface(interface):
    """Renders and build configurations for interface modification"""

    if not request.form:
        current_config = GetNetmiko.current_int_config(
            netmiko_session, interface.replace('%2f', '/'))

        return render_template('modify_interface.html',
                               interface=interface.replace('%2f', '/'),
                               vrfs=QueryDbFor.query_vrfs(device),
                               current_config=current_config,
                               mgmt_int=[
                                   i
                                   for i in QueryDbFor.query_interfaces(device)
                                   if i.id == device
                               ],
                               model=model[:3][-2:])
    else:
        status = BuildConfig.parse_int_form(request.form, device, password,
                                            username)
        current_config = GetNetmiko.current_int_config(
            netmiko_session, interface.replace('%2f', '/'))

        return render_template('modify_interface.html',
                               interface=interface.replace('%2f', '/'),
                               vrfs=QueryDbFor.query_vrfs(device),
                               mgmt_int=[
                                   i
                                   for i in QueryDbFor.query_interfaces(device)
                                   if i.id == device
                               ],
                               current_config=current_config,
                               model=model[:3][-2:],
                               status=status)
Exemplo n.º 3
0
def add_bgp_neighbor():
    """POST BGP configuration from form data"""

    # Remove duplicate prefix-list names for html dropdown
    lists = [i.name for i in QueryDbFor.query_prefix_list(device)]

    return render_template('add_bgp_neighbor.html',
                           prefixes=list(dict.fromkeys(lists)),
                           route_map=QueryDbFor.query_route_maps(device))
Exemplo n.º 4
0
def new_interface():
    """POST new interface"""

    if not request.form:
        return render_template('new_int_form.html',
                               vrfs=QueryDbFor.query_vrfs(device))
    else:
        status = BuildConfig.parse_int_form(request.form, device, password,
                                            username)
        interface = request.form.get('newIntCustomForm').splitlines()
        current_config = GetNetmiko.current_int_config(netmiko_session,
                                                       interface[0].split()[1])

        return render_template('new_int_form.html',
                               vrfs=QueryDbFor.query_vrfs(device),
                               current_config=current_config,
                               status=status)
Exemplo n.º 5
0
def add_poch():
    """Renders vlan configuration form"""

    # Remove duplicate channel-group numbers for html dropdown
    groups = [i.group for i in QueryDbFor.query_port_channels(device)]

    if not request.form:
        return render_template(
            'add_poch.html',
            interfaces=QueryDbFor.query_interfaces(device),
            port_channels=list(dict.fromkeys(groups)),
            int_status=QueryDbFor.query_access_ports(device))
    else:
        channel_mode = [
            i.mode for i in QueryDbFor.query_port_channels(device)
            if request.form.get('pochannel') == i.group
        ]
        status = BuildConfig.parse_poch_interface(
            request.form, list(dict.fromkeys(channel_mode)), device, password,
            username)
        current_config = GetNetmiko.current_int_config(
            netmiko_session, request.form.get('interface'))

        return render_template(
            'add_poch.html',
            interfaces=QueryDbFor.query_interfaces(device),
            port_channels=groups,
            int_status=QueryDbFor.query_access_ports(device),
            current_config=current_config,
            status=status)
Exemplo n.º 6
0
def modify_access_interface(interface):
    """POST BGP configuration from form data"""

    if not request.form:
        current_config = GetNetmiko.current_int_config(
            netmiko_session, interface.replace('%2f', '/'))

        return render_template('modify_access_int.html',
                               interface=interface.replace('%2f', '/'),
                               current_config=current_config,
                               vlans=QueryDbFor.query_vlans(device))
    else:
        status = BuildConfig.parse_access_int_form(request.form, device,
                                                   password, username)
        current_config = GetNetmiko.current_int_config(
            netmiko_session, interface.replace('%2f', '/'))

        return render_template('modify_access_int.html',
                               interface=interface.replace('%2f', '/'),
                               current_config=current_config,
                               vlans=QueryDbFor.query_vlans(device),
                               status=status)
Exemplo n.º 7
0
def modify_trunk_interface(interface):
    """Render trunk modification page"""

    if not request.form:
        current_config = GetNetmiko.current_int_config(
            netmiko_session, interface.replace('%2f', '/'))

        return render_template('modify_trunk_int.html',
                               interface=interface.replace('%2f', '/'),
                               current_config=current_config,
                               vlans=QueryDbFor.query_vlans(device))
    else:
        status = BuildConfig.parse_trunk_interface(request.form, device,
                                                   password, username)
        current_config = GetNetmiko.current_int_config(
            netmiko_session, interface.replace('%2f', '/'))

        return render_template('modify_trunk_int.html',
                               interface=interface.replace('%2f', '/'),
                               current_config=current_config,
                               vlans=QueryDbFor.query_vlans(device),
                               status=status)
Exemplo n.º 8
0
def layer_2():
    """Gets layer two information from the device"""

    return render_template('get_layer_two.html',
                           neighbors=QueryDbFor.query_cdp(device),
                           vlans=QueryDbFor.query_vlans(device),
                           trunks=QueryDbFor.query_trunks(device),
                           access_ports=QueryDbFor.query_access_ports(device),
                           port_chan=QueryDbFor.query_port_channels(device),
                           roots=QueryDbFor.query_spanning_tree(device),
                           mac_arp=QueryDbFor.query_mac_to_arp(device),
                           model=model)
Exemplo n.º 9
0
def parse_int_form(form, device, password, username):
    """Parse, build, send info for interface configuration"""

    ip, mask, status, descr, vrf, switchport = None, None, None, None, None, None

    if not form.get('newIntCustomForm'):
        if form.get('ip') and form.get('mask'):
            ip = form.get('ip')
            mask = form.get('mask')
        if form.get('status'):
            status = form.get('status')
        if form.get('description'):
            descr = form.get('description')
        if form.get('vrf'):
            vrf = form.get('vrf')
        if form.get('negotiation'):
            negotiation = form.get('negotiation')
        if form.get('vlan'):
            negotiation = form.get('negotiation')
        if form.get('switchport'):
            switchport = form.get('switchport')

        # Convert interface number back to slashes from %2f
        int_num = [
            i for i in form.get("interface") if i not in string.ascii_letters
        ]
        int_type = [
            i for i in form.get("interface") if i in string.ascii_letters
        ]

        # Validate interface perameters
        validation = ValidateConfig.validate_interface(
            ''.join(int_type) + ''.join(int_num), ip, mask, status, vrf, descr,
            QueryDbFor.query_interfaces(device))
        config = build_interface(''.join(int_type) + ''.join(int_num), ip,
                                 mask, status, vrf, descr, switchport)
        # If validation passes which is 0, send config, update DB
        if validation == 0:
            status = send_config(device, username, password, config)
            DbOps.update_configurations(device, username, config,
                                        "Modify/Add Interface")
    else:
        status = send_config_cli(device, username, password,
                                 form.get('newIntCustomForm'))
        DbOps.update_configurations(device, username,
                                    form.get('newIntCustomForm'),
                                    "Modify/Add Interface")

    return status
Exemplo n.º 10
0
def index():
    """Gets all things routing, arp, interfaces, routing protocols"""
    return render_template(
        'index.html',
        interfaces=QueryDbFor.query_interfaces(device),
        bgp=QueryDbFor.query_bgp_status(device),
        ospf=QueryDbFor.query_ospf_status(device),
        arp=QueryDbFor.query_arp_table(device),
        hsrp=QueryDbFor.query_hsrp(device),
        border_routers=QueryDbFor.query_ospf_routers(device),
        device=device)
Exemplo n.º 11
0
def dmvpn():
    """Gets layer two information from the device"""

    return render_template(
        'get_dmvpn.html',
        dmvpn_status=QueryDbFor.query_dmvpn_status(device),
        dmvpn_peer_count=QueryDbFor.query_dmvpn_type(device),
        dmvpn_ints=QueryDbFor.query_dmvpn_interfaces(device),
        ospf=QueryDbFor.query_ospf_status(device),
        border_routers=QueryDbFor.query_ospf_routers(device),
        ints=QueryDbFor.query_interfaces(device))
Exemplo n.º 12
0
def add_vlan():
    """Renders vlan configuration form"""

    if not request.form:
        return render_template(
            'add_vlan.html',
            access_ports=QueryDbFor.query_access_ports(device),
            port_channels=QueryDbFor.query_port_channels(device),
            vlans=QueryDbFor.query_vlans(device))
    else:
        status = BuildConfig.parse_add_vlan_form(request.form, device,
                                                 password, username)

        return render_template(
            'add_vlan.html',
            access_ports=QueryDbFor.query_access_ports(device),
            port_channels=QueryDbFor.query_port_channels(device),
            vlans=QueryDbFor.query_vlans(device),
            status=status)
Exemplo n.º 13
0
def routing_table():
    """Gets IOS-XE routing table"""

    return render_template('get_routing.html',
                           route_table=QueryDbFor.query_routes(device))
Exemplo n.º 14
0
def route_default():
    return render_template('inventory.html',
                           inventory=QueryDbFor.query_device_inventory())
Exemplo n.º 15
0
def get_qos():
    """Gets Qos policy stats, CLI view"""

    return render_template('qos.html',
                           interfaces=QueryDbFor.query_interfaces(device),
                           interface_qos=QueryDbFor.query_qos(device))
Exemplo n.º 16
0
def add_ospf_neighbor():
    """Render OSPF configuration/Form"""

    return render_template('add_ospf_neighbor.html',
                           ospf_proc=QueryDbFor.query_ospf_processes(device))
Exemplo n.º 17
0
def table_refresh():
    """Used for table refreshes"""

    # Get for attribute 'name', match condition, refresh data table

    if request.form.get('action') == 'arp':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port, 'arp')
        return jsonify({
            'data':
            render_template('refresh_arp.html',
                            arps=QueryDbFor.query_arp_table(device))
        })
    elif request.form.get('action') == 'bgp':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port, 'bgp')
        return jsonify({
            'data':
            render_template('refresh_bgp.html',
                            bgp=QueryDbFor.query_bgp_status(device))
        })
    elif request.form.get('action') == 'ospf':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'ospf')
        return jsonify({
            'data':
            render_template('refresh_ospf.html',
                            ospf=QueryDbFor.query_ospf_status(device))
        })
    elif request.form.get('action') == 'mac':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port, 'mac')
        return jsonify({
            'data':
            render_template('refresh_mac.html',
                            mac_arp=QueryDbFor.query_mac_to_arp(device))
        })
    elif request.form.get('action') == 'cdp':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port, 'cdp')
        return jsonify({
            'data':
            render_template('refresh_cdp.html',
                            neighbors=QueryDbFor.query_cdp(device))
        })
    elif request.form.get('action') == 'access':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'access')
        return jsonify({
            'data':
            render_template('refresh_access.html',
                            access_ports=QueryDbFor.query_access_ports(device))
        })
    elif request.form.get('action') == 'span':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'span')
        return jsonify({
            'data':
            render_template('refresh_span.html',
                            roots=QueryDbFor.query_spanning_tree(device))
        })
    elif request.form.get('action') == 'clearArp':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'clearArp')
        return jsonify({
            'data':
            render_template('refresh_arp.html',
                            arp=QueryDbFor.query_arp_table(device))
        })
    elif request.form.get('action') == 'refreshArp':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'refreshArp')
        return jsonify({
            'data':
            render_template('refresh_arp.html',
                            arp=QueryDbFor.query_arp_table(device))
        })
    elif request.form.get('action') == 'vlans':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'vlans')
        return jsonify({
            'data':
            render_template('refresh_vlans.html',
                            vlans=QueryDbFor.query_vlans(device))
        })
    elif request.form.get('action') == 'portChannel':
        GetNeconf.indivisual_poll(username, password, device, netconf_port,
                                  'portchannel')
        return jsonify({
            'data':
            render_template('refresh_port_channels.html',
                            port_chan=QueryDbFor.query_port_channels(device))
        })
    elif request.form.get('action') == 'trunks':
        GetNeconf.indivisual_poll(username,
                                  password,
                                  device,
                                  netconf_port,
                                  'trunks',
                                  ssh_port=ssh_port)
        return jsonify({
            'data':
            render_template('refresh_trunks.html',
                            trunks=QueryDbFor.query_trunks(device))
        })
    elif request.form.get('action') == 'interfaces':
        GetNeconf.indivisual_poll(username, password, device, netconf_port,
                                  'interfaces')
        return jsonify({
            'data':
            render_template('refresh_table.html',
                            interfaces=QueryDbFor.query_interfaces(device))
        })
    elif request.form.get('action') == 'hsrp':
        GetNeconf.indivisual_poll(username, password, device, netconf_port,
                                  'hsrp')
        return jsonify({
            'data':
            render_template('refresh_hsrp.html',
                            hsrp=QueryDbFor.query_hsrp(device))
        })
    elif request.form.get('action') == 'peer_count':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'peer_count')
        return jsonify({
            'data':
            render_template('dmvpn_peer_refresh.html',
                            dmvpn_status=QueryDbFor.query_dmvpn_status(device))
        })
    elif request.form.get('action') == 'borderRouters':
        GetNetmiko.indivisual_poll(username, password, device, ssh_port,
                                   'borderRouters')
        return jsonify({
            'data':
            render_template(
                'refresh_border_routers.html',
                border_routers=QueryDbFor.query_ospf_routers(device))
        })