Skip to content

Commit 9f20ee7

Browse files
author
kkumara3
committed
added config bgp examples, and example yang
1 parent 7ebdffe commit 9f20ee7

File tree

3 files changed

+199
-0
lines changed

3 files changed

+199
-0
lines changed

examples/grpc_cfg.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
'''
2+
Note:
3+
This is an example to show replace and merge configs work with a get command.
4+
The example is using XRdocs vagrant topology for all the configurations
5+
'''
6+
7+
import sys
8+
sys.path.insert(0, '../')
9+
from lib.cisco_grpc_client import CiscoGRPCClient
10+
import json
11+
from time import sleep
12+
13+
class Example:
14+
def __init__(self):
15+
self.client = CiscoGRPCClient('11.1.1.10', 57777, 10, 'vagrant', 'vagrant')
16+
def get(self):
17+
path = '{"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": [null]}'
18+
result = self.client.getconfig(path)
19+
print result
20+
21+
def replace(self):
22+
path = open('snips/bgp_start.json').read()
23+
result = self.client.replaceconfig(path)
24+
print result # If this is sucessful, then there should be no errors.
25+
26+
def merge(self):
27+
path = open('snips/bgp_merge.json').read()
28+
result = self.client.mergeconfig(path)
29+
print result # If this is sucessful, then there should be no errors.
30+
31+
def delete(self):
32+
path = open('snips/bgp_start.json').read()
33+
result = self.client.deleteconfig(path)
34+
print result # If this is sucessful, then there should be no errors.
35+
36+
def main():
37+
'''
38+
This example does not use TLS, if you want to use TLS please refer to the example with tls
39+
Here is a workflow of the example that uses all the different types.
40+
'''
41+
example = Example()
42+
#We are going to start with a replace config, to add a base BGP config
43+
example.replace()
44+
#Lets see what the bgp is on the router to ensure the the config got placed in there. \n'
45+
#This config should be the same as the starting snip\n'
46+
example.get()
47+
#Let us use merge to add another neighbor.
48+
example.merge()
49+
#The resulting config should be the first config plus the second
50+
example.get()
51+
#If we were to replace the config wtih the starting config we would see only the starting config
52+
example.replace()
53+
example.get()
54+
#If we were to delete the config using the starting json, we would see that bgp is no longer active.
55+
example.delete()
56+
example.get()
57+
58+
if __name__ == '__main__':
59+
main()

examples/snips/bgp_merge.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {
3+
"instance": [
4+
{
5+
"instance-name": "default",
6+
"instance-as": [
7+
{
8+
"as": 0,
9+
"four-byte-as": [
10+
{
11+
"as": 65400,
12+
"bgp-running": [
13+
null
14+
],
15+
"default-vrf": {
16+
"global": {
17+
"router-id": "11.1.1.10",
18+
"global-afs": {
19+
"global-af": [
20+
{
21+
"af-name": "ipv4-unicast",
22+
"enable": [
23+
null
24+
],
25+
"sourced-networks": {
26+
"sourced-network": [
27+
{
28+
"network-addr": "11.1.1.0",
29+
"network-prefix": 24
30+
}
31+
]
32+
}
33+
}
34+
]
35+
}
36+
},
37+
"bgp-entity": {
38+
"neighbors": {
39+
"neighbor": [
40+
{
41+
"neighbor-address": "11.1.1.60",
42+
"remote-as": {
43+
"as-xx": 0,
44+
"as-yy": 65460
45+
},
46+
"neighbor-afs": {
47+
"neighbor-af": [
48+
{
49+
"af-name": "ipv4-unicast",
50+
"activate": [
51+
null
52+
],
53+
"next-hop-self": true
54+
}
55+
]
56+
}
57+
}
58+
]
59+
}
60+
}
61+
}
62+
}
63+
]
64+
}
65+
]
66+
}
67+
]
68+
}
69+
}
70+

examples/snips/bgp_start.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"Cisco-IOS-XR-ipv4-bgp-cfg:bgp": {
3+
"instance": [
4+
{
5+
"instance-name": "default",
6+
"instance-as": [
7+
{
8+
"as": 0,
9+
"four-byte-as": [
10+
{
11+
"as": 65400,
12+
"bgp-running": [
13+
null
14+
],
15+
"default-vrf": {
16+
"global": {
17+
"router-id": "11.1.1.10",
18+
"global-afs": {
19+
"global-af": [
20+
{
21+
"af-name": "ipv4-unicast",
22+
"enable": [
23+
null
24+
],
25+
"sourced-networks": {
26+
"sourced-network": [
27+
{
28+
"network-addr": "11.1.1.0",
29+
"network-prefix": 24
30+
}
31+
]
32+
}
33+
}
34+
]
35+
}
36+
},
37+
"bgp-entity": {
38+
"neighbors": {
39+
"neighbor": [
40+
{
41+
"neighbor-address": "11.1.1.20",
42+
"remote-as": {
43+
"as-xx": 0,
44+
"as-yy": 65450
45+
},
46+
"neighbor-afs": {
47+
"neighbor-af": [
48+
{
49+
"af-name": "ipv4-unicast",
50+
"activate": [
51+
null
52+
],
53+
"next-hop-self": true
54+
}
55+
]
56+
}
57+
}
58+
]
59+
}
60+
}
61+
}
62+
}
63+
]
64+
}
65+
]
66+
}
67+
]
68+
}
69+
}
70+

0 commit comments

Comments
 (0)