forked from agonzo777/NetAppAciFlask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmvpn.py
94 lines (74 loc) · 2.3 KB
/
dmvpn.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import sys
import time
import paramiko
import subprocess
import os.path
import re
import threading
username = 'user'
password = 'pass'
ch3 = 'ip'
ps2 = 'ip'
ps2outl = ['route-map ToDMVPN permit 5','set community 65111:50']
ch3outl = ['route-map ToDMVPN permit 5','set community 65112:50']
inservice = ['no route-map ToDMVPN permit 5']
def ps2out ():
session = paramiko.SSHClient()
session.set_missing_host_key_policy(paramiko.AutoAddPolicy())
session.connect(ps2, username = username, password = password)
connection = session.invoke_shell()
connection.send("terminal length 0\n")
time.sleep(1)
connection.send("config t\n")
time.sleep(1)
connection.send("\n")
for line in ps2outl():
connection.send(line +'\n')
time.sleep(3)
connection.send("wr mem\n")
time.sleep(3)
session.close()
def ch3out():
session = paramiko.SSHClient()
session.set_missing_host_key_policy(paramiko.AutoAddPolicy())
session.connect(ps2, username = username, password = password)
connection = session.invoke_shell()
connection.send("terminal length 0\n")
time.sleep(1)
connection.send("\n")
for line in ch3outl():
connection.send(line +'\n')
time.sleep(3)
session.close()
def ps2in ():
session = paramiko.SSHClient()
session.set_missing_host_key_policy(paramiko.AutoAddPolicy())
session.connect(ps2, username = username, password = password)
connection = session.invoke_shell()
connection.send("terminal length 0\n")
time.sleep(1)
connection.send("\n")
connection.send("no", ch3outl + '\n')
time.sleep(3)
session.close()
def ch3in():
print('CH3 has been executed')
session = paramiko.SSHClient()
session.set_missing_host_key_policy(paramiko.AutoAddPolicy())
session.connect(ps2, username = username, password = password)
connection = session.invoke_shell()
connection.send("terminal length 0\n")
time.sleep(1)
connection.send("\n")
connection.send('no',ch3outl[0],'\n')
time.sleep(3)
session.close()
def dmvpn(dop, loc, sp):
if (loc == 'Piscataway') and (sp == 'OutService'):
ps2out()
elif (loc == 'Piscataway') and (sp == 'InService'):
ps2in()
elif (loc == 'Chicago') and (sp == 'OutService'):
ch3out()
elif (loc == 'Chicago') and (sp == 'InService'):
ch3in()