-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerrun.py
More file actions
36 lines (36 loc) · 895 Bytes
/
dockerrun.py
File metadata and controls
36 lines (36 loc) · 895 Bytes
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
#! /usr/bin/python3
print("content-type:text/html")
print()
import subprocess as sp
import cgi
form=cgi.FieldStorage()
cmd1=form.getvalue("x")
cmd=int(cmd1)
#osname=input("enter your os name:")
if cmd==1:
cmd_start="sudo docker run -d -i -t --name myos ubuntu:14.04"
output=sp.getstatusoutput(cmd_start)
status=output[0]
out=output[1]
if status ==0:
print("OS launched ")
else:
print("some error:{}".format(out))
elif cmd==2:
cmd_stop="sudo docker stop myos"
output=sp.getstatusoutput(cmd_stop)
status=output[0]
out=output[1]
if status ==0:
print("OS stopped")
else:
print("some error:{}".format(out))
elif cmd==3:
cmd_status="sudo docker rm myos"
output=sp.getstatusoutput(cmd_status)
status=output[0]
out=output[1]
if status ==0:
print("os is removed")
else:
print("some error:{}".format(out))