-
Notifications
You must be signed in to change notification settings - Fork 0
/
netmiko_service_policy.py
52 lines (38 loc) · 2.87 KB
/
netmiko_service_policy.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
def policy():
ExcelExport = [["Description", "Interface", "Input_Policy","Output_Policy"]]
ciscoasr9k = { "host" : "192.168.0.10","username" :"TEST","password" :"TEST","port" : 22,"device_type" : "cisco_xr",}
conn = ConnectHandler(**ciscoasr9k)
conn.enable()
data_to_parse = conn.send_command_timing('show run interface')
ttp_template = """
interface Bundle-Ether{{ interface_Bundle | split(".") }}
description {{ Description }}
service-policy input {{ qos_input }}
service-policy output {{ qos_output}}
"""
# create parser object and parse data using template:
parser = ttp(data=data_to_parse, template=ttp_template)
parser.parse()
# print result in JSON format
results = parser.result(format='json')[0]
result = json.loads(results)
#print(result[0])
#for i in result[0]:
#print(int(i["interface_Bundle"][0]))
for i in result[0]:
if len(i["interface_Bundle"]) > 1 and int(i["interface_Bundle"][1]) > 200 and "Description" in i and i["interface_Bundle"][1] != "311" and i["interface_Bundle"][1] != "202" and i["interface_Bundle"][1] != "203" and i["interface_Bundle"][1] != "204" and i["interface_Bundle"][1] != "205" and i["interface_Bundle"][1] != "220" and i["interface_Bundle"][1] != "227" and i["interface_Bundle"][1] != "262" and i["interface_Bundle"][1] != "276" and i["interface_Bundle"][1] != "280" and i["interface_Bundle"][1] != "300" and i["interface_Bundle"][1] != "308" and i["interface_Bundle"][1] != "309" and i["interface_Bundle"][1] != "310" and i["interface_Bundle"][1] != "322" and i["interface_Bundle"][1] != "324" and i["interface_Bundle"][1] != "340" and i["interface_Bundle"][1] != "341" and i["interface_Bundle"][1] != "347" and i["interface_Bundle"][1] != "350" and i["interface_Bundle"][1] != "356" and i["interface_Bundle"][1] != "405" and i["interface_Bundle"][1] != "1225" and i["interface_Bundle"][1] != "1474" and i["interface_Bundle"][1] != "1632" and i["interface_Bundle"][1] != "320" and i["interface_Bundle"][1] != "747" :
if "qos_input" not in i:
interface_Bundle2 = "interface_Bundle"+str(i["interface_Bundle"][0]) +"."+ str(i["interface_Bundle"][1])
ExcelExport.append([i["Description"],interface_Bundle2,"input policy none", "output policy none"])
XLSExport(ExcelExport, "Policy", "policy1.xlsx")
SendMailwAttachment_(ExcelExport, "policy1.xlsx")
# schedule.every(10).minutes.do(policy)
# schedule.every().hour.do(policy)
# schedule.every().day.at("07:59").do(policy)
# schedule.every().monday.do(policy)
# schedule.every().monday.at("08:00").do(policy)
schedule.every().minute.at(":05").do(policy)
while True:
schedule.run_pending()
time.sleep(1)
policy()