-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_yabgp.py
77 lines (53 loc) · 1.68 KB
/
my_yabgp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
from flask import Blueprint
import flask
from yabgp.agent import prepare_service
from yabgp.handler import BaseHandler
class APIHandler(object):
blueprint = Blueprint('demo', __name__)
url_prefix = '/v1'
@APIHandler.blueprint.route('/rib')
def root():
"""
v1 api root. Get the api status.
"""
intro = {
'rib': []
}
return flask.jsonify(intro)
class CliHandler(BaseHandler):
"""demo handler implementation
"""
def __init__(self):
super(CliHandler, self).__init__()
def init(self):
pass
def on_update_error(self, peer, timestamp, msg):
print('[-] UPDATE ERROR,', msg)
def route_refresh_received(self, peer, msg, msg_type):
print('[+] ROUTE_REFRESH received,', msg)
def keepalive_received(self, peer, timestamp):
print('[+] KEEPALIVE received')
def open_received(self, peer, timestamp, result):
print('[+] OPEN received,', result)
def update_received(self, peer, timestamp, msg):
print('[+] UPDATE received,', msg)
def notification_received(self, peer, msg):
print('[-] NOTIFICATION received,', msg)
def on_connection_lost(self, peer):
print('[-] CONNECTION lost')
def on_connection_failed(self, peer, msg):
print('[-] CONNECTION failed,', msg)
def on_established(self, peer, msg):
print('[-] ESTABLISHED,', msg)
def main():
try:
cli_handler = CliHandler()
prepare_service(handler=cli_handler, api_hander=APIHandler())
except Exception as e:
print(e)
if __name__ == '__main__':
sys.exit(main())