-
Notifications
You must be signed in to change notification settings - Fork 0
/
naas.py
66 lines (53 loc) · 2.09 KB
/
naas.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
#!/usr/bin/python2
import cgi
import commands
print "content-type: text/html"
print
Bname=cgi.FormContent()['bname'][0]
Cip=cgi.FormContent()['cip'][0]
Cpass=cgi.FormContent()['cpass'][0]
x=commands.getoutput("sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} sudo ifconfig | grep enp0s".format(Cpass,Cip))
y=x.split('.')
z=y[-1][2:8]
commands.getstatusoutput("sudo touch /naas/daemon.json")
commands.getstatusoutput("sudo chown apache /naas/daemon.json")
x="""{{
\"bridge\" : \"{0}\"
}}
""".format(Bname)
f1=open('/naas/daemon.json','w')
f1.write(x)
f1.close()
commands.getstatusoutput("sshpass -p {0} scp -o stricthostkeychecking=no /naas/daemon.json root@{1}:/etc/docker/".format(Cpass,Cip))
commands.getstatusoutput(" sudo touch /naas/Dockerfile")
commands.getstatusoutput("sudo chown apache /naas/Dockerfile")
#Creating a Dockerfile with required tools
y="""FROM centos
RUN yum install net-tools -y
RUN yum install dhclient -y
"""
commands.getstatusoutput("sudo touch /naas/Dockerfile")
commands.getstatusoutput("sudo chown apache /naas/Dockerfile")
f2=open("/naas/Dockerfile",'w')
f2.write(y)
f2.close()
commands.getstatusoutput("sshpass -p {0} ssh -o stricthostkeychecking=no -l root {1} sudo mkdir /test".format(Cpass,Cip))
commands.getstatusoutput("sshpass -p {0} scp -o stricthostkeychecking=no /naas/Dockerfile root@{1}:/test/".format(Cpass,Cip))
#Python Script to be run on client side
a="""#!/usr/bin/python2
import cgi
import commands
commands.getstatusoutput(\"brctl addbr {0}\")\n
commands.getstatusoutput(\"ifconfig {0} 0\")\n
commands.getstatusoutput(\"ifconfig {3} 0\")\n
commands.getstatusoutput(\"brctl addif {0} {3}\")\n
commands.getstatusoutput(\"killall dhclient\")\n
print commands.getstatusoutput(\"dhclient -v {0}\")\n
""".format(Bname,Iname,Cname,z)
commands.getoutput("sudo touch /naas/naas.py")
commands.getoutput("sudo chown apache /naas/naas.py")
f3=open('/naas/naas.py','w')
f3.write(a)
f3.close()
print commands.getoutput("sudo chmod +x /naas/naas.py")
commands.getstatusoutput("sshpass -p {0} scp -o stricthostkeychecking=no /naas/naas.py root@{1}:/test/".format(Cpass,Cip))