forked from Renater/SIPMediaGW
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPLauncher.py
More file actions
executable file
·60 lines (49 loc) · 1.72 KB
/
HTTPLauncher.py
File metadata and controls
executable file
·60 lines (49 loc) · 1.72 KB
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
#!/usr/bin/python
import web
import json
import subprocess
import os
import docker
class Launcher:
def GET(self, args=None):
data = web.input()
resJson = []
web.header('Content-Type', 'application/json')
response = dict()
gwSubProc = ['./SIPMediaGW.sh']
if 'from' in data.keys():
gwSubProc.append( '-f%s' % data['from'])
if 'room' in data.keys() and data['room'] != '0':
gwSubProc.append( '-r%s' % data['room'])
if 'prefix' in data.keys():
gwSubProc.append( '-p%s' % data['prefix'])
filePath = os.path.dirname(__file__)
print(gwSubProc)
res = subprocess.Popen(gwSubProc, cwd=filePath, stdout=subprocess.PIPE)
res.wait()
resStr = res.stdout.read().decode('utf-8')
resJson = json.loads(resStr.replace("'", '"'))
return json.dumps(resJson)
class Status:
def GET(self, args=None):
client = docker.from_env()
callsEnded = True
readyToCall = 0
for i in range(8):
try:
gateway = client.containers.get(f"gw{i}")
if gateway.status == "running":
callsEnded = False
readyToCall += "chrome" not in str(gateway.exec_run("ps -e").output)
except:
if i == 0: # No gateways started yet
callsEnded = False
break
return json.dumps({"readyToCall": readyToCall, "callsEnded": callsEnded})
urls = "/(.*)", "Launcher"
application = web.application(urls, globals()).wsgifunc()
urls = ("/sipmediagw", "Launcher",
"/status", "Status")
app = web.application(urls, globals())
if __name__ == "__main__":
app.run()