-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
81 lines (55 loc) · 2.34 KB
/
fabfile.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
78
79
80
81
from __future__ import print_function
from fabric.api import env, run
import osmaxx
from host_setup import provide_docker_compose
env.use_ssh_config = True
OSMAXX_COMPONENT = osmaxx.__name__
ALL_COMPONENTS = {
OSMAXX_COMPONENT: osmaxx,
}
class Action(object):
def __init__(self, action, default_components):
self.action = action
self.default_components = default_components
def perform(self, on_components):
if isinstance(on_components, basestring):
on_components = set(on_components.split(";"))
assert on_components.issubset(ALL_COMPONENTS.keys())
for component in on_components:
component_environment = {}
exec_string = "executing {} on {}".format(self.action, component)
print("")
print(exec_string)
print("=" * len(exec_string))
module = ALL_COMPONENTS[component]
if hasattr(module, 'ENVIRONMENT'):
component_environment = module.ENVIRONMENT
for command in getattr(module, self.action):
command.execute(project=component, hostname=env.host_string, environment=component_environment)
print('*' * 40)
def __call__(self, on_components=None):
if on_components is None:
on_components = self.default_components
self.perform(on_components)
health_check = Action('health_check', default_components=set(ALL_COMPONENTS))
logs = Action('logs', default_components=set(ALL_COMPONENTS))
_pre_start = Action('pre_start', default_components=set(ALL_COMPONENTS))
_actual_start = Action('start', default_components=set(ALL_COMPONENTS))
_stop = Action('stop', default_components=set(ALL_COMPONENTS))
_change = Action('change', default_components=set(ALL_COMPONENTS))
def prepare_host():
provide_docker_compose()
def start(on_components=set(ALL_COMPONENTS)):
_pre_start(on_components=on_components)
_actual_start(on_components=on_components)
health_check(on_components=on_components)
def upgrade(on_components=OSMAXX_COMPONENT):
_change(on_components=on_components)
health_check(on_components=on_components)
def stop(on_components=set(ALL_COMPONENTS)):
_stop(on_components=on_components)
health_check(on_components=on_components)
def execute_command(command):
run(command)
def host_type():
run('uname -s')