forked from vinklat/macli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_marathon.py
executable file
·77 lines (61 loc) · 2.19 KB
/
api_marathon.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python
from marathon import MarathonClient, MarathonApp
import json
class Marathon(MarathonClient):
def get_app_json(self, id):
app = MarathonClient.get_app(self, id)
return (app.to_json())
def get_app_dict(self, id):
return (json.loads(self.get_app_json(id)))
# def get_app_json_config(self,id):
# app = self.get_app_dict(id)
# if 'tasks' in app:
# del app['tasks']
# if 'tasksiRunning' in app:
# del app['tasksRunning']
# return (json.dumps(app))
def get_apps_json_config(self):
n = 0
d = {}
for app in MarathonClient.list_apps(self):
json_data = json.loads(app.to_json())
for p in 'tasks', 'tasksRunning', 'tasksStaged':
if p in json_data:
del json_data[p]
d[n] = json_data
n += 1
return (json.dumps(d))
# def get_apps_list(self):
# apps=[]
# for app in MarathonClient.list_apps(self):
# apps.append(app.id)
# return apps
def get_apps_dict(self):
apps = {}
for app in MarathonClient.list_apps(self):
apps[app.id] = self.get_app_dict(app.id)
return apps
def get_hosts_dict(self):
hosts = {}
for app in MarathonClient.list_apps(self):
for task in MarathonClient.get_app(self, app.id).tasks:
host = task.host
if not host in hosts:
hosts[host] = []
hosts[host].append(task)
return hosts
def kill_t(self, task_id):
# MarathonClient.kill_task(self,app_id, task_id, False, False)
return MarathonClient.kill_given_tasks(self, task_id)
# return 0
# def kill_h(self, app_id, hostname):
# MarathonClient.kill_tasks(self,app_id, False, False, hostname, 0, 0)
# return 0
def create_app_from_json(self, json_data):
a = MarathonApp.from_json(json_data)
return MarathonClient.create_app(self, a.id, a)
def update_app_from_json(self, json_data, force):
a = MarathonApp.from_json(json_data)
return MarathonClient.update_app(self, a.id, a, force)
def __init__(self, addr):
MarathonClient.__init__(self, addr)