~openstack-charmers-next/charms/wily/nova-compute/trunk

« back to all changes in this revision

Viewing changes to hooks/nova_compute_hooks.py

  • Committer: James Page
  • Date: 2015-10-07 23:48:03 UTC
  • mfrom: (170.1.2 trunk)
  • Revision ID: james.page@ubuntu.com-20151007234803-ix3qpg6qymc3880i
Refactor to assess status after every hook execution, add update-status hook

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
    git_install_requested,
34
34
    openstack_upgrade_available,
35
35
    os_requires_version,
36
 
    os_workload_status,
 
36
    set_os_workload_status,
37
37
)
38
38
 
39
39
from charmhelpers.contrib.storage.linux.ceph import (
92
92
 
93
93
 
94
94
@hooks.hook('install.real')
95
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
96
 
                    charm_func=check_optional_relations)
97
95
def install():
98
96
    status_set('maintenance', 'Executing pre-install')
99
97
    execd_preinstall()
108
106
 
109
107
 
110
108
@hooks.hook('config-changed')
111
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
112
 
                    charm_func=check_optional_relations)
113
109
@restart_on_change(restart_map())
114
110
def config_changed():
115
111
    if config('prefer-ipv6'):
166
162
 
167
163
 
168
164
@hooks.hook('amqp-relation-joined')
169
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
170
 
                    charm_func=check_optional_relations)
171
165
def amqp_joined(relation_id=None):
172
166
    relation_set(relation_id=relation_id,
173
167
                 username=config('rabbit-user'),
176
170
 
177
171
@hooks.hook('amqp-relation-changed')
178
172
@hooks.hook('amqp-relation-departed')
179
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
180
 
                    charm_func=check_optional_relations)
181
173
@restart_on_change(restart_map())
182
174
def amqp_changed():
183
175
    if 'amqp' not in CONFIGS.complete_contexts():
193
185
 
194
186
 
195
187
@hooks.hook('shared-db-relation-joined')
196
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
197
 
                    charm_func=check_optional_relations)
198
188
def db_joined(rid=None):
199
189
    if is_relation_made('pgsql-db'):
200
190
        # error, postgresql is used
210
200
 
211
201
 
212
202
@hooks.hook('pgsql-db-relation-joined')
213
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
214
 
                    charm_func=check_optional_relations)
215
203
def pgsql_db_joined():
216
204
    if is_relation_made('shared-db'):
217
205
        # raise error
224
212
 
225
213
 
226
214
@hooks.hook('shared-db-relation-changed')
227
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
228
 
                    charm_func=check_optional_relations)
229
215
@restart_on_change(restart_map())
230
216
def db_changed():
231
217
    if 'shared-db' not in CONFIGS.complete_contexts():
235
221
 
236
222
 
237
223
@hooks.hook('pgsql-db-relation-changed')
238
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
239
 
                    charm_func=check_optional_relations)
240
224
@restart_on_change(restart_map())
241
225
def postgresql_db_changed():
242
226
    if 'pgsql-db' not in CONFIGS.complete_contexts():
246
230
 
247
231
 
248
232
@hooks.hook('image-service-relation-changed')
249
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
250
 
                    charm_func=check_optional_relations)
251
233
@restart_on_change(restart_map())
252
234
def image_service_changed():
253
235
    if 'image-service' not in CONFIGS.complete_contexts():
289
271
 
290
272
 
291
273
@hooks.hook('ceph-relation-joined')
292
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
293
 
                    charm_func=check_optional_relations)
294
274
@restart_on_change(restart_map())
295
275
def ceph_joined():
296
276
    status_set('maintenance', 'Installing apt packages')
307
287
 
308
288
 
309
289
@hooks.hook('ceph-relation-changed')
310
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
311
 
                    charm_func=check_optional_relations)
312
290
@restart_on_change(restart_map())
313
291
def ceph_changed():
314
292
    if 'ceph' not in CONFIGS.complete_contexts():
343
321
 
344
322
 
345
323
@hooks.hook('ceph-relation-broken')
346
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
347
 
                    charm_func=check_optional_relations)
348
324
def ceph_broken():
349
325
    service = service_name()
350
326
    delete_keyring(service=service)
355
331
            'image-service-relation-broken',
356
332
            'shared-db-relation-broken',
357
333
            'pgsql-db-relation-broken')
358
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
359
 
                    charm_func=check_optional_relations)
360
334
@restart_on_change(restart_map())
361
335
def relation_broken():
362
336
    CONFIGS.write_all()
381
355
 
382
356
 
383
357
@hooks.hook('zeromq-configuration-relation-joined')
384
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
385
 
                    charm_func=check_optional_relations)
386
358
@os_requires_version('kilo', 'nova-common')
387
359
def zeromq_configuration_relation_joined(relid=None):
388
360
    relation_set(relation_id=relid,
391
363
 
392
364
 
393
365
@hooks.hook('zeromq-configuration-relation-changed')
394
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
395
 
                    charm_func=check_optional_relations)
396
366
@restart_on_change(restart_map())
397
367
def zeromq_configuration_relation_changed():
398
368
    CONFIGS.write(NOVA_CONF)
411
381
 
412
382
 
413
383
@hooks.hook('neutron-plugin-relation-changed')
414
 
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
415
 
                    charm_func=check_optional_relations)
416
384
@restart_on_change(restart_map())
417
385
def neutron_plugin_changed():
418
386
    settings = relation_get()
445
413
        hooks.execute(sys.argv)
446
414
    except UnregisteredHookError as e:
447
415
        log('Unknown hook {} - skipping.'.format(e))
 
416
    set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
 
417
                           charm_func=check_optional_relations)
448
418
 
449
419
 
450
420
if __name__ == '__main__':