-
Notifications
You must be signed in to change notification settings - Fork 0
/
task9.py
59 lines (56 loc) · 1.99 KB
/
task9.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
#!/usr/bin/python3
import cgi
import subprocess
import time
print("content-type: text/html")
print()
f = cgi.FieldStorage()
cmd = f.getvalue("x")
ins = cmd.split()
if ins[0] == "1":
img_name = ins[1]
deployment_name = ins[2]
command = "kubectl create deployment " + (deployment_name) + " --image=" + (img_name)
o = subprocess.getoutput("sudo " + command + " --kubeconfig /root/admin.conf")
print(o)
elif ins[0] == "2":
pod_name = ins[2]
img_name = ins[1]
command = "kubectl run " + (pod_name) + " --image=" + (img_name)
o = subprocess.getoutput("sudo " + command + " --kubeconfig /root/admin.conf")
print(o)
elif ins[0] == "3":
pod_name = ins[1]
command = "kubectl delete pod " + (pod_name)
o = subprocess.getoutput("sudo " + command + " --kubeconfig /root/admin.conf")
print(o)
elif ins[0] == "4":
deployment_name = ins[1]
command = "kubectl delete deployment " + (deployment_name)
o = subprocess.getoutput("sudo " + command + " --kubeconfig /root/admin.conf")
print(o)
elif ins[0] == "5":
deployment_name = ins[1]
port_no = ins[2]
expose_type = ins[3]
command = "kubectl expose deployment " + (deployment_name) + " --port=" + (port_no) + " --type=" + (expose_type)
o = subprocess.getoutput("sudo " + command + " --kubeconfig /root/admin.conf")
print(o)
elif ins[0] == "6":
deployment_name = ins[1]
replica = ins[2]
command = "kubectl scale deployment " + (deployment_name) + " --replicas=" + (replica)
o = subprocess.getoutput("sudo " + command + " --kubeconfig /root/admin.conf")
print(o)
elif ins[0] == "7":
command = "sudo kubectl get pods --kubeconfig /root/admin.conf"
o = subprocess.getoutput(command)
print(o)
elif ins[0] == "8":
command = "sudo kubectl get svc --kubeconfig /root/admin.conf"
o = subprocess.getoutput(command)
print(o)
elif ins[0] == "9":
command = "sudo kubectl delete all --all --kubeconfig /root/admin.conf"
o = subprocess.getoutput(command)
print(o)