Skip to content

Commit 74857bb

Browse files
brmcdougKarthik Kumaravel
authored andcommitted
merge-config fixed (#7)
* initial commit * Added python based command line interface (cli.py), json directory containing numerous json files for grpc calls, and yang directory containing a dump of all yang data models found in IOS XR 6.2.1 * added a note to cli.py explaining v1.0 functionality * refactored directory structure * fixed merge-config RPC
1 parent 828ceea commit 74857bb

34 files changed

+838
-3
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
*.pem
2-
.DS_STORE
3-
*.pyc

examples/cli.py

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
"""
2+
GRPC Client with command line options
3+
4+
Usage:
5+
client.py -i <router_IP> -p <port> -u <user> -pw <password> -r <rpc> [--file <json_file>]
6+
client.py (-h | --help)
7+
8+
Options:
9+
-h --help Show this help
10+
--version Show version
11+
-i IP address of the router which the client will connect to
12+
-p Router gRPC server will be running on some TCP port, generally 57400
13+
-u Username to connect with
14+
-pw User's password
15+
-r RPC call to make. Valid RPCS: get-oper, get-config, merge-config, replace-config
16+
--file Optional json file for filtered namespace requests. Client is expecting these files to be stored in json/ folder
17+
18+
Example:
19+
python cli.py -i 192.168.122.214 -p 57400 -u cisco -pw cisco -r get-oper --file json/get-oper-mpls-te.json
20+
21+
Note: Version 1.0 supports get-oper, get-config, and merge-config RPCs, replace-config hopefully coming soon
22+
"""
23+
24+
import json
25+
from grpc.framework.interfaces.face.face import AbortionError
26+
import sys
27+
sys.path.insert(0, '../')
28+
from lib.cisco_grpc_client import CiscoGRPCClient
29+
30+
from docopt import docopt
31+
32+
def main():
33+
34+
__version__ = 'GRPC_Client 1.0'
35+
arguments = docopt(__doc__, version=__version__)
36+
37+
IP = arguments['<router_IP>']
38+
TCP_PORT = int(arguments['<port>'])
39+
user = arguments['<user>']
40+
password = arguments['<password>']
41+
RPC = arguments['<rpc>']
42+
43+
client = CiscoGRPCClient(IP, TCP_PORT, 10, user, password)
44+
45+
if RPC == "get-oper":
46+
47+
if arguments['--file']:
48+
file = arguments['--file']
49+
path = open(file).read()
50+
# path = open('json/' + file).read()
51+
else:
52+
path = 'Error'
53+
print(
54+
'get-oper argument must include --file option and json file to filter yang operational namespace'
55+
)
56+
try:
57+
err, result = client.getoper(path)
58+
if err:
59+
print err
60+
print result
61+
except AbortionError:
62+
print(
63+
'Unable to connect to local box, check your gRPC destination.'
64+
)
65+
66+
if RPC == "get-config":
67+
68+
if arguments['--file']:
69+
file = arguments['--file']
70+
path = open(file).read()
71+
# path = open('json/' + file).read()
72+
else:
73+
path = ""
74+
75+
try:
76+
err, result = client.getconfig(path)
77+
if err:
78+
print err
79+
print result
80+
except AbortionError:
81+
print(
82+
'Unable to connect to local box, check your gRPC destination.'
83+
)
84+
85+
if RPC == "merge-config":
86+
87+
if arguments['--file']:
88+
file = arguments['--file']
89+
path = open(file).read()
90+
else:
91+
path = 'Error'
92+
print(
93+
'get-oper argument must include --file option and json file to filter yang operational namespace'
94+
)
95+
try:
96+
err = client.mergeconfig(path)
97+
if err:
98+
print err
99+
#print result
100+
except AbortionError:
101+
print(
102+
'Unable to connect to local box, check your gRPC destination.'
103+
)
104+
105+
if RPC == "replace-config":
106+
107+
if arguments['--file']:
108+
file = arguments['--file']
109+
path = open(file).read()
110+
else:
111+
path = 'Error'
112+
print(
113+
'get-oper argument must include --file option and json file to filter yang operational namespace'
114+
)
115+
try:
116+
err = client.replaceconfig(path)
117+
if err:
118+
print err
119+
except AbortionError:
120+
print(
121+
'Unable to connect to local box, check your gRPC destination.'
122+
)
123+
124+
if __name__ == '__main__':
125+
main()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {
3+
"instance": [
4+
{
5+
"instance-name": "default",
6+
"instance-as": [
7+
]
8+
}
9+
]
10+
}
11+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {
3+
"instance": [
4+
{
5+
"instance-name": "default",
6+
"instance-as": [
7+
{
8+
"four-byte-as": [
9+
{
10+
"default-vrf": {
11+
"bgp-entity": {
12+
"neighbors": {
13+
"neighbor": [
14+
{
15+
"neighbor-address": "2.2.2.42",
16+
"remote-as": {
17+
}
18+
}
19+
]
20+
}
21+
}
22+
}
23+
}
24+
]
25+
}
26+
]
27+
}
28+
]
29+
}
30+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {
3+
"instance": [
4+
{
5+
"instance-name": "default",
6+
"instance-as": [
7+
{
8+
"four-byte-as": [
9+
{
10+
"default-vrf": {
11+
"bgp-entity": {
12+
"neighbors": {
13+
"neighbor": [
14+
{
15+
"neighbor-address": "2.2.2.42",
16+
"neighbor-afs": {
17+
"neighbor-af": [
18+
]
19+
}
20+
}
21+
]
22+
}
23+
}
24+
}
25+
}
26+
]
27+
}
28+
]
29+
}
30+
]
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {
3+
"instance": [
4+
{
5+
"instance-name": "default",
6+
"instance-as": [
7+
{
8+
"four-byte-as": [
9+
{
10+
"default-vrf": {
11+
"bgp-entity": {
12+
"neighbors": {
13+
"neighbor": [
14+
{
15+
"neighbor-afs": {
16+
"neighbor-af": [
17+
]
18+
}
19+
}
20+
]
21+
}
22+
}
23+
}
24+
}
25+
]
26+
}
27+
]
28+
}
29+
]
30+
}
31+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": [null]
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Cisco-IOS-XR-policy-repository-cfg:routing-policy": [null]
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Cisco-IOS-XR-shellutil-cfg:host-names": [null]
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Cisco-IOS-XR-ifmgr-cfg:interface-configurations": [null]
3+
}

0 commit comments

Comments
 (0)