-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_wind_play.py
53 lines (46 loc) · 1.6 KB
/
run_wind_play.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
#!/usr/bin/python
import subprocess
import sys
import os
def named_container_running(name):
"""Checks with docker if a container is running."""
command = "docker ps -q -f name={}".format(name)
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
process.wait()
id_text = process.stdout.read()
if not process.returncode == 0:
print Red+"\a"
print "ERROR: Docker call in 'named_container_running' failed."
print " Command:",command
print " Output:",id_text
print White
sys.exit(1)
if len(id_text) < 1:
return(False)
else:
return(id_text)
def kill():
subprocess.call("docker-compose -f docker-compose.yml kill",shell=True)
def rm():
subprocess.call("docker-compose -f docker-compose.yml rm ",shell=True)
def up():
# Is the edgeservice running?
if named_container_running('edgecdp'):
# Start up the wind turbine playground
subprocess.call("docker-compose -f docker-compose.yml up -d ",shell=True)
else:
print Red+"\a"
print "ERROR: Edge Services (edgecdp container) is not running."
print "FIX: Start it using the './start_edgeservices.sh' script"
print " located in the directory. 'edgeservices'"
print White
sys.exit(1)
def main():
if len(sys.argv) > 1 and sys.argv[1].lower() == 'up':
up()
if len(sys.argv) > 1 and sys.argv[1].lower() == 'kill':
kill()
if len(sys.argv) > 1 and sys.argv[1].lower() == 'rm':
rm()
if __name__ == '__main__':
main()