|
1 |
| -Grpc for Cisco IOS-XR in python |
2 |
| --- |
| 1 | +## gRPC for Cisco IOS-XR in Python |
| 2 | + |
3 | 3 | Author: Karthik Kumaravel
|
4 | 4 |
|
5 |
| -Contact: kkumara3@cisco.com |
| 5 | +This package contains a library with the methods that are available to use over gRPC with IOS-XR boxes after 6.0.0. The API has several methods which allows a user to send simple RPC commands such as ```get``` and ```push``` using YANG and JSON. |
6 | 6 |
|
7 |
| -This is a small repo showing how to use GRPC in python for the IOS-XR end node.The repo is consisted of three main componenets, the compiled pb2 file from the IDL, a python client accessing the pb2 file, and an example python file. The example is a small python file showing how to set up the connection and use one of the rpc calls. Please look at the unit-testing and client page for more rpc calls. At the bottom of the repo, there is a walkthrough of how to create your own client. |
| 7 | +The repo consists of two main components: |
| 8 | +1. The compiled pb2 file from the proto definition. |
| 9 | +2. A Python module accessing the pb2 file with the library bindings. |
8 | 10 |
|
9 |
| -If you find any problems with this repo, please file a bug so I can fix it. If you need help, feel free to contact me. |
| 11 | +The repo also includes examples on how to use the library to interact with an IOS-XR device. If you want to create your own client, there is a walkthrough [at the bottom of this page](#creating-your-own-client). |
10 | 12 |
|
| 13 | +If you find any problems or need help, create an issue! |
11 | 14 |
|
12 |
| -GRPC Calls |
13 |
| --- |
14 |
| -The file is called example_grpc.py. This file has an excamples of the different rpc calls. This configuration shows how to get things started with self signed certs. |
| 15 | +## Installation |
| 16 | +Either download this repository or install with ```pip install iosxr_grpc``` |
15 | 17 |
|
16 |
| -- Download the repository |
17 |
| -- Install grpc |
| 18 | +It is always recommended to work in a virtual environment with something like [virtualenv](https://virtualenv.pypa.io/en/stable/) or [pipenv](http://docs.pipenv.org/en/latest/). |
18 | 19 |
|
19 |
| -``` |
20 |
| -pip install grpcio |
21 |
| -``` |
22 |
| -(sudo may be required) |
23 |
| -- ssh into the router and turn on grpc and tls on the router, below is an example configuration. |
24 | 20 |
|
| 21 | +## gRPC Calls |
| 22 | + |
| 23 | +### Enable gRPC |
| 24 | + |
| 25 | +SSH in to the router and turn on gRPC, below is an example configuration: |
25 | 26 | ```
|
26 | 27 | interface GigabitEthernet 0/0/0/0
|
27 | 28 | ipv4 address 192.168.1.2 255.255.255.0
|
28 | 29 | no shut
|
29 | 30 |
|
30 | 31 | grpc
|
31 |
| - tls |
32 | 32 | port 57777
|
33 | 33 | !
|
34 | 34 | !
|
35 | 35 | ```
|
36 | 36 |
|
37 |
| -- Copy the autogenerated .pem file to the 'keys' folder in the client directory. |
| 37 | +Note: Default port is 57400, and IPv4 only. |
38 | 38 |
|
| 39 | +#### Using TLS |
| 40 | + |
| 41 | +1. Enable TLS in configuration, example: |
39 | 42 | ```
|
40 |
| -scp cisco@192.168.1.2:/misc/config/grpc/ems.pem ./ |
| 43 | +grpc |
| 44 | + tls |
| 45 | + port 57777 |
| 46 | + ! |
| 47 | +! |
41 | 48 | ```
|
42 | 49 |
|
43 |
| -(note if you don't want to use TLS, don't pass the cred and options) |
| 50 | +2. Copy the autogenerated .pem file to the 'keys' folder in the client directory. |
44 | 51 |
|
45 |
| -- If you are using your own box, change the parameters in the example.py file to have the proper authentication credentials. |
46 |
| -- Run the program |
| 52 | +``` |
| 53 | +scp cisco@192.168.1.2:/misc/config/grpc/ems.pem ./ |
| 54 | +``` |
| 55 | + |
| 56 | +### Usage |
| 57 | +```from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient``` |
47 | 58 |
|
48 | 59 | ```
|
49 |
| -python grpc_example.py |
| 60 | +from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient |
| 61 | +client = CiscoGRPCClient( |
| 62 | + <ip address>, |
| 63 | + <port>, |
| 64 | + <timeout>, |
| 65 | + <username>, |
| 66 | + <password>, |
| 67 | + <optional: tls key>, |
| 68 | + <optional: tls server name ('ems.cisco.com')>) |
| 69 | +path = <yang path> # '{"openconfig-interfaces:interfaces": [null]}') |
| 70 | +err, result = client.<operation>(path) # client.getconfig(path) |
50 | 71 | ```
|
51 |
| -For a more in-depth look, check out the wiki https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python/wiki |
52 | 72 |
|
53 |
| -Getting here from the beginning |
54 |
| --- |
| 73 | +For a more in-depth look, [check out the wiki](https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python/wiki)! |
| 74 | + |
| 75 | +## Creating your own Client |
| 76 | + |
55 | 77 | To create a client of your own there are a few steps to follow.
|
56 | 78 |
|
57 | 79 | - Download the proto file for IOS-XR's grpc: https://github.com/CiscoDevNet/grpc-getting-started
|
58 | 80 | - Follow the instructions to generate the client/server code in python using the grpc-getting-started's proto file: http://www.grpc.io/docs/tutorials/basic/python.html#generating-client-and-server-code
|
59 | 81 | - From here create a client, an example can be found here: http://www.grpc.io/docs/tutorials/basic/python.html#creating-the-client
|
60 |
| - - At this point you should have a client similar to the one in this repo |
| 82 | +- At this point you should have a client similar to the one in this repo |
| 83 | + |
| 84 | +## Useful Links |
61 | 85 |
|
62 |
| -Other Useful Links |
63 |
| --- |
64 | 86 | If you would like to test this all out with IOS-XRv, use the following link to request access to the vagrant box.
|
65 | 87 |
|
66 | 88 | https://xrdocs.github.io/
|
67 | 89 |
|
68 |
| -Projects that use the python client |
69 |
| --- |
70 |
| -[Solenoid](https://github.com/ios-xr/Solenoid) |
71 |
| - |
72 |
| -To be done |
73 |
| --- |
74 |
| -Here is a list of current work to be done |
75 |
| -- Add example vagrant setup |
76 |
| -- Examples of all the different tests |
77 |
| -- More unit testing |
78 |
| -- Documentation around MDT telemetry |
| 90 | +## Projects that use the python client |
| 91 | + |
| 92 | +[Solenoid](https://github.com/ios-xr/Solenoid) - App that injects routes directly into Cisco's IOS-XR RIB table. |
| 93 | + |
| 94 | +[Pipedown](https://github.com/cisco-ie/Pipedown) - CDN router monitoring tool for data center connectivity. |
| 95 | + |
0 commit comments