summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-06-29 14:43:19 +0900
committerSatoshi Fujimoto <satoshi.fujimoto7@gmail.com>2017-06-30 13:29:51 +0900
commitba2ac3e45272f2231494195335e706f2374ec877 (patch)
tree9aea46f03797db1d9abfa85eebd386c840107b56
parentb81e2fd806055400307098af5fc426d7ae4b6515 (diff)
grpc: Update Python sample and doc for GoBGP v1.20 gRPC API
Signed-off-by: Satoshi Fujimoto <satoshi.fujimoto7@gmail.com>
-rw-r--r--docs/sources/grpc-client.md14
-rw-r--r--tools/grpc/python/get_neighbor.py31
2 files changed, 22 insertions, 23 deletions
diff --git a/docs/sources/grpc-client.md b/docs/sources/grpc-client.md
index 8320ec6e..32acef14 100644
--- a/docs/sources/grpc-client.md
+++ b/docs/sources/grpc-client.md
@@ -36,15 +36,13 @@ $ protoc -I $GOBGP_API --python_out=. --grpc_out=. --plugin=protoc-gen-grpc=`wh
Let's run this script.
```bash
-$ source ~/venv/bin/activate
-(venv)$ python get_neighbor.py 10.0.255.1 10.0.0.1
-BGP neighbor is 10.0.0.1, remote AS 65001
- BGP version 4, remote router ID 192.168.0.1
- BGP state = BGP_FSM_ESTABLISHED, up for 9042
+$ python get_neighbor.py 172.18.0.2
+BGP neighbor is 10.0.0.2, remote AS 65002
+ BGP version 4, remote router ID
+ BGP state = active, up for 0
BGP OutQ = 0, Flops = 0
- Hold time is 30, keepalive interval is 10 seconds
- Configured hold time is 30, keepalive interval is 10 seconds
-
+ Hold time is 0, keepalive interval is 0 seconds
+ Configured hold time is 90, keepalive interval is 30 seconds
```
We got the neighbor information successfully.
diff --git a/tools/grpc/python/get_neighbor.py b/tools/grpc/python/get_neighbor.py
index 3a57fdb8..ff94569d 100644
--- a/tools/grpc/python/get_neighbor.py
+++ b/tools/grpc/python/get_neighbor.py
@@ -1,27 +1,28 @@
+import gobgp_pb2_grpc
import gobgp_pb2
import sys
-from grpc.beta import implementations
+import grpc
from grpc.framework.interfaces.face.face import ExpirationError
_TIMEOUT_SECONDS = 1
def run(gobgpd_addr):
- channel = implementations.insecure_channel(gobgpd_addr, 50051)
- with gobgp_pb2.beta_create_GobgpApi_stub(channel) as stub:
- try:
- peers = stub.GetNeighbor(gobgp_pb2.GetNeighborRequest(), _TIMEOUT_SECONDS).peers
- for peer in peers:
- print("BGP neighbor is %s, remote AS %d" % (peer.conf.neighbor_address, peer.conf.peer_as))
- print(" BGP version 4, remote router ID %s" % (peer.conf.id))
- print(" BGP state = %s, up for %s" % (peer.info.bgp_state, peer.timers.state.uptime))
- print(" BGP OutQ = %d, Flops = %d" % (peer.info.out_q, peer.info.flops))
- print(" Hold time is %d, keepalive interval is %d seconds" % (peer.timers.state.negotiated_hold_time, peer.timers.state.keepalive_interval))
- print(" Configured hold time is %d, keepalive interval is %d seconds" % (peer.timers.config.hold_time, peer.timers.config.keepalive_interval))
- except ExpirationError, e:
- print str(e)
- sys.exit(-1)
+ channel = grpc.insecure_channel(gobgpd_addr + ':50051')
+ stub = gobgp_pb2_grpc.GobgpApiStub(channel)
+ try:
+ peers = stub.GetNeighbor(gobgp_pb2.GetNeighborRequest()).peers
+ for peer in peers:
+ print("BGP neighbor is %s, remote AS %d" % (peer.conf.neighbor_address, peer.conf.peer_as))
+ print(" BGP version 4, remote router ID %s" % (peer.conf.id))
+ print(" BGP state = %s, up for %s" % (peer.info.bgp_state, peer.timers.state.uptime))
+ print(" BGP OutQ = %d, Flops = %d" % (peer.info.out_q, peer.info.flops))
+ print(" Hold time is %d, keepalive interval is %d seconds" % (peer.timers.state.negotiated_hold_time, peer.timers.state.keepalive_interval))
+ print(" Configured hold time is %d, keepalive interval is %d seconds" % (peer.timers.config.hold_time, peer.timers.config.keepalive_interval))
+ except ExpirationError, e:
+ print str(e)
+ sys.exit(-1)
if __name__ == '__main__':
gobgp = sys.argv[1]