5
from charmhelpers.core.hookenv import (
14
UnregisteredHookError,
17
from charmhelpers.core.host import (
21
from charmhelpers.fetch import (
24
filter_installed_packages,
27
from charmhelpers.contrib.openstack.utils import (
28
configure_installation_source,
29
openstack_upgrade_available,
32
from charmhelpers.contrib.storage.linux.ceph import ensure_ceph_keyring
33
from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
34
from charmhelpers.payload.execd import execd_preinstall
36
from nova_compute_utils import (
37
create_libvirt_secret,
39
import_authorized_keys,
40
import_keystone_ca_cert,
50
QUANTUM_CONF, NEUTRON_CONF,
51
CEPH_CONF, CEPH_SECRET
54
from nova_compute_context import CEPH_SECRET_UUID
57
CONFIGS = register_configs()
63
configure_installation_source(config('openstack-origin'))
65
apt_install(determine_packages(), fatal=True)
68
@hooks.hook('config-changed')
69
@restart_on_change(restart_map())
71
if openstack_upgrade_available('nova-common'):
72
do_openstack_upgrade(CONFIGS)
74
if migration_enabled() and config('migration-auth-type') == 'ssh':
75
# Check-in with nova-c-c and register new ssh key, if it has just been
78
[compute_joined(rid) for rid in relation_ids('cloud-compute')]
83
@hooks.hook('amqp-relation-joined')
84
@restart_on_change(restart_map())
86
relation_set(username=config('rabbit-user'), vhost=config('rabbit-vhost'))
89
@hooks.hook('amqp-relation-changed')
90
@restart_on_change(restart_map())
92
if 'amqp' not in CONFIGS.complete_contexts():
93
log('amqp relation incomplete. Peer not ready?')
95
CONFIGS.write(NOVA_CONF)
96
if network_manager() == 'quantum':
97
CONFIGS.write(QUANTUM_CONF)
98
if network_manager() == 'neutron':
99
CONFIGS.write(NEUTRON_CONF)
102
@hooks.hook('shared-db-relation-joined')
103
def db_joined(rid=None):
104
relation_set(relation_id=rid,
105
nova_database=config('database'),
106
nova_username=config('database-user'),
107
nova_hostname=unit_get('private-address'))
108
if network_manager() in ['quantum', 'neutron']:
109
# XXX: Renaming relations from quantum_* to neutron_* here.
110
relation_set(relation_id=rid,
111
neutron_database=config('neutron-database'),
112
neutron_username=config('neutron-database-user'),
113
neutron_hostname=unit_get('private-address'))
116
@hooks.hook('shared-db-relation-changed')
117
@restart_on_change(restart_map())
119
if 'shared-db' not in CONFIGS.complete_contexts():
120
log('shared-db relation incomplete. Peer not ready?')
122
CONFIGS.write(NOVA_CONF)
123
nm = network_manager()
124
if nm in ['quantum', 'neutron']:
125
plugin = neutron_plugin()
126
CONFIGS.write(neutron_plugin_attribute(plugin, 'config', nm))
129
@hooks.hook('image-service-relation-changed')
130
@restart_on_change(restart_map())
131
def image_service_changed():
132
if 'image-service' not in CONFIGS.complete_contexts():
133
log('image-service relation incomplete. Peer not ready?')
135
CONFIGS.write(NOVA_CONF)
138
@hooks.hook('cloud-compute-relation-joined')
139
def compute_joined(rid=None):
140
if not migration_enabled():
142
auth_type = config('migration-auth-type')
144
'migration_auth_type': auth_type
146
if auth_type == 'ssh':
147
settings['ssh_public_key'] = public_ssh_key()
148
relation_set(relation_id=rid, **settings)
151
@hooks.hook('cloud-compute-relation-changed')
152
@restart_on_change(restart_map())
153
def compute_changed():
154
# rewriting all configs to pick up possible net or vol manager
155
# config advertised from controller.
157
import_authorized_keys()
158
import_keystone_ca_cert()
159
if network_manager() in ['quantum', 'neutron']:
160
# in case we already have a database relation, need to request
161
# access to the additional neutron database.
162
[db_joined(rid) for rid in relation_ids('shared-db')]
165
@hooks.hook('ceph-relation-joined')
166
@restart_on_change(restart_map())
168
apt_install(filter_installed_packages(['ceph-common']), fatal=True)
171
@hooks.hook('ceph-relation-changed')
172
@restart_on_change(restart_map())
174
if 'ceph' not in CONFIGS.complete_contexts():
175
log('ceph relation incomplete. Peer not ready?')
178
if not ensure_ceph_keyring(service=svc):
179
log('Could not create ceph keyring: peer not ready?')
181
CONFIGS.write(CEPH_CONF)
182
CONFIGS.write(CEPH_SECRET)
183
CONFIGS.write(NOVA_CONF)
185
# With some refactoring, this can move into NovaComputeCephContext
186
# and allow easily extended to support other compute flavors.
187
if config('virt-type') in ['kvm', 'qemu', 'lxc']:
188
create_libvirt_secret(secret_file=CEPH_SECRET,
189
secret_uuid=CEPH_SECRET_UUID,
190
key=relation_get('key'))
193
@hooks.hook('amqp-relation-broken',
194
'ceph-relation-broken',
195
'image-service-relation-broken',
196
'shared-db-relation-broken')
197
@restart_on_change(restart_map())
198
def relation_broken():
204
hooks.execute(sys.argv)
205
except UnregisteredHookError as e:
206
log('Unknown hook {} - skipping.'.format(e))
209
if __name__ == '__main__':