/
services.py
372 lines (309 loc) · 11.1 KB
/
services.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
from fabfile.config import *
from misc import zoolink
from fabfile.utils.fabos import detect_ostype
@task
@roles('cfgm')
def stop_rabbitmq():
with settings(warn_only=True):
sudo('service supervisor-support-service stop')
@task
@roles('cfgm')
def restart_rabbitmq():
sudo('service supervisor-support-service restart')
@task
def stop_and_disable_qpidd():
"""stops the qpidd and disables it."""
execute(stop_and_disable_qpidd_node, env.host_string)
@task
def stop_and_disable_qpidd_node(*args):
"""stops the qpidd and disables it in one node."""
for host_string in args:
with settings(host_string=host_string, warn_only=True):
if not sudo('service qpidd status').succeeded:
print "qpidd not running, skipping stop."
return
with settings(host_string=host_string):
sudo('service qpidd stop')
sudo('chkconfig qpidd off')
@task
@roles('database')
def stop_database():
"""stops the contrail database services."""
#sudo('service supervisord-contrail-database stop')
sudo('service supervisor-database stop')
@task
@roles('cfgm')
def stop_cfgm():
"""stops the contrail config services."""
execute('stop_cfgm_node', env.host_string)
@task
def stop_cfgm_node(*args):
for host_string in args:
with settings(host_string=host_string, warn_only=True):
sudo('service supervisor-config stop')
sudo('service neutron-server stop')
sudo('service supervisor-support-service stop')
@task
@roles('cfgm')
def start_cfgm():
"""starts the contrail config services."""
with settings(warn_only=True):
sudo('service supervisor-support-service start')
sudo('service supervisor-config start')
sudo('service neutron-server start')
@task
@roles('database')
def start_database():
"""Starts the contrail database services."""
#sudo('service supervisord-contrail-database start')
sudo('service supervisor-database start')
@task
@roles('control')
def start_control():
"""Starts the contrail control services."""
sudo('service supervisor-control start')
@task
@roles('webui')
def start_webui():
"""starts the contrail webui services."""
sudo('service supervisor-webui start')
@task
@roles('collector')
def start_collector():
"""starts the contrail collector services."""
sudo('service supervisor-analytics start')
@task
@roles('control')
def stop_control():
"""Stops the contrail control services."""
execute('stop_control_node', env.host_string)
@task
def stop_control_node(*args):
"""Stops the contrail control services in once control node. USAGE:fab stop_control_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
sudo('service supervisor-control stop')
@task
@roles('collector')
def stop_collector():
"""stops the contrail collector services."""
with settings(warn_only=True):
sudo('service supervisor-analytics stop')
@task
@roles('compute')
def stop_vrouter():
"""stops the contrail vrouter services."""
sudo('service supervisor-vrouter stop')
@task
@roles('webui')
def stop_webui():
"""stops the contrail webui services."""
sudo('service supervisor-webui stop')
@task
@roles('database')
def restart_database():
"""Restarts the contrail database services."""
execute('restart_database_node', env.host_string)
@task
def restart_database_node(*args):
"""Restarts the contrail database services in once database node. USAGE:fab restart_database_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
execute('zoolink_node', host_string)
zoo_svc = 'zookeeper'
sudo('service %s restart' % zoo_svc)
for host_string in args:
with settings(host_string=host_string):
sudo('service supervisor-database restart')
@task
@roles('openstack')
def restart_openstack():
"""Restarts the contrail openstack services."""
execute('restart_openstack_node', env.host_string)
@task
def restart_openstack_node(*args):
"""Restarts the contrail openstack services in once openstack node. USAGE:fab restart_openstack_node:user@1.1.1.1,user@2.2.2.2"""
openstack_services = [ 'httpd', 'memcached', 'supervisor-openstack']
if detect_ostype() in ['ubuntu']:
openstack_services = ['memcached', 'supervisor-openstack']
for host_string in args:
with settings(host_string=host_string):
for svc in openstack_services:
sudo('service %s restart' % svc)
@task
@roles('compute')
def restart_openstack_compute():
"""Restarts the contrail openstack compute service."""
if 'tsn' in env.roledefs.keys() and env.host_string in env.roledefs['tsn']:
return
if detect_ostype() in ['ubuntu']:
sudo('service nova-compute restart')
return
sudo('service openstack-nova-compute restart')
@task
@parallel
@roles('cfgm')
def restart_cfgm():
"""Restarts the contrail config services."""
execute("restart_cfgm_node", env.host_string)
@task
def restart_cfgm_node(*args):
"""Restarts the contrail config services in once cfgm node. USAGE:fab restart_cfgm_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
sudo('service supervisor-support-service restart')
sudo('service supervisor-config restart')
sudo('service neutron-server restart')
@task
@roles('control')
def restart_control():
"""Restarts the contrail control services."""
execute("restart_control_node", env.host_string)
@task
def restart_control_node(*args):
"""Restarts the contrail control services in once control node. USAGE:fab restart_control_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
sudo('service supervisor-control restart')
@task
@roles('collector')
def restart_collector():
"""Restarts the contrail collector services."""
execute('restart_collector_node', env.host_string)
@task
def restart_collector_node(*args):
"""Restarts the contrail collector services in once collector node. USAGE:fab restart_collector_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
sudo('service supervisor-analytics restart')
@task
@roles('compute')
def restart_vrouter():
"""Restarts the contrail compute services."""
execute('restart_vrouter_node', env.host_string)
@task
def restart_vrouter_node(*args):
"""Restarts the contrail vrouter services in once vrouter node. USAGE:fab restart_vrouter_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
sudo('service supervisor-vrouter restart')
@task
@roles('webui')
def restart_webui():
"""Restarts the contrail webui services."""
execute('restart_webui_node', env.host_string)
@task
def restart_webui_node(*args):
"""Restarts the contrail webui services in once webui node. USAGE:fab restart_webui_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
sudo('service supervisor-webui restart')
@task
@roles('webui')
def start_redis_webui():
"""Starts redis service in webui node."""
execute('start_redis_webui_node', env.host_string)
@task
def start_redis_webui_node(*args):
"""Starts redis service in webui node. USAGE:fab start_redis_webui_node:user@1.1.1.1,user@2.2.2.2"""
for host_string in args:
with settings(host_string=host_string):
run('chkconfig redis on')
run('service redis start')
@task
@roles('build')
def stop_contrail_control_services():
"""stops the Contrail config,control,analytics,database,webui services."""
execute('stop_cfgm')
execute('stop_database')
execute('stop_collector')
execute('stop_control')
execute('stop_webui')
@task
@roles('build')
def start_contrail_control_services():
"""Starts the Contrail config,control,analytics,database,webui services."""
execute('start_cfgm')
execute('start_database')
execute('start_collector')
execute('start_control')
execute('start_webui')
@task
@roles('build')
def restart_contrail_control_services():
"""Restarts the Contrail config,control,analytics,database,webui services."""
execute('restart_cfgm')
execute('restart_database')
execute('restart_collector')
execute('restart_control')
execute('restart_webui')
@roles('openstack')
def stop_nova():
"""Stop nova services :fab stop_nova"""
host = env.host_string
openstack_services = ['nova-api', 'nova-scheduler',
'nova-conductor']
with settings(host_string=host):
for svc in openstack_services:
sudo('service %s stop' % svc)
@roles('openstack')
def start_nova():
"""Start nova services :fab stop_nova"""
host = env.host_string
openstack_services = ['nova-api', 'nova-scheduler',
'nova-conductor']
with settings(host_string=host):
for svc in openstack_services:
sudo('service %s start' % svc)
@roles('openstack')
def stop_keystone():
"""Stop keystone services :fab stop_keystone"""
host = env.host_string
openstack_services = ['keystone']
with settings(host_string=host):
for svc in openstack_services:
sudo('service %s stop' % svc)
@roles('openstack')
def start_keystone():
"""Start keystone services :fab start_keystone"""
host = env.host_string
openstack_services = ['keystone']
with settings(host_string=host):
for svc in openstack_services:
sudo('service %s start' % svc)
@roles('openstack')
def stop_glance():
"""Stop keystone services :fab stop_keystone"""
host = env.host_string
openstack_services = ['glance-api','glance-registry']
with settings(host_string=host):
for svc in openstack_services:
sudo('service %s stop' % svc)
@roles('openstack')
def start_glance():
"""Start keystone services :fab start_keystone"""
host = env.host_string
openstack_services = ['glance-api','glance-registry']
with settings(host_string=host):
for svc in openstack_services:
sudo('service %s start' % svc)
@roles('compute')
def stop_nova_openstack_compute():
"""Stop the contrail openstack compute service."""
if detect_ostype() in ['ubuntu']:
sudo('service nova-compute stop')
return
sudo('service openstack-nova-compute stop')
@roles('compute')
def start_nova_openstack_compute():
"""Start the contrail openstack compute service."""
if detect_ostype() in ['ubuntu']:
sudo('service nova-compute start')
return
sudo('service openstack-nova-compute start')
@roles('openstack')
def reboot_nova_instance():
host = env.host_string
with settings(host_string=host,warn_only=True):
sudo(
"source /etc/contrail/openstackrc;nova list --all_tenants | awk '{print $2}' | grep -v ID | xargs -L1 nova reboot --hard $2")