-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapis.py
60 lines (45 loc) · 1.54 KB
/
apis.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
54
55
56
57
58
59
60
from Network.Devices import Switches
from netmiko import ConnectHandler
from fastapi import FastAPI
import ntc_templates
app = FastAPI()
'''
Show VLANS configured on Switches
'''
@app.get('/Devices/Switches/{Switch_name}/GET/VLANs')
def vlans(Switch_name: str):
switch = Switches[Switch_name]
conn = ConnectHandler(**switch)
conn.enable()
command = conn.send_command('show vlan brief',use_textfsm=True)
return {f'{Switch_name}': command}
'''
Verifying Spanning tree status on Switches
'''
@app.get('/Devices/Switches/{Switch_name}/GET/Spanningtree/{VLAN_ID}/status')
def vlans(Switch_name: str, VLAN_ID: str):
switch = Switches[Switch_name]
conn = ConnectHandler(**switch)
conn.enable()
command = conn.send_command('show spanning-tree '+VLAN_ID,use_textfsm=True)
return {f'{Switch_name}': command}
'''
Verifying Etherchannels on Switches
'''
@app.get('/Devices/Switches/{Switch_name}/GET/Etherchannel')
def vlans(Switch_name: str):
switch = Switches[Switch_name]
conn = ConnectHandler(**switch)
conn.enable()
command = conn.send_command('show etherchannel summary',use_textfsm=True)
return {f'{Switch_name}': command}
'''
Verifying MAC-Address tables on Switches
'''
@app.get('/Devices/Switches/{Switch_name}/GET/addresstable/{VLAN_ID}')
def vlans(Switch_name: str, VLAN_ID:str):
switch = Switches[Switch_name]
conn = ConnectHandler(**switch)
conn.enable()
command = conn.send_command('show mac address-table '+VLAN_ID,use_textfsm=True)
return {f'{Switch_name}': command}