Skip to content

Commit 6b7cbb3

Browse files
committed
basic python script
1 parent 2c94e38 commit 6b7cbb3

1 file changed

Lines changed: 96 additions & 0 deletions

File tree

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
sys.path.append("/pkg/bin/")
5+
from ztp_helper import ZtpHelpers
6+
7+
ParameterMap = {
8+
"rtr1" : {
9+
"local_asn" : 65000,
10+
"remote_asn" : 65000,
11+
"loopback0_ip" : "1.1.1.1/32",
12+
"bgp_neighbor_ip" : "2.2.2.2"
13+
},
14+
15+
"rtr2" : {
16+
"local_asn" : 65000,
17+
"remote_asn" : 65000,
18+
"loopback0_ip" : "2.2.2.2/32",
19+
"bgp_neighbor_ip" : "1.1.1.1"
20+
}
21+
}
22+
23+
24+
class ZtpChildClass(ZtpHelpers):
25+
26+
def get_hostname(self):
27+
28+
show_command= "show running-config hostname"
29+
30+
response = self.xrcmd({"exec_cmd" : show_command})
31+
32+
if response["status"] == "success":
33+
try:
34+
output = response["output"]
35+
hostname_config = output[0]
36+
hostname = hostname_config.split()[1]
37+
return hostname
38+
except Exception as e:
39+
print("Failed to extract hostname")
40+
print("Error: " + str(e))
41+
sys.exit(1)
42+
else:
43+
print("Failed to fetch hostname configuration")
44+
sys.exit(1)
45+
46+
47+
def configure_ospf(self) {
48+
49+
ospf_config = """!
50+
router ospf ztp-bash
51+
area 0
52+
interface Loopback0
53+
!
54+
interface GigabitEthernet0/0/0/0
55+
!
56+
interface GigabitEthernet0/0/0/1
57+
!
58+
!
59+
!
60+
end
61+
"""
62+
63+
}
64+
65+
66+
def configure_bgp(asn=None, hostname=None) {
67+
68+
bgp_config = """ !
69+
router bgp {local_asn}
70+
address-family ipv4 unicast
71+
!
72+
neighbor {neighbor_ip}
73+
remote-as {remote_asn}
74+
update-source Loopback0
75+
address-family ipv4 unicast
76+
!
77+
!
78+
end
79+
""".format(local_asn = ParameterMap[hostname][local_asn],
80+
neighbor_ip = ParameterMap[hostname][bgp_neighbor_ip],
81+
remote_asn = ParameterMap[hostname][remote_asn])
82+
83+
}
84+
85+
86+
def configure_loopback() {
87+
88+
hostname = self.get_hostname()
89+
loopback0_config = """!
90+
interface Loopback0
91+
ipv4 address ${HostMap[${hostname}]}
92+
!
93+
end
94+
"""
95+
96+
}

0 commit comments

Comments
 (0)