Skip to content

Commit 07fc68c

Browse files
author
Karthik Kumaravel
authored
Packaging (#9)
* Initial commit for packaging * Fix examples to import pip package * Update Readme * Fix README.md issues Fix some grammar and structural issues.
1 parent d70bf9f commit 07fc68c

15 files changed

+98
-81
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
*.pyc
22
__pycache__
3+
dist/
4+
*.egg
5+
*.egg-info

README.md

Lines changed: 56 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,95 @@
1-
Grpc for Cisco IOS-XR in python
2-
--
1+
## gRPC for Cisco IOS-XR in Python
2+
33
Author: Karthik Kumaravel
44

5-
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.
66

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.
810

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).
1012

13+
If you find any problems or need help, create an issue!
1114

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```
1517

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/).
1819

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.
2420

21+
## gRPC Calls
22+
23+
### Enable gRPC
24+
25+
SSH in to the router and turn on gRPC, below is an example configuration:
2526
```
2627
interface GigabitEthernet 0/0/0/0
2728
ipv4 address 192.168.1.2 255.255.255.0
2829
no shut
2930
3031
grpc
31-
tls
3232
port 57777
3333
!
3434
!
3535
```
3636

37-
- Copy the autogenerated .pem file to the 'keys' folder in the client directory.
37+
Note: Default port is 57400, and IPv4 only.
3838

39+
#### Using TLS
40+
41+
1. Enable TLS in configuration, example:
3942
```
40-
scp [email protected]:/misc/config/grpc/ems.pem ./
43+
grpc
44+
tls
45+
port 57777
46+
!
47+
!
4148
```
4249

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.
4451

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 [email protected]:/misc/config/grpc/ems.pem ./
54+
```
55+
56+
### Usage
57+
```from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient```
4758

4859
```
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)
5071
```
51-
For a more in-depth look, check out the wiki https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python/wiki
5272

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+
5577
To create a client of your own there are a few steps to follow.
5678

5779
- Download the proto file for IOS-XR's grpc: https://github.com/CiscoDevNet/grpc-getting-started
5880
- 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
5981
- 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
6185

62-
Other Useful Links
63-
--
6486
If you would like to test this all out with IOS-XRv, use the following link to request access to the vagrant box.
6587

6688
https://xrdocs.github.io/
6789

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+

examples/cli.py

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
Note: Version 1.0 supports get-oper, get-config, and merge-config RPCs, replace-config hopefully coming soon
2222
"""
2323

24-
import json
2524
from grpc.framework.interfaces.face.face import AbortionError
26-
import sys
27-
sys.path.insert(0, '../')
28-
from lib.cisco_grpc_client import CiscoGRPCClient
25+
from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
2926
from docopt import docopt
3027

28+
3129
def main():
3230

3331
__version__ = 'GRPC_Client 1.0'
@@ -50,17 +48,15 @@ def main():
5048
else:
5149
path = 'Error'
5250
print(
53-
'get-oper argument must include --file option and json file to filter yang operational namespace'
54-
)
51+
'get-oper argument must include --file option and json file to filter yang operational namespace')
5552
try:
5653
err, result = client.getoper(path)
5754
if err:
5855
print(err)
5956
print(result)
6057
except AbortionError:
6158
print(
62-
'Unable to connect to local box, check your gRPC destination.'
63-
)
59+
'Unable to connect to local box, check your gRPC destination.')
6460

6561
if RPC == "get-config":
6662

@@ -78,8 +74,7 @@ def main():
7874
print(result)
7975
except AbortionError:
8076
print(
81-
'Unable to connect to local box, check your gRPC destination.'
82-
)
77+
'Unable to connect to local box, check your gRPC destination.')
8378

8479
if RPC == "merge-config":
8580

@@ -89,17 +84,15 @@ def main():
8984
else:
9085
path = 'Error'
9186
print(
92-
'get-oper argument must include --file option and json file to filter yang operational namespace'
93-
)
87+
'get-oper argument must include --file option and json file to filter yang operational namespace')
9488
try:
9589
err = client.mergeconfig(path)
9690
if err:
9791
print(err)
98-
#print result
92+
# print result
9993
except AbortionError:
10094
print(
101-
'Unable to connect to local box, check your gRPC destination.'
102-
)
95+
'Unable to connect to local box, check your gRPC destination.')
10396

10497
if RPC == "replace-config":
10598

@@ -109,16 +102,15 @@ def main():
109102
else:
110103
path = 'Error'
111104
print(
112-
'get-oper argument must include --file option and json file to filter yang operational namespace'
113-
)
105+
'get-oper argument must include --file option and json file to filter yang operational namespace')
114106
try:
115107
err = client.replaceconfig(path)
116108
if err:
117109
print(err)
118110
except AbortionError:
119111
print(
120-
'Unable to connect to local box, check your gRPC destination.'
121-
)
112+
'Unable to connect to local box, check your gRPC destination.')
113+
122114

123115
if __name__ == '__main__':
124116
main()

examples/grpc_cfg.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
'''
66
from grpc.framework.interfaces.face.face import AbortionError
77
import json
8-
from time import sleep
9-
import sys
10-
sys.path.insert(0, '../')
11-
from lib.cisco_grpc_client import CiscoGRPCClient
8+
from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
129

1310

1411
class Example(object):

examples/grpc_cfgclireplace.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44
import json
55
from grpc.framework.interfaces.face.face import AbortionError
6-
import sys
7-
sys.path.insert(0, '../')
8-
from lib.cisco_grpc_client import CiscoGRPCClient
6+
from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
97

108
def main():
119
'''

examples/grpc_example.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
"""
44
import json
55
from grpc.framework.interfaces.face.face import AbortionError
6-
import sys
7-
sys.path.insert(0, '../')
8-
from lib.cisco_grpc_client import CiscoGRPCClient
6+
from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
97

108
def main():
119
'''

examples/route_policy.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
from collections import OrderedDict
1111
except ImportError:
1212
from ordereddict import OrderedDict
13-
import sys
14-
sys.path.insert(0, '../')
15-
from lib.cisco_grpc_client import CiscoGRPCClient
13+
from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
1614

1715

1816
class RoutePolicy(object):
1917
"""Class to manipulate route policy and bgp neighbors using openconfig
2018
"""
21-
def __init__(self, host, port, username, password):
19+
def __init__(, host, port, username, password):
2220
"""This class creates a grpc client for the functions to use.
2321
:param host: The ip address for the device.
2422
:param port: The port for the device.

examples/telemetry_collector.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
and output to display. Converts from protobuf to JSON for display.
44
"""
55

6-
import sys
7-
sys.path.insert(0, '../')
8-
from lib.cisco_grpc_client import CiscoGRPCClient
6+
from iosxr_grpc.cisco_grpc_client import CiscoGRPCClient
97
import json
108

9+
1110
def print_connectivity(connectivity):
12-
print connectivity
11+
print connectivity
12+
1313

1414
# Change client details to match your environment.
1515
client = CiscoGRPCClient('localhost', 57777, 10, 'vagrant', 'vagrant')
@@ -21,8 +21,7 @@ def print_connectivity(connectivity):
2121
for segment in client.getsubscription(subscription_id, unmarshal=True):
2222
# unmarshal is an optional argument, default is unmarshal = True
2323
# If unmarshal is false, out is in gpb k/v
24-
recv_count += 1
25-
print(json.dumps(segment, indent=4, separators=(',', ': ')))
26-
print('End Telemetry Segment')
27-
print(str(recv_count) + ' Segments Received')
28-
24+
recv_count += 1
25+
print(json.dumps(segment, indent=4, separators=(',', ': ')))
26+
print('End Telemetry Segment')
27+
print(str(recv_count) + ' Segments Received')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/__init__.py

Whitespace-only changes.

setup.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from setuptools import setup
2+
3+
4+
setup(name='iosxr_grpc',
5+
version='1.1',
6+
description='gRPC library for IOS-XR > 6.1.1',
7+
url='https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python',
8+
author='Karthik Kumaravel',
9+
authoer_email='[email protected]',
10+
licencse='Apache 2.0',
11+
packages=['iosxr_grpc'],
12+
install_requires=[
13+
'grpcio==1.1.0',
14+
],
15+
zip_safe=False)

0 commit comments

Comments
 (0)