-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlldp-increment.py
53 lines (46 loc) · 1.3 KB
/
lldp-increment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/python3
import subprocess
import json
import ipaddress
lldpOutput = subprocess.getoutput("Cli -p 15 -c 'show lldp neighbors | json'")
jsonOutput = json.loads(lldpOutput)
for neighbor in jsonOutput["lldpNeighbors"]:
if neighbor["port"] == "Management1":
portOutput = neighbor["neighborPort"]
portNumber = int(list(filter(str.isdigit, portOutput))[0])
number = portNumber + 100
subnet = "" # SPECIFY SUBNET TO BE GIVEN TO SWITCHES IN THE FOLLOWING FORMAT xxx.xxx.xxx. EX: 10.0.0.
netmask = "" # SPECIFY NETMASK TO BE GIVEN TO THE SWITCHES IN THE FOLLOWING FORMAT xx EX: 24
ipAddress = f"{subnet}{number}/{netmask}"
password = "" # SPECIFY PASSWORD TO BE USED FOR THE ADMIN ACCOUNT ON SWITCHES
network = ipaddress.ip_network(ipAddress, strict=False)
gateway = str(network[1])
config = f"""
vrf instance MGMT
!
username admin secret {password}
!
interface Management1
vrf MGMT
ip address {ipAddress}
!
ip route vrf MGMT 0.0.0.0/0 {gateway}
!
management api http-commands
protocol http
no shutdown
!
vrf MGMT
no shutdown
protocol http
!
management ssh
no shutdown
!
vrf MGMT
no shutdown
!
!
"""
with open("/mnt/flash/startup-config", "w") as file:
file.write(config)