blob: 9384d8596b131a801ad92ec06e807729d2e15d73 [file] [log] [blame]
ss412g07ef76d2019-08-12 17:26:40 +03001#!/usr/bin/env python
2
3
4import sys, os, traceback
5import docker
6# Getting the Arguments. if argument are missing exit the script with exit 1
7try:
8 ms = sys.argv[1].lower()
9 action = sys.argv[2].lower()
10 script = os.path.basename(sys.argv[0])
11except:
12 print("Usage: %s <microservice> <action> for now only stop action is allowd" % \
13 (os.path.basename(sys.argv[0])))
14 sys.exit(1)
15
16ms=sys.argv[1].lower()
17action=sys.argv[2].lower()
18docker_host_ip=os.environ.get('DOCKER_HOST_IP', False)
19cms=[]
20if not docker_host_ip:
21 print('The DOCKER_HOST_IP env varibale is not defined, exiting!')
22 sys.exit(1)
23
24def get_ms():
25 try:
26 client = docker.DockerClient(base_url='tcp://%s:2376' % docker_host_ip)
27
28 for ms in client.containers.list():
29 if ms.name == sys.argv[1]:
30 cms.append(ms)
31 return cms[0]
32 except:
33 print('Can\'t connect to docker API, Exiting!')
34 print(traceback.format_exc())
35 sys.exit(1)
36
37if action == 'stop':
38 print('Stop the %s pod' % ms )
39 get_ms().stop()
40 sys.exit(0)
41else:
42 print ('Only stop commnad is allowed!, exiting!')
43 sys.exit(1)