2013-07-18 19:37:30 -07:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2013-07-30 20:39:44 -07:00
|
|
|
import sys
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks,
|
|
|
|
config,
|
2014-03-25 10:12:03 +01:00
|
|
|
is_relation_made,
|
2013-07-18 19:37:30 -07:00
|
|
|
log,
|
2014-03-25 10:12:03 +01:00
|
|
|
ERROR,
|
2013-07-18 19:37:30 -07:00
|
|
|
relation_ids,
|
2013-09-03 17:16:15 -07:00
|
|
|
relation_get,
|
2013-07-18 19:37:30 -07:00
|
|
|
relation_set,
|
|
|
|
service_name,
|
|
|
|
unit_get,
|
2013-07-30 20:39:44 -07:00
|
|
|
UnregisteredHookError,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
|
|
|
from charmhelpers.core.host import (
|
2013-09-20 17:40:54 +01:00
|
|
|
restart_on_change,
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.fetch import (
|
2013-07-18 19:37:30 -07:00
|
|
|
apt_install,
|
|
|
|
apt_update,
|
2013-08-01 12:53:09 -07:00
|
|
|
filter_installed_packages,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
|
|
|
configure_installation_source,
|
|
|
|
openstack_upgrade_available,
|
|
|
|
)
|
|
|
|
|
2013-09-23 11:49:55 -07:00
|
|
|
from charmhelpers.contrib.storage.linux.ceph import ensure_ceph_keyring
|
2013-09-27 17:20:42 +01:00
|
|
|
from charmhelpers.payload.execd import execd_preinstall
|
2013-07-18 19:37:30 -07:00
|
|
|
from nova_compute_utils import (
|
2013-09-03 17:16:15 -07:00
|
|
|
create_libvirt_secret,
|
2013-07-18 21:41:07 -07:00
|
|
|
determine_packages,
|
2013-07-18 19:37:30 -07:00
|
|
|
import_authorized_keys,
|
|
|
|
import_keystone_ca_cert,
|
2013-07-30 20:39:44 -07:00
|
|
|
initialize_ssh_keys,
|
2013-07-18 19:37:30 -07:00
|
|
|
migration_enabled,
|
2013-08-12 14:48:24 -07:00
|
|
|
network_manager,
|
|
|
|
neutron_plugin,
|
2013-07-18 19:37:30 -07:00
|
|
|
do_openstack_upgrade,
|
|
|
|
public_ssh_key,
|
2013-07-18 21:41:07 -07:00
|
|
|
restart_map,
|
2013-07-18 19:37:30 -07:00
|
|
|
register_configs,
|
2013-09-20 17:50:33 +01:00
|
|
|
NOVA_CONF,
|
|
|
|
QUANTUM_CONF, NEUTRON_CONF,
|
2013-12-16 12:33:45 +00:00
|
|
|
ceph_config_file, CEPH_SECRET,
|
2014-02-19 16:03:50 +10:00
|
|
|
enable_shell, disable_shell,
|
2014-05-06 21:58:56 +00:00
|
|
|
fix_path_ownership,
|
2014-09-09 09:47:14 +00:00
|
|
|
services,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
|
|
|
|
2013-09-03 17:16:15 -07:00
|
|
|
from nova_compute_context import CEPH_SECRET_UUID
|
2014-06-12 10:40:30 +01:00
|
|
|
from socket import gethostname
|
2013-09-03 17:16:15 -07:00
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
hooks = Hooks()
|
|
|
|
CONFIGS = register_configs()
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook()
|
|
|
|
def install():
|
2013-09-27 17:20:42 +01:00
|
|
|
execd_preinstall()
|
2013-07-18 19:37:30 -07:00
|
|
|
configure_installation_source(config('openstack-origin'))
|
|
|
|
apt_update()
|
2013-07-18 21:41:07 -07:00
|
|
|
apt_install(determine_packages(), fatal=True)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('config-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def config_changed():
|
2014-04-01 17:01:37 +01:00
|
|
|
global CONFIGS
|
2013-07-18 19:37:30 -07:00
|
|
|
if openstack_upgrade_available('nova-common'):
|
2014-04-01 17:01:37 +01:00
|
|
|
CONFIGS = do_openstack_upgrade()
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
if migration_enabled() and config('migration-auth-type') == 'ssh':
|
|
|
|
# Check-in with nova-c-c and register new ssh key, if it has just been
|
|
|
|
# generated.
|
2013-07-30 20:39:44 -07:00
|
|
|
initialize_ssh_keys()
|
2013-12-16 10:10:19 +00:00
|
|
|
|
|
|
|
if config('enable-resize') is True:
|
2013-12-16 12:33:45 +00:00
|
|
|
enable_shell(user='nova')
|
2013-12-16 10:10:19 +00:00
|
|
|
initialize_ssh_keys(user='nova')
|
2013-12-16 12:33:45 +00:00
|
|
|
else:
|
|
|
|
disable_shell(user='nova')
|
2013-12-16 10:10:19 +00:00
|
|
|
|
2014-03-31 16:30:14 +01:00
|
|
|
if config('instances-path') is not None:
|
2014-02-19 14:40:50 +10:00
|
|
|
fp = config('instances-path')
|
2014-02-19 14:53:05 +10:00
|
|
|
fix_path_ownership(fp, user='nova')
|
2014-02-19 14:40:50 +10:00
|
|
|
|
2013-12-16 10:10:19 +00:00
|
|
|
[compute_joined(rid) for rid in relation_ids('cloud-compute')]
|
2014-09-09 09:52:27 +00:00
|
|
|
for rid in relation_ids('zeromq-configuration'):
|
|
|
|
zeromq_configuration_relation_joined(rid)
|
2013-07-30 19:40:47 -07:00
|
|
|
CONFIGS.write_all()
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-joined')
|
2013-10-17 20:25:15 +01:00
|
|
|
def amqp_joined(relation_id=None):
|
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
username=config('rabbit-user'),
|
|
|
|
vhost=config('rabbit-vhost'))
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-changed')
|
2014-01-30 12:46:46 +01:00
|
|
|
@hooks.hook('amqp-relation-departed')
|
|
|
|
@restart_on_change(restart_map())
|
2014-02-13 09:49:17 +01:00
|
|
|
def amqp_changed():
|
2014-01-30 12:46:46 +01:00
|
|
|
if 'amqp' not in CONFIGS.complete_contexts():
|
|
|
|
log('amqp relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
2014-06-23 15:00:12 +01:00
|
|
|
# No need to write NEUTRON_CONF if neutron-plugin is managing it
|
|
|
|
if not relation_ids('neutron-plugin'):
|
|
|
|
if network_manager() == 'quantum' and neutron_plugin() == 'ovs':
|
|
|
|
CONFIGS.write(QUANTUM_CONF)
|
|
|
|
if network_manager() == 'neutron' and neutron_plugin() == 'ovs':
|
|
|
|
CONFIGS.write(NEUTRON_CONF)
|
2014-01-30 12:46:46 +01:00
|
|
|
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
@hooks.hook('shared-db-relation-joined')
|
2013-08-15 12:43:43 -07:00
|
|
|
def db_joined(rid=None):
|
2014-03-25 10:12:03 +01:00
|
|
|
if is_relation_made('pgsql-db'):
|
|
|
|
# error, postgresql is used
|
|
|
|
e = ('Attempting to associate a mysql database when there is already '
|
2014-03-25 10:35:58 +01:00
|
|
|
'associated a postgresql one')
|
2014-03-25 10:12:03 +01:00
|
|
|
log(e, level=ERROR)
|
|
|
|
raise Exception(e)
|
|
|
|
|
2013-08-15 12:43:43 -07:00
|
|
|
relation_set(relation_id=rid,
|
|
|
|
nova_database=config('database'),
|
|
|
|
nova_username=config('database-user'),
|
|
|
|
nova_hostname=unit_get('private-address'))
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
2014-03-25 11:27:22 +01:00
|
|
|
@hooks.hook('pgsql-db-relation-joined')
|
|
|
|
def pgsql_db_joined():
|
2014-03-25 10:12:03 +01:00
|
|
|
if is_relation_made('shared-db'):
|
|
|
|
# raise error
|
2014-04-10 17:09:53 +01:00
|
|
|
e = ('Attempting to associate a postgresql database when'
|
|
|
|
' there is already associated a mysql one')
|
2014-03-25 10:12:03 +01:00
|
|
|
log(e, level=ERROR)
|
|
|
|
raise Exception(e)
|
|
|
|
|
|
|
|
relation_set(database=config('database'))
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('shared-db-relation-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def db_changed():
|
|
|
|
if 'shared-db' not in CONFIGS.complete_contexts():
|
|
|
|
log('shared-db relation incomplete. Peer not ready?')
|
|
|
|
return
|
2013-09-20 17:50:33 +01:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
2014-03-25 11:27:22 +01:00
|
|
|
@hooks.hook('pgsql-db-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def postgresql_db_changed():
|
|
|
|
if 'pgsql-db' not in CONFIGS.complete_contexts():
|
|
|
|
log('pgsql-db relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('image-service-relation-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def image_service_changed():
|
|
|
|
if 'image-service' not in CONFIGS.complete_contexts():
|
|
|
|
log('image-service relation incomplete. Peer not ready?')
|
|
|
|
return
|
2013-09-20 17:50:33 +01:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('cloud-compute-relation-joined')
|
|
|
|
def compute_joined(rid=None):
|
2014-06-12 10:40:30 +01:00
|
|
|
# NOTE(james-page) in MAAS environments the actual hostname is a CNAME
|
|
|
|
# record so won't get scanned based on private-address which is an IP
|
|
|
|
# add the hostname configured locally to the relation.
|
|
|
|
settings = {
|
|
|
|
'hostname': gethostname()
|
|
|
|
}
|
2013-12-16 10:10:19 +00:00
|
|
|
if migration_enabled():
|
|
|
|
auth_type = config('migration-auth-type')
|
2014-06-12 10:40:30 +01:00
|
|
|
settings['migration_auth_type'] = auth_type
|
2013-12-16 10:10:19 +00:00
|
|
|
if auth_type == 'ssh':
|
|
|
|
settings['ssh_public_key'] = public_ssh_key()
|
|
|
|
relation_set(relation_id=rid, **settings)
|
|
|
|
if config('enable-resize'):
|
2014-06-12 10:40:30 +01:00
|
|
|
settings['nova_ssh_public_key'] = public_ssh_key(user='nova')
|
2013-12-16 10:10:19 +00:00
|
|
|
relation_set(relation_id=rid, **settings)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('cloud-compute-relation-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def compute_changed():
|
2013-07-30 19:40:47 -07:00
|
|
|
# rewriting all configs to pick up possible net or vol manager
|
|
|
|
# config advertised from controller.
|
|
|
|
CONFIGS.write_all()
|
2013-07-18 19:37:30 -07:00
|
|
|
import_authorized_keys()
|
2013-12-16 10:10:19 +00:00
|
|
|
import_authorized_keys(user='nova', prefix='nova')
|
2013-07-18 19:37:30 -07:00
|
|
|
import_keystone_ca_cert()
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ceph-relation-joined')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def ceph_joined():
|
2013-08-01 16:37:19 -07:00
|
|
|
apt_install(filter_installed_packages(['ceph-common']), fatal=True)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ceph-relation-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def ceph_changed():
|
|
|
|
if 'ceph' not in CONFIGS.complete_contexts():
|
|
|
|
log('ceph relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
svc = service_name()
|
|
|
|
if not ensure_ceph_keyring(service=svc):
|
|
|
|
log('Could not create ceph keyring: peer not ready?')
|
|
|
|
return
|
2013-10-10 12:41:00 +01:00
|
|
|
CONFIGS.write(ceph_config_file())
|
2013-09-20 17:50:33 +01:00
|
|
|
CONFIGS.write(CEPH_SECRET)
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-07-30 20:39:44 -07:00
|
|
|
|
2013-09-03 17:16:15 -07:00
|
|
|
# With some refactoring, this can move into NovaComputeCephContext
|
|
|
|
# and allow easily extended to support other compute flavors.
|
|
|
|
if config('virt-type') in ['kvm', 'qemu', 'lxc']:
|
2013-09-20 17:50:33 +01:00
|
|
|
create_libvirt_secret(secret_file=CEPH_SECRET,
|
2013-09-03 17:16:15 -07:00
|
|
|
secret_uuid=CEPH_SECRET_UUID,
|
|
|
|
key=relation_get('key'))
|
|
|
|
|
2013-07-30 20:39:44 -07:00
|
|
|
|
2013-08-20 12:10:36 -07:00
|
|
|
@hooks.hook('amqp-relation-broken',
|
|
|
|
'ceph-relation-broken',
|
|
|
|
'image-service-relation-broken',
|
2014-03-25 10:12:03 +01:00
|
|
|
'shared-db-relation-broken',
|
|
|
|
'pgsql-db-relation-broken')
|
2013-08-20 12:10:36 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def relation_broken():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
|
2013-10-17 20:25:15 +01:00
|
|
|
@hooks.hook('upgrade-charm')
|
|
|
|
def upgrade_charm():
|
|
|
|
for r_id in relation_ids('amqp'):
|
|
|
|
amqp_joined(relation_id=r_id)
|
|
|
|
|
|
|
|
|
2013-11-29 15:35:28 +00:00
|
|
|
@hooks.hook('nova-ceilometer-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def nova_ceilometer_relation_changed():
|
2013-11-29 15:57:59 +00:00
|
|
|
CONFIGS.write_all()
|
2013-11-29 15:35:28 +00:00
|
|
|
|
|
|
|
|
2014-09-09 09:47:14 +00:00
|
|
|
@hooks.hook('zeromq-configuration-relation-joined')
|
|
|
|
def zeromq_configuration_relation_joined(relid=None):
|
|
|
|
if services:
|
|
|
|
relation_set(relation_id=relid,
|
|
|
|
topics=" ".join(services()),
|
|
|
|
users="nova")
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('zeromq-configuration-relation-changed')
|
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
|
|
|
def zeromq_configuration_relation_changed():
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
|
|
|
|
2013-07-30 20:39:44 -07:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
|
|
|
log('Unknown hook {} - skipping.'.format(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|