Exemplo n.º 1
0
def config():

    config_form = ConfigForm()
    peer_form = BGPPeer()
    
    if config_form.validate_on_submit():
        
        bgp_config.update(bgp_config.find_one(), 
            {'$set': {
                'local-as': int(config_form.asn.data),
                'router-id': config_form.router_id.data,
                'local-address': config_form.local_ip.data
            }
        })

        flash('Config successfully updated.', 'success')
        return redirect(url_for('config', _anchor='exabgp'))

    if peer_form.validate_on_submit():
            
        try:
            # Create the new peer
            new_peer = {
                'ip': peer_form.ip_address.data,
                'asn': int(peer_form.asn.data),
                'state': 'down',
                'enabled': peer_form.enabled.data
            }

            bgp_peers.insert_one(new_peer)
        except:
            flash('Error adding peer %s.' % peer_form.ip_address.data, 'warning')
        else:
            flash('Peer %s added' % peer_form.ip_address.data, 'success')

        return redirect(url_for('config', _anchor='peers'))

    else:

        peers = list(bgp_peers.find())
        config = bgp_config.find_one()
        prefix_counts = {}
        for peer in bgp_peers.find():
            prefix_counts[peer['ip']] = {
                'received': len(bgp_peers.distinct('current_prefixes', {'ip': {'$eq': peer['ip']}})),
                'advertised': len(adv_routes.distinct('prefix', {'peer': {'$eq': peer['ip']}}))
            }

        config_form.asn.data = config['local-as']
        config_form.router_id.data = config['router-id']
        config_form.local_ip.data = config['local-address']

        return render_template('config.html', peers=peers, config=config, 
            config_form=config_form, peer_form=peer_form, prefix_counts=prefix_counts)
Exemplo n.º 2
0
def config():
    config_form = ConfigForm()
    peer_form = BGPPeer()

    if config_form.validate_on_submit():
        bgp_config.update(bgp_config.find_one(),
                          {'$set': {
                              'local-as': int(config_form.asn.data),
                              'router-id': config_form.router_id.data,
                              'local-address': config_form.local_ip.data
                          }
                          })

        flash('Config successfully updated.', 'success')
        return redirect(url_for('config', _anchor='exabgp'))

    if peer_form.validate_on_submit():

        try:
            # Create the new peer
            new_peer = {
                'ip': peer_form.ip_address.data,
                'asn': int(peer_form.asn.data),
                'state': 'down',
                'enabled': peer_form.enabled.data
            }

            bgp_peers.insert_one(new_peer)
        except:
            flash('Error adding peer %s.' % peer_form.ip_address.data, 'warning')
        else:
            flash('Peer %s added' % peer_form.ip_address.data, 'success')

        return redirect(url_for('config', _anchor='peers'))

    else:

        peers = list(bgp_peers.find())
        config = bgp_config.find_one()
        prefix_counts = {}
        for peer in bgp_peers.find():
            prefix_counts[peer['ip']] = {
                'received': len(bgp_peers.distinct('current_prefixes', {'ip': {'$eq': peer['ip']}})),
                'advertised': len(adv_routes.distinct('prefix', {'peer': {'$eq': peer['ip']}}))
            }

        config_form.asn.data = config['local-as']
        config_form.router_id.data = config['router-id']
        config_form.local_ip.data = config['local-address']

        return render_template('config.html', peers=peers, config=config,
                               config_form=config_form, peer_form=peer_form, prefix_counts=prefix_counts)
Exemplo n.º 3
0
def dashboard():
    prefixes_out = adv_routes.distinct('prefix')
    prefixes_out_count = len(prefixes_out)
    prefixes_in = bgp_peers.distinct('current_prefixes')
    prefixes_in_count = len(prefixes_in)

    peers = list(bgp_peers.find())

    overview_counts = {
        'prefixes_out': prefixes_out,
        'prefixes_out_count': prefixes_out_count,
        'prefixes_out_count': prefixes_out_count,
        'prefixes_in': prefixes_in,
        'prefixes_in_count': prefixes_in_count,
    }

    return render_template('dashboard.html', overview_counts=overview_counts, peers=peers)