Beispiel #1
0
def get_trunk_ports(ssh_port, username, password, device):
    """Get trunk ports. Uses NETCONF and Netmiko """

    trunks = []

    # Deletes table data
    DbOps.delete_rows('Trunks_front_end', device)

    for ints in interface_types:
        try:
            current_interfaces = get_config()[0]["native"]["interface"].get(
                ints)
            make_list = is_in_list(current_interfaces)
            for interface in make_list:
                if interface is None:
                    continue

                if interface.get("switchport",
                                 {}).get("trunk",
                                         {}).get("allowed",
                                                 {}).get("vlan",
                                                         {}).get("vlans", {}):
                    # Use netconf interface name to get vlans using netmiko. I find netconf can be untrustworthy sometimes
                    vlans = GetWithNetmiko.indivisual_poll(
                        username,
                        password,
                        device,
                        ssh_port,
                        'trunk_helper',
                        interface=ints + interface.get('name'))
                    # Write dictionary to list and join our vlan list returned from netmiko funtion
                    trunks.append({
                        'interface': ints + interface.get('name'),
                        'vlans': ', '.join(vlans),
                        'cdp': interface.get('name')
                    })

                elif interface.get("switchport",
                                   {}).get("trunk",
                                           {}).get("allowed",
                                                   {}).get("vlan",
                                                           {}).get("add", {}):
                    # Use netconf interface name to get vlans using netmiko. I find netconf can be untrustworthy sometimes
                    vlans = GetWithNetmiko.indivisual_poll(
                        username,
                        password,
                        device,
                        ssh_port,
                        'trunk_helper',
                        interface=ints + interface.get('name'))
                    # Write dictionary to list and join our vlan list returned from netmiko funtion
                    trunks.append({
                        'interface': ints + interface.get('name'),
                        'vlans': ', '.join(vlans),
                        'cdp': interface.get('name')
                    })
        except TypeError:
            pass

    # Iterate through trunk list and interface state. Comapre interface banes and get interface state. Write to database
    for interface in trunks:
        for port in get_stats():
            if interface.get('interface') == port.get('name'):
                DbOps.update_trunks_table(device, interface['interface'],
                                          interface['vlans'],
                                          port.get('admin-status'),
                                          port.get('oper-status'))
Beispiel #2
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))
        })