-
Notifications
You must be signed in to change notification settings - Fork 2
/
StopController.py
55 lines (49 loc) · 1.62 KB
/
StopController.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
#!/usr/bin/env python
import os
import sys
import yaml
from jinja2 import Template
from time import sleep
def RenderConfigFiles():
script_dir = os.path.dirname(__file__)
rel_path = "TopologyVariables.yaml"
abs_file_path = os.path.join(script_dir, rel_path)
file=open(abs_file_path)
topo_vars = yaml.load(file.read())
topo_vars['home_directory'] = os.path.dirname(os.path.realpath(__file__))
file.close()
template_open = open("srdemo.j2")
ingress_template = Template(template_open.read())
template_output = ingress_template.render(topo_vars)
script_dir = os.path.dirname(__file__)
rel_path = "srdemo.conf"
abs_file_path = os.path.join(script_dir, rel_path)
with open(abs_file_path, "wb") as f:
f.write(template_output)
f.close()
file.close()
def main():
#os.chdir( path )
RenderConfigFiles()
with open('TopologyVariables.yaml', 'r') as f:
TopoVar = yaml.load(f)
f.close()
user = str(TopoVar['Container']['user'])
password = str(TopoVar['Container']['password'])
host = str(TopoVar['Container']['ip_address'])
poll_router = str(TopoVar['ISIS-DB-Poll']['ip_address'])
poll_router_user = str(TopoVar['ISIS-DB-Poll']['user'])
poll_router_pw = str(TopoVar['ISIS-DB-Poll']['password'])
data = {"user": user,
"host": host,
"password": password,
"commands": "sudo pkill -9 exabgp ; sudo pkill -9 screen ; screen -wipe"}
command = "sshpass -p {password} ssh -o StrictHostKeyChecking=no {user}@{host} {commands}"
os.system(command.format(**data))
print ("\n\nKilling Controller........\n\n\n")
sleep(0.5)
print ("\n\nDone! ........\n\n\n")
exit(0)
if __name__ == "__main__":
main()
os.system("sudo pkill -9 python")