2011-12-08 09:52:12 -08:00
|
|
|
#!/usr/bin/python
|
2014-12-12 18:32:45 +00:00
|
|
|
import hashlib
|
2015-01-21 16:23:15 +00:00
|
|
|
import json
|
2014-02-25 12:34:13 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from subprocess import check_call
|
|
|
|
|
|
|
|
from charmhelpers.contrib import unison
|
|
|
|
|
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks,
|
|
|
|
UnregisteredHookError,
|
|
|
|
config,
|
2014-03-31 10:35:19 +02:00
|
|
|
is_relation_made,
|
2014-02-25 12:34:13 +01:00
|
|
|
log,
|
2014-08-28 06:54:27 +00:00
|
|
|
local_unit,
|
2015-01-10 14:56:22 +00:00
|
|
|
DEBUG,
|
2015-02-05 17:48:25 +00:00
|
|
|
INFO,
|
2015-01-05 17:49:38 +00:00
|
|
|
WARNING,
|
2014-03-31 10:35:19 +02:00
|
|
|
ERROR,
|
2014-02-25 12:34:13 +01:00
|
|
|
relation_get,
|
|
|
|
relation_ids,
|
|
|
|
relation_set,
|
2014-03-27 22:00:08 +00:00
|
|
|
related_units,
|
2014-02-25 12:34:13 +01:00
|
|
|
unit_get,
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set,
|
2014-02-25 12:34:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.core.host import (
|
|
|
|
mkdir,
|
|
|
|
)
|
|
|
|
|
2015-02-16 11:25:45 +00:00
|
|
|
from charmhelpers.core.strutils import (
|
|
|
|
bool_from_string,
|
|
|
|
)
|
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
from charmhelpers.fetch import (
|
2014-02-26 16:54:26 +00:00
|
|
|
apt_install, apt_update,
|
|
|
|
filter_installed_packages
|
2014-02-25 12:34:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
2015-03-18 15:23:03 +00:00
|
|
|
config_value_changed,
|
2014-02-25 12:34:13 +01:00
|
|
|
configure_installation_source,
|
2014-12-03 16:23:02 +00:00
|
|
|
git_install_requested,
|
2014-02-25 12:34:13 +01:00
|
|
|
openstack_upgrade_available,
|
2015-09-25 11:59:06 -07:00
|
|
|
sync_db_with_multi_ipv6_addresses,
|
2016-03-07 09:10:53 +00:00
|
|
|
os_release,
|
2016-03-02 11:04:09 +00:00
|
|
|
pausable_restart_on_change as restart_on_change,
|
2014-02-25 12:34:13 +01:00
|
|
|
)
|
2012-10-02 17:36:25 -07:00
|
|
|
|
2013-03-18 12:56:57 +00:00
|
|
|
from keystone_utils import (
|
2014-02-25 12:34:13 +01:00
|
|
|
add_service_to_keystone,
|
|
|
|
determine_packages,
|
2015-10-19 12:22:10 +00:00
|
|
|
do_openstack_upgrade_reexec,
|
2013-03-18 12:56:57 +00:00
|
|
|
ensure_initial_admin,
|
2014-10-24 08:51:39 +00:00
|
|
|
get_admin_passwd,
|
2014-12-03 16:23:02 +00:00
|
|
|
git_install,
|
2014-02-25 12:34:13 +01:00
|
|
|
migrate_database,
|
|
|
|
save_script_rc,
|
2015-01-10 14:56:22 +00:00
|
|
|
synchronize_ca_if_changed,
|
2014-02-25 12:34:13 +01:00
|
|
|
register_configs,
|
|
|
|
restart_map,
|
2014-11-17 13:39:29 +10:00
|
|
|
services,
|
2013-03-19 13:41:27 +00:00
|
|
|
CLUSTER_RES,
|
2014-02-25 12:34:13 +01:00
|
|
|
KEYSTONE_CONF,
|
2016-03-07 09:10:53 +00:00
|
|
|
POLICY_JSON,
|
2016-03-06 12:19:47 -07:00
|
|
|
TOKEN_FLUSH_CRON_FILE,
|
2014-02-25 12:34:13 +01:00
|
|
|
SSH_USER,
|
2014-12-12 15:21:32 +00:00
|
|
|
setup_ipv6,
|
2014-12-16 23:48:42 +00:00
|
|
|
send_notifications,
|
2015-01-05 17:49:38 +00:00
|
|
|
check_peer_actions,
|
2015-01-16 14:02:29 +00:00
|
|
|
get_ssl_sync_request_units,
|
2015-01-21 16:23:15 +00:00
|
|
|
is_ssl_cert_master,
|
2015-01-22 18:44:33 +00:00
|
|
|
is_db_ready,
|
2015-02-03 12:56:40 +00:00
|
|
|
clear_ssl_synced_units,
|
2015-02-16 23:56:01 +00:00
|
|
|
is_db_initialised,
|
2015-03-12 09:21:51 +00:00
|
|
|
update_certs_if_available,
|
2015-02-19 23:42:38 +00:00
|
|
|
ensure_ssl_dir,
|
|
|
|
ensure_pki_dir_permissions,
|
2015-07-21 14:44:57 +01:00
|
|
|
ensure_permissions,
|
2015-02-20 12:20:16 +00:00
|
|
|
force_ssl_sync,
|
2015-03-10 12:02:11 +00:00
|
|
|
filter_null,
|
2015-03-12 09:21:51 +00:00
|
|
|
ensure_ssl_dirs,
|
2015-12-07 15:04:38 +01:00
|
|
|
ensure_pki_cert_paths,
|
2016-01-12 11:09:46 +00:00
|
|
|
is_service_present,
|
|
|
|
delete_service_entry,
|
2016-01-14 11:31:23 +00:00
|
|
|
assess_status,
|
2014-02-25 12:34:13 +01:00
|
|
|
)
|
2011-12-08 09:52:12 -08:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
from charmhelpers.contrib.hahelpers.cluster import (
|
2015-01-05 17:49:38 +00:00
|
|
|
is_elected_leader,
|
2014-07-16 14:33:47 +01:00
|
|
|
get_hacluster_config,
|
2015-01-10 14:56:22 +00:00
|
|
|
peer_units,
|
2014-02-25 12:34:13 +01:00
|
|
|
)
|
2013-11-12 16:28:10 +00:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
from charmhelpers.payload.execd import execd_preinstall
|
2014-08-19 12:39:31 +00:00
|
|
|
from charmhelpers.contrib.peerstorage import (
|
|
|
|
peer_retrieve_by_prefix,
|
|
|
|
peer_echo,
|
|
|
|
)
|
2014-10-24 12:52:11 +00:00
|
|
|
from charmhelpers.contrib.openstack.ip import (
|
|
|
|
ADMIN,
|
|
|
|
resolve_address,
|
|
|
|
)
|
2014-07-15 16:55:39 +01:00
|
|
|
from charmhelpers.contrib.network.ip import (
|
|
|
|
get_iface_for_address,
|
2014-09-26 12:00:16 +01:00
|
|
|
get_netmask_for_address,
|
2014-09-30 15:28:37 +08:00
|
|
|
get_address_in_network,
|
2014-09-30 15:52:03 +08:00
|
|
|
get_ipv6_addr,
|
2014-10-24 12:52:11 +00:00
|
|
|
is_ipv6,
|
2014-07-15 16:55:39 +01:00
|
|
|
)
|
2014-09-29 10:36:30 +01:00
|
|
|
from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
|
2011-12-08 09:52:12 -08:00
|
|
|
|
2015-01-12 12:04:00 +00:00
|
|
|
from charmhelpers.contrib.charmsupport import nrpe
|
2014-10-29 22:30:35 -05:00
|
|
|
|
2016-03-10 22:26:58 -07:00
|
|
|
from charmhelpers.contrib.hardening.harden import harden
|
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
hooks = Hooks()
|
|
|
|
CONFIGS = register_configs()
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2014-02-26 16:54:26 +00:00
|
|
|
|
2015-09-22 14:46:01 +01:00
|
|
|
@hooks.hook('install.real')
|
2016-03-10 22:26:58 -07:00
|
|
|
@harden()
|
2014-02-25 12:34:13 +01:00
|
|
|
def install():
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set('maintenance', 'Executing pre-install')
|
2013-11-12 16:28:10 +00:00
|
|
|
execd_preinstall()
|
2014-02-25 12:34:13 +01:00
|
|
|
configure_installation_source(config('openstack-origin'))
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set('maintenance', 'Installing apt packages')
|
2014-02-25 12:34:13 +01:00
|
|
|
apt_update()
|
|
|
|
apt_install(determine_packages(), fatal=True)
|
|
|
|
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set('maintenance', 'Git install')
|
2014-12-03 16:23:02 +00:00
|
|
|
git_install(config('openstack-origin-git'))
|
2014-02-25 12:34:13 +01:00
|
|
|
|
2015-10-19 20:52:06 +00:00
|
|
|
unison.ensure_user(user=SSH_USER, group='juju_keystone')
|
|
|
|
unison.ensure_user(user=SSH_USER, group='keystone')
|
|
|
|
|
2014-02-26 16:54:26 +00:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('config-changed')
|
2014-02-26 17:05:40 +00:00
|
|
|
@restart_on_change(restart_map())
|
2015-02-18 17:20:23 +00:00
|
|
|
@synchronize_ca_if_changed(fatal=True)
|
2016-03-10 22:26:58 -07:00
|
|
|
@harden()
|
2014-02-25 12:34:13 +01:00
|
|
|
def config_changed():
|
2014-09-18 19:27:07 +08:00
|
|
|
if config('prefer-ipv6'):
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set('maintenance', 'configuring ipv6')
|
2014-09-18 19:27:07 +08:00
|
|
|
setup_ipv6()
|
2014-09-26 20:15:39 +01:00
|
|
|
sync_db_with_multi_ipv6_addresses(config('database'),
|
|
|
|
config('database-user'))
|
2014-09-18 19:56:23 +08:00
|
|
|
|
2015-01-10 14:56:22 +00:00
|
|
|
unison.ensure_user(user=SSH_USER, group='juju_keystone')
|
2014-02-26 16:54:26 +00:00
|
|
|
unison.ensure_user(user=SSH_USER, group='keystone')
|
2014-02-25 12:34:13 +01:00
|
|
|
homedir = unison.get_homedir(SSH_USER)
|
|
|
|
if not os.path.isdir(homedir):
|
2015-01-27 22:21:37 +00:00
|
|
|
mkdir(homedir, SSH_USER, 'juju_keystone', 0o775)
|
2014-02-26 16:54:26 +00:00
|
|
|
|
2015-03-18 15:23:03 +00:00
|
|
|
if git_install_requested():
|
|
|
|
if config_value_changed('openstack-origin-git'):
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set('maintenance', 'Running Git install')
|
2015-03-18 15:23:03 +00:00
|
|
|
git_install(config('openstack-origin-git'))
|
2015-10-07 12:20:36 -04:00
|
|
|
elif not config('action-managed-upgrade'):
|
2014-12-03 16:23:02 +00:00
|
|
|
if openstack_upgrade_available('keystone'):
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set('maintenance', 'Running openstack upgrade')
|
2015-10-19 12:22:10 +00:00
|
|
|
do_openstack_upgrade_reexec(configs=CONFIGS)
|
2014-02-26 16:54:26 +00:00
|
|
|
|
2015-10-19 08:16:38 +00:00
|
|
|
config_changed_postupgrade()
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('config-changed-postupgrade')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
@synchronize_ca_if_changed(fatal=True)
|
2016-03-10 22:26:58 -07:00
|
|
|
@harden()
|
2015-10-19 08:16:38 +00:00
|
|
|
def config_changed_postupgrade():
|
2015-02-19 23:42:38 +00:00
|
|
|
# Ensure ssl dir exists and is unison-accessible
|
|
|
|
ensure_ssl_dir()
|
|
|
|
|
2014-02-26 16:54:26 +00:00
|
|
|
check_call(['chmod', '-R', 'g+wrx', '/var/lib/keystone/'])
|
|
|
|
|
2015-03-12 09:21:51 +00:00
|
|
|
ensure_ssl_dirs()
|
2015-01-05 17:49:38 +00:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
save_script_rc()
|
|
|
|
configure_https()
|
2015-02-18 17:20:23 +00:00
|
|
|
|
2014-10-29 22:30:35 -05:00
|
|
|
update_nrpe_config()
|
2014-02-25 12:34:13 +01:00
|
|
|
CONFIGS.write_all()
|
2015-01-05 17:49:38 +00:00
|
|
|
|
2015-12-07 15:04:38 +01:00
|
|
|
initialise_pki()
|
2015-02-18 17:20:23 +00:00
|
|
|
|
2015-07-09 12:59:30 +01:00
|
|
|
update_all_identity_relation_units()
|
2011-12-08 09:52:12 -08:00
|
|
|
|
2015-01-14 11:04:13 +00:00
|
|
|
for rid in relation_ids('identity-admin'):
|
|
|
|
admin_relation_changed(rid)
|
2014-09-26 12:00:16 +01:00
|
|
|
|
2015-03-10 12:02:11 +00:00
|
|
|
# Ensure sync request is sent out (needed for any/all ssl change)
|
2015-02-03 12:56:40 +00:00
|
|
|
send_ssl_sync_request()
|
|
|
|
|
2015-01-22 16:19:44 +00:00
|
|
|
for r_id in relation_ids('ha'):
|
|
|
|
ha_joined(relation_id=r_id)
|
2014-09-26 12:00:16 +01:00
|
|
|
|
2013-01-30 16:48:51 -08:00
|
|
|
|
2015-02-18 17:20:23 +00:00
|
|
|
@synchronize_ca_if_changed(fatal=True)
|
|
|
|
def initialise_pki():
|
2015-12-07 15:04:38 +01:00
|
|
|
"""Create certs and keys required for token signing.
|
|
|
|
|
|
|
|
Used for PKI and signing token revocation list.
|
2015-02-18 17:20:23 +00:00
|
|
|
|
|
|
|
NOTE: keystone.conf [signing] section must be up-to-date prior to
|
|
|
|
executing this.
|
|
|
|
"""
|
2015-12-07 15:04:38 +01:00
|
|
|
ensure_pki_cert_paths()
|
2015-07-21 14:44:57 +01:00
|
|
|
if not peer_units() or is_ssl_cert_master():
|
2015-02-18 17:20:23 +00:00
|
|
|
log("Ensuring PKI token certs created", level=DEBUG)
|
|
|
|
cmd = ['keystone-manage', 'pki_setup', '--keystone-user', 'keystone',
|
|
|
|
'--keystone-group', 'keystone']
|
|
|
|
check_call(cmd)
|
|
|
|
|
2015-07-21 14:44:57 +01:00
|
|
|
# Ensure logfile has keystone perms since we may have just created it
|
|
|
|
# with root.
|
|
|
|
ensure_permissions('/var/log/keystone', user='keystone',
|
|
|
|
group='keystone', perms=0o744)
|
|
|
|
ensure_permissions('/var/log/keystone/keystone.log', user='keystone',
|
|
|
|
group='keystone', perms=0o644)
|
|
|
|
|
2015-02-19 23:42:38 +00:00
|
|
|
ensure_pki_dir_permissions()
|
2015-02-18 17:20:23 +00:00
|
|
|
|
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('shared-db-relation-joined')
|
2011-12-08 09:52:12 -08:00
|
|
|
def db_joined():
|
2014-03-31 10:35:19 +02:00
|
|
|
if is_relation_made('pgsql-db'):
|
|
|
|
# error, postgresql is used
|
|
|
|
e = ('Attempting to associate a mysql database when there is already '
|
|
|
|
'associated a postgresql one')
|
|
|
|
log(e, level=ERROR)
|
|
|
|
raise Exception(e)
|
|
|
|
|
2014-08-04 21:47:53 +08:00
|
|
|
if config('prefer-ipv6'):
|
2014-09-26 20:15:39 +01:00
|
|
|
sync_db_with_multi_ipv6_addresses(config('database'),
|
|
|
|
config('database-user'))
|
2014-08-04 21:47:53 +08:00
|
|
|
else:
|
2014-09-26 15:24:59 +01:00
|
|
|
relation_set(database=config('database'),
|
|
|
|
username=config('database-user'),
|
|
|
|
hostname=unit_get('private-address'))
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2011-12-08 09:52:12 -08:00
|
|
|
|
2014-03-31 10:35:19 +02:00
|
|
|
@hooks.hook('pgsql-db-relation-joined')
|
|
|
|
def pgsql_db_joined():
|
|
|
|
if is_relation_made('shared-db'):
|
|
|
|
# raise error
|
2014-04-10 17:00:28 +01:00
|
|
|
e = ('Attempting to associate a postgresql database when there'
|
|
|
|
' is already associated a mysql one')
|
2014-03-31 10:35:19 +02:00
|
|
|
log(e, level=ERROR)
|
|
|
|
raise Exception(e)
|
|
|
|
|
|
|
|
relation_set(database=config('database'))
|
|
|
|
|
|
|
|
|
2015-02-06 12:05:52 +00:00
|
|
|
def update_all_identity_relation_units(check_db_ready=True):
|
2015-01-13 16:01:25 +00:00
|
|
|
CONFIGS.write_all()
|
2015-02-06 12:05:52 +00:00
|
|
|
if check_db_ready and not is_db_ready():
|
2015-02-05 17:48:25 +00:00
|
|
|
log('Allowed_units list provided and this unit not present',
|
|
|
|
level=INFO)
|
|
|
|
return
|
|
|
|
|
2015-02-16 23:56:01 +00:00
|
|
|
if not is_db_initialised():
|
|
|
|
log("Database not yet initialised - deferring identity-relation "
|
|
|
|
"updates", level=INFO)
|
|
|
|
return
|
|
|
|
|
|
|
|
if is_elected_leader(CLUSTER_RES):
|
2015-01-10 14:56:22 +00:00
|
|
|
ensure_initial_admin(config)
|
2015-02-16 23:56:01 +00:00
|
|
|
|
2015-02-16 20:58:06 +00:00
|
|
|
log('Firing identity_changed hook for all related services.')
|
|
|
|
for rid in relation_ids('identity-service'):
|
2015-07-22 10:17:13 +01:00
|
|
|
for unit in related_units(rid):
|
|
|
|
identity_changed(relation_id=rid, remote_unit=unit)
|
2015-01-10 14:56:22 +00:00
|
|
|
|
|
|
|
|
2015-01-13 16:01:25 +00:00
|
|
|
@synchronize_ca_if_changed(force=True)
|
|
|
|
def update_all_identity_relation_units_force_sync():
|
|
|
|
update_all_identity_relation_units()
|
|
|
|
|
|
|
|
|
2016-01-07 12:32:30 +00:00
|
|
|
def leader_init_db_if_ready(use_current_context=False):
|
|
|
|
""" Initialise the keystone db if it is ready and mark it as initialised.
|
|
|
|
|
|
|
|
NOTE: this must be idempotent.
|
|
|
|
"""
|
|
|
|
if not is_elected_leader(CLUSTER_RES):
|
|
|
|
log("Not leader - skipping db init", level=DEBUG)
|
|
|
|
return
|
|
|
|
|
|
|
|
if is_db_initialised():
|
|
|
|
log("Database already initialised - skipping db init", level=DEBUG)
|
|
|
|
return
|
|
|
|
|
|
|
|
# Bugs 1353135 & 1187508. Dbs can appear to be ready before the
|
|
|
|
# units acl entry has been added. So, if the db supports passing
|
|
|
|
# a list of permitted units then check if we're in the list.
|
|
|
|
if not is_db_ready(use_current_context=use_current_context):
|
|
|
|
log('Allowed_units list provided and this unit not present',
|
|
|
|
level=INFO)
|
|
|
|
return
|
|
|
|
|
|
|
|
migrate_database()
|
|
|
|
# Ensure any existing service entries are updated in the
|
|
|
|
# new database backend. Also avoid duplicate db ready check.
|
|
|
|
update_all_identity_relation_units(check_db_ready=False)
|
|
|
|
|
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('shared-db-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
2015-01-10 14:56:22 +00:00
|
|
|
@synchronize_ca_if_changed()
|
2011-12-08 09:52:12 -08:00
|
|
|
def db_changed():
|
2014-02-25 12:34:13 +01:00
|
|
|
if 'shared-db' not in CONFIGS.complete_contexts():
|
|
|
|
log('shared-db relation incomplete. Peer not ready?')
|
2014-03-31 10:35:19 +02:00
|
|
|
else:
|
|
|
|
CONFIGS.write(KEYSTONE_CONF)
|
2016-01-07 12:32:30 +00:00
|
|
|
leader_init_db_if_ready(use_current_context=True)
|
2016-03-07 09:10:53 +00:00
|
|
|
if os_release('keystone-common') >= 'liberty':
|
|
|
|
CONFIGS.write(POLICY_JSON)
|
2014-03-31 10:35:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('pgsql-db-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
2015-01-10 14:56:22 +00:00
|
|
|
@synchronize_ca_if_changed()
|
2014-03-31 10:35:19 +02:00
|
|
|
def pgsql_db_changed():
|
|
|
|
if 'pgsql-db' not in CONFIGS.complete_contexts():
|
|
|
|
log('pgsql-db relation incomplete. Peer not ready?')
|
2014-02-26 16:54:26 +00:00
|
|
|
else:
|
|
|
|
CONFIGS.write(KEYSTONE_CONF)
|
2016-01-07 12:32:30 +00:00
|
|
|
leader_init_db_if_ready(use_current_context=True)
|
2016-03-07 09:10:53 +00:00
|
|
|
if os_release('keystone-common') >= 'liberty':
|
|
|
|
CONFIGS.write(POLICY_JSON)
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2013-02-07 21:03:44 -08:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('identity-service-relation-changed')
|
2015-02-06 11:52:49 +00:00
|
|
|
@restart_on_change(restart_map())
|
2015-01-10 14:56:22 +00:00
|
|
|
@synchronize_ca_if_changed()
|
2014-02-26 16:54:26 +00:00
|
|
|
def identity_changed(relation_id=None, remote_unit=None):
|
2015-01-13 11:04:56 +00:00
|
|
|
CONFIGS.write_all()
|
|
|
|
|
2014-12-12 15:21:32 +00:00
|
|
|
notifications = {}
|
2015-01-05 17:49:38 +00:00
|
|
|
if is_elected_leader(CLUSTER_RES):
|
2015-01-22 18:44:33 +00:00
|
|
|
if not is_db_ready():
|
|
|
|
log("identity-service-relation-changed hook fired before db "
|
|
|
|
"ready - deferring until db ready", level=WARNING)
|
|
|
|
return
|
2014-12-12 15:21:32 +00:00
|
|
|
|
2015-02-16 23:56:01 +00:00
|
|
|
if not is_db_initialised():
|
|
|
|
log("Database not yet initialised - deferring identity-relation "
|
|
|
|
"updates", level=INFO)
|
|
|
|
return
|
|
|
|
|
2015-01-22 18:44:33 +00:00
|
|
|
add_service_to_keystone(relation_id, remote_unit)
|
2016-01-12 11:09:46 +00:00
|
|
|
if is_service_present('neutron', 'network'):
|
|
|
|
delete_service_entry('quantum', 'network')
|
2014-12-12 20:21:44 +00:00
|
|
|
settings = relation_get(rid=relation_id, unit=remote_unit)
|
2014-12-16 23:20:46 +00:00
|
|
|
service = settings.get('service', None)
|
|
|
|
if service:
|
|
|
|
# If service is known and endpoint has changed, notify service if
|
|
|
|
# it is related with notifications interface.
|
|
|
|
csum = hashlib.sha256()
|
|
|
|
# We base the decision to notify on whether these parameters have
|
|
|
|
# changed (if csum is unchanged from previous notify, relation will
|
|
|
|
# not fire).
|
|
|
|
csum.update(settings.get('public_url', None))
|
|
|
|
csum.update(settings.get('admin_url', None))
|
|
|
|
csum.update(settings.get('internal_url', None))
|
|
|
|
notifications['%s-endpoint-changed' % (service)] = csum.hexdigest()
|
2014-02-26 16:54:26 +00:00
|
|
|
else:
|
2014-08-19 12:39:31 +00:00
|
|
|
# Each unit needs to set the db information otherwise if the unit
|
|
|
|
# with the info dies the settings die with it Bug# 1355848
|
|
|
|
for rel_id in relation_ids('identity-service'):
|
|
|
|
peerdb_settings = peer_retrieve_by_prefix(rel_id)
|
2015-03-10 12:02:11 +00:00
|
|
|
# Ensure the null'd settings are unset in the relation.
|
|
|
|
peerdb_settings = filter_null(peerdb_settings)
|
2014-08-19 12:39:31 +00:00
|
|
|
if 'service_password' in peerdb_settings:
|
|
|
|
relation_set(relation_id=rel_id, **peerdb_settings)
|
2015-02-20 13:34:29 +00:00
|
|
|
|
2014-02-26 16:54:26 +00:00
|
|
|
log('Deferring identity_changed() to service leader.')
|
2012-12-17 13:45:58 +00:00
|
|
|
|
2014-12-12 15:21:32 +00:00
|
|
|
if notifications:
|
2014-12-16 23:48:42 +00:00
|
|
|
send_notifications(notifications)
|
2014-12-12 15:21:32 +00:00
|
|
|
|
2012-12-17 13:45:58 +00:00
|
|
|
|
2015-02-03 12:56:40 +00:00
|
|
|
def send_ssl_sync_request():
|
|
|
|
"""Set sync request on cluster relation.
|
2015-01-21 16:23:15 +00:00
|
|
|
|
2015-02-03 12:56:40 +00:00
|
|
|
Value set equals number of ssl configs currently enabled so that if they
|
|
|
|
change, we ensure that certs are synced. This setting is consumed by
|
|
|
|
cluster-relation-changed ssl master. We also clear the 'synced' set to
|
|
|
|
guarantee that a sync will occur.
|
|
|
|
|
|
|
|
Note the we do nothing if the setting is already applied.
|
2015-01-21 16:23:15 +00:00
|
|
|
"""
|
2015-02-03 12:56:40 +00:00
|
|
|
unit = local_unit().replace('/', '-')
|
2015-12-07 15:04:38 +01:00
|
|
|
# Start with core config (e.g. used for signing revoked token list)
|
|
|
|
ssl_config = 0b1
|
2015-02-18 17:20:23 +00:00
|
|
|
|
|
|
|
use_https = config('use-https')
|
|
|
|
if use_https and bool_from_string(use_https):
|
2015-12-07 15:04:38 +01:00
|
|
|
ssl_config ^= 0b10
|
2015-02-03 12:56:40 +00:00
|
|
|
|
2015-02-18 17:20:23 +00:00
|
|
|
https_service_endpoints = config('https-service-endpoints')
|
|
|
|
if (https_service_endpoints and
|
|
|
|
bool_from_string(https_service_endpoints)):
|
2015-12-07 15:04:38 +01:00
|
|
|
ssl_config ^= 0b100
|
2015-02-03 12:56:40 +00:00
|
|
|
|
2015-02-18 17:20:23 +00:00
|
|
|
enable_pki = config('enable-pki')
|
|
|
|
if enable_pki and bool_from_string(enable_pki):
|
2015-12-07 15:04:38 +01:00
|
|
|
ssl_config ^= 0b1000
|
2015-02-18 17:20:23 +00:00
|
|
|
|
2015-03-10 12:02:11 +00:00
|
|
|
key = 'ssl-sync-required-%s' % (unit)
|
2015-12-07 15:04:38 +01:00
|
|
|
settings = {key: ssl_config}
|
2015-03-10 12:02:11 +00:00
|
|
|
|
2015-12-07 15:04:38 +01:00
|
|
|
prev = 0b0
|
2015-03-10 12:02:11 +00:00
|
|
|
rid = None
|
|
|
|
for rid in relation_ids('cluster'):
|
|
|
|
for unit in related_units(rid):
|
2015-12-07 15:04:38 +01:00
|
|
|
_prev = relation_get(rid=rid, unit=unit, attribute=key) or 0b0
|
2015-03-10 12:02:11 +00:00
|
|
|
if _prev and _prev > prev:
|
2015-12-07 15:04:38 +01:00
|
|
|
prev = bin(_prev)
|
2015-03-10 12:02:11 +00:00
|
|
|
|
2015-12-07 15:04:38 +01:00
|
|
|
if rid and prev ^ ssl_config:
|
2015-03-10 12:02:11 +00:00
|
|
|
clear_ssl_synced_units()
|
2015-12-07 15:04:38 +01:00
|
|
|
log("Setting %s=%s" % (key, bin(ssl_config)), level=DEBUG)
|
2015-03-10 12:02:11 +00:00
|
|
|
relation_set(relation_id=rid, relation_settings=settings)
|
|
|
|
|
2015-01-21 16:23:15 +00:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('cluster-relation-joined')
|
2015-01-13 16:01:25 +00:00
|
|
|
def cluster_joined():
|
2013-02-12 21:56:39 -08:00
|
|
|
unison.ssh_authorized_peers(user=SSH_USER,
|
2014-02-25 12:34:13 +01:00
|
|
|
group='juju_keystone',
|
2013-02-12 21:56:39 -08:00
|
|
|
peer_interface='cluster',
|
2013-04-09 13:16:44 +01:00
|
|
|
ensure_local_user=True)
|
2015-01-13 16:01:25 +00:00
|
|
|
|
|
|
|
settings = {}
|
|
|
|
|
2014-09-29 10:36:30 +01:00
|
|
|
for addr_type in ADDRESS_TYPES:
|
|
|
|
address = get_address_in_network(
|
|
|
|
config('os-{}-network'.format(addr_type))
|
|
|
|
)
|
|
|
|
if address:
|
2015-01-13 16:01:25 +00:00
|
|
|
settings['{}-address'.format(addr_type)] = address
|
2013-03-18 12:56:57 +00:00
|
|
|
|
2014-08-04 21:47:53 +08:00
|
|
|
if config('prefer-ipv6'):
|
2014-09-30 15:28:37 +08:00
|
|
|
private_addr = get_ipv6_addr(exc_list=[config('vip')])[0]
|
2015-01-13 16:01:25 +00:00
|
|
|
settings['private-address'] = private_addr
|
2012-12-17 13:45:58 +00:00
|
|
|
|
2015-01-13 16:01:25 +00:00
|
|
|
relation_set(relation_settings=settings)
|
2015-02-03 12:56:40 +00:00
|
|
|
send_ssl_sync_request()
|
2012-12-17 13:45:58 +00:00
|
|
|
|
2015-01-10 14:56:22 +00:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('cluster-relation-changed',
|
|
|
|
'cluster-relation-departed')
|
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
2015-03-12 09:21:51 +00:00
|
|
|
@update_certs_if_available
|
2012-12-17 13:45:58 +00:00
|
|
|
def cluster_changed():
|
2015-01-27 22:21:37 +00:00
|
|
|
unison.ssh_authorized_peers(user=SSH_USER,
|
|
|
|
group='juju_keystone',
|
|
|
|
peer_interface='cluster',
|
|
|
|
ensure_local_user=True)
|
2014-03-28 11:04:08 +00:00
|
|
|
# NOTE(jamespage) re-echo passwords for peer storage
|
2015-03-10 12:02:11 +00:00
|
|
|
echo_whitelist = ['_passwd', 'identity-service:', 'ssl-cert-master',
|
2015-03-12 09:21:51 +00:00
|
|
|
'db-initialised', 'ssl-cert-available-updates']
|
2015-03-10 12:02:11 +00:00
|
|
|
log("Peer echo whitelist: %s" % (echo_whitelist), level=DEBUG)
|
2015-03-12 09:21:51 +00:00
|
|
|
peer_echo(includes=echo_whitelist, force=True)
|
2015-01-13 22:16:46 +00:00
|
|
|
|
|
|
|
check_peer_actions()
|
2015-01-05 21:57:25 +00:00
|
|
|
|
2015-12-07 15:04:38 +01:00
|
|
|
initialise_pki()
|
2015-03-11 14:46:42 +00:00
|
|
|
|
|
|
|
# Figure out if we need to mandate a sync
|
2015-02-20 13:34:29 +00:00
|
|
|
units = get_ssl_sync_request_units()
|
|
|
|
synced_units = relation_get(attribute='ssl-synced-units',
|
|
|
|
unit=local_unit())
|
2015-03-11 14:46:42 +00:00
|
|
|
diff = None
|
2015-02-20 13:34:29 +00:00
|
|
|
if synced_units:
|
|
|
|
synced_units = json.loads(synced_units)
|
|
|
|
diff = set(units).symmetric_difference(set(synced_units))
|
|
|
|
|
|
|
|
if units and (not synced_units or diff):
|
|
|
|
log("New peers joined and need syncing - %s" %
|
|
|
|
(', '.join(units)), level=DEBUG)
|
|
|
|
update_all_identity_relation_units_force_sync()
|
|
|
|
else:
|
|
|
|
update_all_identity_relation_units()
|
|
|
|
|
|
|
|
for rid in relation_ids('identity-admin'):
|
|
|
|
admin_relation_changed(rid)
|
2015-01-16 14:50:19 +00:00
|
|
|
|
2015-02-20 13:34:29 +00:00
|
|
|
if not is_elected_leader(CLUSTER_RES) and is_ssl_cert_master():
|
2015-03-11 14:46:42 +00:00
|
|
|
# Force and sync and trigger a sync master re-election since we are not
|
|
|
|
# leader anymore.
|
2015-02-20 12:20:16 +00:00
|
|
|
force_ssl_sync()
|
2015-01-10 14:56:22 +00:00
|
|
|
else:
|
2015-01-13 16:01:25 +00:00
|
|
|
CONFIGS.write_all()
|
2014-02-25 12:34:13 +01:00
|
|
|
|
|
|
|
|
2016-03-06 12:19:47 -07:00
|
|
|
@hooks.hook('leader-elected')
|
|
|
|
def leader_elected():
|
|
|
|
log('Unit has been elected leader.', level=DEBUG)
|
|
|
|
# When the local unit has been elected the leader, update the cron jobs
|
|
|
|
# to ensure that the cron jobs are active on this unit.
|
|
|
|
CONFIGS.write(TOKEN_FLUSH_CRON_FILE)
|
|
|
|
|
|
|
|
|
2015-03-13 14:56:44 +00:00
|
|
|
@hooks.hook('leader-settings-changed')
|
|
|
|
def leader_settings_changed():
|
2016-03-06 12:19:47 -07:00
|
|
|
# Since minions are notified of a regime change via the
|
|
|
|
# leader-settings-changed hook, rewrite the token flush cron job to make
|
|
|
|
# sure only the leader is running the cron job.
|
|
|
|
CONFIGS.write(TOKEN_FLUSH_CRON_FILE)
|
|
|
|
|
2015-03-13 14:56:44 +00:00
|
|
|
log('Firing identity_changed hook for all related services.')
|
|
|
|
for rid in relation_ids('identity-service'):
|
2016-03-06 12:19:47 -07:00
|
|
|
for unit in related_units(rid):
|
|
|
|
identity_changed(relation_id=rid, remote_unit=unit)
|
2015-03-13 14:56:44 +00:00
|
|
|
|
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('ha-relation-joined')
|
2015-01-22 16:09:29 +00:00
|
|
|
def ha_joined(relation_id=None):
|
2014-08-04 21:47:53 +08:00
|
|
|
cluster_config = get_hacluster_config()
|
2012-12-17 13:45:58 +00:00
|
|
|
resources = {
|
2014-02-25 12:34:13 +01:00
|
|
|
'res_ks_haproxy': 'lsb:haproxy',
|
|
|
|
}
|
2012-12-17 13:45:58 +00:00
|
|
|
resource_params = {
|
2013-03-18 12:56:57 +00:00
|
|
|
'res_ks_haproxy': 'op monitor interval="5s"'
|
2014-02-25 12:34:13 +01:00
|
|
|
}
|
2014-07-15 16:55:39 +01:00
|
|
|
|
|
|
|
vip_group = []
|
2014-08-08 17:27:31 +08:00
|
|
|
for vip in cluster_config['vip'].split():
|
2014-09-30 15:52:03 +08:00
|
|
|
if is_ipv6(vip):
|
2014-09-30 15:28:37 +08:00
|
|
|
res_ks_vip = 'ocf:heartbeat:IPv6addr'
|
|
|
|
vip_params = 'ipv6addr'
|
|
|
|
else:
|
|
|
|
res_ks_vip = 'ocf:heartbeat:IPaddr2'
|
|
|
|
vip_params = 'ip'
|
|
|
|
|
2014-11-12 09:27:15 +00:00
|
|
|
iface = (get_iface_for_address(vip) or
|
|
|
|
config('vip_iface'))
|
|
|
|
netmask = (get_netmask_for_address(vip) or
|
|
|
|
config('vip_cidr'))
|
|
|
|
|
2014-07-15 16:55:39 +01:00
|
|
|
if iface is not None:
|
|
|
|
vip_key = 'res_ks_{}_vip'.format(iface)
|
2015-09-16 03:22:34 +02:00
|
|
|
if vip_key in vip_group:
|
|
|
|
log("Resource '%s' (vip='%s') already exists in "
|
|
|
|
"vip group - skipping" % (vip_key, vip),
|
|
|
|
WARNING)
|
|
|
|
continue
|
|
|
|
|
|
|
|
vip_group.append(vip_key)
|
2014-08-04 21:47:53 +08:00
|
|
|
resources[vip_key] = res_ks_vip
|
2014-07-15 16:55:39 +01:00
|
|
|
resource_params[vip_key] = (
|
2014-08-04 21:47:53 +08:00
|
|
|
'params {ip}="{vip}" cidr_netmask="{netmask}"'
|
|
|
|
' nic="{iface}"'.format(ip=vip_params,
|
|
|
|
vip=vip,
|
2014-07-15 16:55:39 +01:00
|
|
|
iface=iface,
|
2014-11-12 09:27:15 +00:00
|
|
|
netmask=netmask)
|
2014-07-15 16:55:39 +01:00
|
|
|
)
|
|
|
|
|
2014-09-04 10:19:33 +01:00
|
|
|
if len(vip_group) >= 1:
|
2015-01-22 16:09:29 +00:00
|
|
|
relation_set(relation_id=relation_id,
|
2015-01-22 16:37:17 +00:00
|
|
|
groups={CLUSTER_RES: ' '.join(vip_group)})
|
2014-07-15 16:57:34 +01:00
|
|
|
|
2012-12-17 13:45:58 +00:00
|
|
|
init_services = {
|
2013-03-18 12:56:57 +00:00
|
|
|
'res_ks_haproxy': 'haproxy'
|
2014-02-25 12:34:13 +01:00
|
|
|
}
|
2013-03-18 12:56:57 +00:00
|
|
|
clones = {
|
2013-03-18 15:49:00 +00:00
|
|
|
'cl_ks_haproxy': 'res_ks_haproxy'
|
2014-02-25 12:34:13 +01:00
|
|
|
}
|
2015-01-22 16:09:29 +00:00
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
init_services=init_services,
|
2014-08-04 21:47:53 +08:00
|
|
|
corosync_bindiface=cluster_config['ha-bindiface'],
|
|
|
|
corosync_mcastport=cluster_config['ha-mcastport'],
|
2014-02-25 12:34:13 +01:00
|
|
|
resources=resources,
|
|
|
|
resource_params=resource_params,
|
|
|
|
clones=clones)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ha-relation-changed')
|
2015-09-29 08:20:23 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
@synchronize_ca_if_changed()
|
2014-02-25 12:34:13 +01:00
|
|
|
def ha_changed():
|
2014-03-03 09:13:00 +00:00
|
|
|
CONFIGS.write_all()
|
2015-01-13 11:04:56 +00:00
|
|
|
|
|
|
|
clustered = relation_get('clustered')
|
2015-01-10 14:56:22 +00:00
|
|
|
if clustered and is_elected_leader(CLUSTER_RES):
|
2014-02-26 16:54:26 +00:00
|
|
|
log('Cluster configured, notifying other services and updating '
|
|
|
|
'keystone endpoint configuration')
|
2015-01-10 14:56:22 +00:00
|
|
|
update_all_identity_relation_units()
|
2014-02-25 12:34:13 +01:00
|
|
|
|
|
|
|
|
2014-05-06 14:13:30 +01:00
|
|
|
@hooks.hook('identity-admin-relation-changed')
|
2014-10-24 08:51:39 +00:00
|
|
|
def admin_relation_changed(relation_id=None):
|
2014-09-26 11:20:38 +01:00
|
|
|
# TODO: fixup
|
2014-03-25 17:20:13 +11:00
|
|
|
relation_data = {
|
2014-10-24 12:52:11 +00:00
|
|
|
'service_hostname': resolve_address(ADMIN),
|
2014-05-06 14:13:30 +01:00
|
|
|
'service_port': config('service-port'),
|
|
|
|
'service_username': config('admin-user'),
|
|
|
|
'service_tenant_name': config('admin-role'),
|
|
|
|
'service_region': config('region'),
|
2014-03-25 17:20:13 +11:00
|
|
|
}
|
2014-10-24 08:51:39 +00:00
|
|
|
relation_data['service_password'] = get_admin_passwd()
|
|
|
|
relation_set(relation_id=relation_id, **relation_data)
|
2014-05-06 14:13:30 +01:00
|
|
|
|
|
|
|
|
2015-01-12 17:02:08 +00:00
|
|
|
@synchronize_ca_if_changed(fatal=True)
|
2014-02-25 12:34:13 +01:00
|
|
|
def configure_https():
|
|
|
|
'''
|
|
|
|
Enables SSL API Apache config if appropriate and kicks identity-service
|
|
|
|
with any required api updates.
|
|
|
|
'''
|
|
|
|
# need to write all to ensure changes to the entire request pipeline
|
|
|
|
# propagate (c-api, haprxy, apache)
|
|
|
|
CONFIGS.write_all()
|
|
|
|
if 'https' in CONFIGS.complete_contexts():
|
|
|
|
cmd = ['a2ensite', 'openstack_https_frontend']
|
|
|
|
check_call(cmd)
|
|
|
|
else:
|
|
|
|
cmd = ['a2dissite', 'openstack_https_frontend']
|
|
|
|
check_call(cmd)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('upgrade-charm')
|
2014-02-26 16:54:26 +00:00
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
2015-01-10 14:56:22 +00:00
|
|
|
@synchronize_ca_if_changed()
|
2016-03-10 22:26:58 -07:00
|
|
|
@harden()
|
2014-02-25 12:34:13 +01:00
|
|
|
def upgrade_charm():
|
2015-09-25 11:59:06 -07:00
|
|
|
status_set('maintenance', 'Installing apt packages')
|
2014-02-26 16:54:26 +00:00
|
|
|
apt_install(filter_installed_packages(determine_packages()))
|
2014-03-28 10:43:32 +00:00
|
|
|
unison.ssh_authorized_peers(user=SSH_USER,
|
2015-01-27 22:21:37 +00:00
|
|
|
group='juju_keystone',
|
2014-03-28 10:43:32 +00:00
|
|
|
peer_interface='cluster',
|
|
|
|
ensure_local_user=True)
|
2015-01-13 11:04:56 +00:00
|
|
|
|
2015-03-12 09:21:51 +00:00
|
|
|
ensure_ssl_dirs()
|
|
|
|
|
2015-01-13 11:04:56 +00:00
|
|
|
CONFIGS.write_all()
|
2016-01-07 12:32:30 +00:00
|
|
|
|
|
|
|
# See LP bug 1519035
|
|
|
|
leader_init_db_if_ready()
|
|
|
|
|
2014-10-29 22:30:35 -05:00
|
|
|
update_nrpe_config()
|
2015-01-13 11:04:56 +00:00
|
|
|
|
2015-01-05 17:49:38 +00:00
|
|
|
if is_elected_leader(CLUSTER_RES):
|
2015-01-10 14:56:22 +00:00
|
|
|
log('Cluster leader - ensuring endpoint configuration is up to '
|
|
|
|
'date', level=DEBUG)
|
|
|
|
update_all_identity_relation_units()
|
2014-02-25 12:34:13 +01:00
|
|
|
|
|
|
|
|
2016-03-10 22:26:58 -07:00
|
|
|
@hooks.hook('update-status')
|
|
|
|
@harden()
|
|
|
|
def update_status():
|
|
|
|
log('Updating status.')
|
|
|
|
|
|
|
|
|
2014-11-17 13:39:29 +10:00
|
|
|
@hooks.hook('nrpe-external-master-relation-joined',
|
|
|
|
'nrpe-external-master-relation-changed')
|
2014-10-29 22:30:35 -05:00
|
|
|
def update_nrpe_config():
|
2015-01-12 12:04:00 +00:00
|
|
|
# python-dbus is used by check_upstart_job
|
2014-10-29 22:30:35 -05:00
|
|
|
apt_install('python-dbus')
|
2015-01-12 12:04:00 +00:00
|
|
|
hostname = nrpe.get_nagios_hostname()
|
|
|
|
current_unit = nrpe.get_nagios_unit_name()
|
|
|
|
nrpe_setup = nrpe.NRPE(hostname=hostname)
|
2015-02-19 14:17:25 +10:00
|
|
|
nrpe.copy_nrpe_checks()
|
2015-01-12 12:04:00 +00:00
|
|
|
nrpe.add_init_service_checks(nrpe_setup, services(), current_unit)
|
2015-02-19 14:17:25 +10:00
|
|
|
nrpe.add_haproxy_checks(nrpe_setup, current_unit)
|
2015-01-12 12:04:00 +00:00
|
|
|
nrpe_setup.write()
|
2014-10-29 22:30:35 -05:00
|
|
|
|
2014-11-17 13:39:29 +10:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
|
|
|
log('Unknown hook {} - skipping.'.format(e))
|
2016-01-14 11:31:23 +00:00
|
|
|
assess_status(CONFIGS)
|
2014-02-25 12:34:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|