-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathssh_client.py
executable file
·34 lines (29 loc) · 1.11 KB
/
ssh_client.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
#!/usr/bin/python
import sshutil
from sshutil.cmd import SSHCommand
# Utility to close a ssh session
def close_ssh_session(session):
# Close the session
remoteCmd.close()
# Flush the cache
remoteCmd.cache.flush()
# Let's create a new route
cmd = "ip -6 route add 1111:4::2/128 encap seg6 mode inline segs 1111:3::2 dev eth0"
remoteCmd = SSHCommand(cmd, "127.0.0.1", 220, "srv6", "srv6")
remoteCmd.run()
# Let's create a bunch of routes
cmd = "ip -6 route add 2222:4::2/128 encap seg6 mode inline segs 2222:3::2 dev eth0; \
ip -6 route add 3333:4::2/128 encap seg6 mode encap segs 3333:3::2,3333:2::2,3333:3::1 dev eth0"
remoteCmd = SSHCommand(cmd, "127.0.0.1", 220, "srv6", "srv6")
remoteCmd.run()
# Close the session
close_ssh_session(remoteCmd)
# Now delete all the routes created before
cmds = ["ip -6 route del 1111:4::2/128 dev eth0", "ip -6 route del 2222:4::2/128 dev eth0",
"ip -6 route del 3333:4::2/128 dev eth0"]
# Iterate over the commands
for cmd in cmds:
# Each time creating a new session
remoteCmd = SSHCommand(cmd, "127.0.0.1", 220, "srv6", "srv6")
remoteCmd.run()
close_ssh_session(remoteCmd)