2011-12-08 09:52:12 -08:00
|
|
|
#!/usr/bin/python
|
2012-02-29 11:59:37 -08:00
|
|
|
|
2014-12-12 18:32:45 +00:00
|
|
|
import hashlib
|
2014-02-25 12:34:13 +01:00
|
|
|
import os
|
|
|
|
import sys
|
2014-02-26 16:54:26 +00:00
|
|
|
import time
|
2014-02-25 12:34:13 +01:00
|
|
|
|
|
|
|
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,
|
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,
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.core.host import (
|
|
|
|
mkdir,
|
|
|
|
restart_on_change,
|
|
|
|
)
|
|
|
|
|
|
|
|
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 (
|
|
|
|
configure_installation_source,
|
|
|
|
openstack_upgrade_available,
|
2014-09-26 15:24:59 +01:00
|
|
|
sync_db_with_multi_ipv6_addresses
|
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,
|
|
|
|
do_openstack_upgrade,
|
2013-03-18 12:56:57 +00:00
|
|
|
ensure_initial_admin,
|
2014-10-24 08:51:39 +00:00
|
|
|
get_admin_passwd,
|
2014-02-25 12:34:13 +01:00
|
|
|
migrate_database,
|
|
|
|
save_script_rc,
|
2014-03-28 10:39:49 +00:00
|
|
|
synchronize_ca,
|
2014-02-25 12:34:13 +01:00
|
|
|
register_configs,
|
|
|
|
relation_list,
|
|
|
|
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,
|
|
|
|
SSH_USER,
|
2014-12-12 15:21:32 +00:00
|
|
|
setup_ipv6,
|
2014-12-16 23:48:42 +00:00
|
|
|
send_notifications,
|
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 (
|
|
|
|
eligible_leader,
|
|
|
|
is_leader,
|
2014-07-16 14:33:47 +01:00
|
|
|
get_hacluster_config,
|
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
|
|
|
|
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
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook()
|
|
|
|
def 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'))
|
|
|
|
apt_update()
|
|
|
|
apt_install(determine_packages(), fatal=True)
|
|
|
|
|
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())
|
2014-02-25 12:34:13 +01:00
|
|
|
def config_changed():
|
2014-09-18 19:27:07 +08:00
|
|
|
if config('prefer-ipv6'):
|
|
|
|
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
|
|
|
|
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):
|
2014-03-03 09:14:09 +00:00
|
|
|
mkdir(homedir, SSH_USER, 'keystone', 0o775)
|
2014-02-26 16:54:26 +00:00
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
if openstack_upgrade_available('keystone'):
|
|
|
|
do_openstack_upgrade(configs=CONFIGS)
|
2014-02-26 16:54:26 +00:00
|
|
|
|
|
|
|
check_call(['chmod', '-R', 'g+wrx', '/var/lib/keystone/'])
|
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
save_script_rc()
|
|
|
|
configure_https()
|
2014-10-29 22:30:35 -05:00
|
|
|
update_nrpe_config()
|
2014-02-25 12:34:13 +01:00
|
|
|
CONFIGS.write_all()
|
|
|
|
if eligible_leader(CLUSTER_RES):
|
|
|
|
migrate_database()
|
|
|
|
ensure_initial_admin(config)
|
|
|
|
log('Firing identity_changed hook for all related services.')
|
|
|
|
# HTTPS may have been set - so fire all identity relations
|
|
|
|
# again
|
|
|
|
for r_id in relation_ids('identity-service'):
|
2014-02-26 16:54:26 +00:00
|
|
|
for unit in relation_list(r_id):
|
|
|
|
identity_changed(relation_id=r_id,
|
|
|
|
remote_unit=unit)
|
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)
|
|
|
|
for rid in relation_ids('cluster'):
|
|
|
|
cluster_joined(rid)
|
2014-09-26 12:00:16 +01:00
|
|
|
|
2013-01-30 16:48:51 -08: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'))
|
|
|
|
|
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('shared-db-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
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)
|
|
|
|
if eligible_leader(CLUSTER_RES):
|
2014-08-28 09:12:42 +01:00
|
|
|
# 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.
|
2014-08-28 06:54:27 +00:00
|
|
|
allowed_units = relation_get('allowed_units')
|
|
|
|
if allowed_units and local_unit() not in allowed_units.split():
|
|
|
|
log('Allowed_units list provided and this unit not present')
|
|
|
|
return
|
2014-03-31 10:35:19 +02:00
|
|
|
migrate_database()
|
|
|
|
ensure_initial_admin(config)
|
|
|
|
# Ensure any existing service entries are updated in the
|
|
|
|
# new database backend
|
|
|
|
for rid in relation_ids('identity-service'):
|
|
|
|
for unit in related_units(rid):
|
|
|
|
identity_changed(relation_id=rid, remote_unit=unit)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('pgsql-db-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
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)
|
|
|
|
if eligible_leader(CLUSTER_RES):
|
|
|
|
migrate_database()
|
|
|
|
ensure_initial_admin(config)
|
2014-03-27 22:00:08 +00:00
|
|
|
# Ensure any existing service entries are updated in the
|
|
|
|
# new database backend
|
|
|
|
for rid in relation_ids('identity-service'):
|
2014-03-27 22:02:13 +00:00
|
|
|
for unit in related_units(rid):
|
2014-03-27 22:00:08 +00:00
|
|
|
identity_changed(relation_id=rid, remote_unit=unit)
|
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')
|
2014-02-26 16:54:26 +00:00
|
|
|
def identity_changed(relation_id=None, remote_unit=None):
|
2014-12-12 15:21:32 +00:00
|
|
|
notifications = {}
|
2014-02-25 12:34:13 +01:00
|
|
|
if eligible_leader(CLUSTER_RES):
|
2014-02-26 16:54:26 +00:00
|
|
|
add_service_to_keystone(relation_id, remote_unit)
|
2014-03-28 10:39:49 +00:00
|
|
|
synchronize_ca()
|
2014-12-12 15:21:32 +00:00
|
|
|
|
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)
|
|
|
|
if 'service_password' in peerdb_settings:
|
|
|
|
relation_set(relation_id=rel_id, **peerdb_settings)
|
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
|
|
|
|
2014-02-25 12:34:13 +01:00
|
|
|
@hooks.hook('cluster-relation-joined')
|
2014-09-26 12:00:16 +01:00
|
|
|
def cluster_joined(relation_id=None):
|
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)
|
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:
|
|
|
|
relation_set(
|
|
|
|
relation_id=relation_id,
|
|
|
|
relation_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]
|
2014-10-02 10:12:13 +01:00
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
relation_settings={'private-address': private_addr})
|
2012-12-17 13:45:58 +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)
|
2012-12-17 13:45:58 +00:00
|
|
|
def cluster_changed():
|
2014-03-28 11:04:08 +00:00
|
|
|
# NOTE(jamespage) re-echo passwords for peer storage
|
2014-08-19 12:39:31 +00:00
|
|
|
peer_echo(includes=['_passwd', 'identity-service:'])
|
2013-02-12 21:56:39 -08:00
|
|
|
unison.ssh_authorized_peers(user=SSH_USER,
|
2014-02-26 16:54:26 +00:00
|
|
|
group='keystone',
|
2013-03-18 12:56:57 +00:00
|
|
|
peer_interface='cluster',
|
2013-04-09 13:16:44 +01:00
|
|
|
ensure_local_user=True)
|
2014-03-28 10:39:49 +00:00
|
|
|
synchronize_ca()
|
2014-02-25 12:34:13 +01:00
|
|
|
CONFIGS.write_all()
|
2014-08-19 12:39:31 +00:00
|
|
|
for r_id in relation_ids('identity-service'):
|
|
|
|
for unit in relation_list(r_id):
|
|
|
|
identity_changed(relation_id=r_id,
|
|
|
|
remote_unit=unit)
|
2015-01-14 11:04:13 +00:00
|
|
|
for rid in relation_ids('identity-admin'):
|
|
|
|
admin_relation_changed(rid)
|
2014-02-25 12:34:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ha-relation-joined')
|
|
|
|
def ha_joined():
|
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)
|
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
|
|
|
)
|
|
|
|
vip_group.append(vip_key)
|
|
|
|
|
2014-09-04 10:19:33 +01:00
|
|
|
if len(vip_group) >= 1:
|
2014-07-16 14:17:03 +01:00
|
|
|
relation_set(groups={'grp_ks_vips': ' '.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
|
|
|
}
|
|
|
|
relation_set(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')
|
2014-03-03 09:13:00 +00:00
|
|
|
@restart_on_change(restart_map())
|
2014-02-25 12:34:13 +01:00
|
|
|
def ha_changed():
|
|
|
|
clustered = relation_get('clustered')
|
2014-03-03 09:13:00 +00:00
|
|
|
CONFIGS.write_all()
|
2014-02-26 16:54:26 +00:00
|
|
|
if (clustered is not None and
|
2014-03-03 09:14:09 +00:00
|
|
|
is_leader(CLUSTER_RES)):
|
2014-02-26 16:54:26 +00:00
|
|
|
ensure_initial_admin(config)
|
|
|
|
log('Cluster configured, notifying other services and updating '
|
|
|
|
'keystone endpoint configuration')
|
2014-09-15 15:10:03 +08:00
|
|
|
for rid in relation_ids('identity-service'):
|
|
|
|
for unit in related_units(rid):
|
|
|
|
identity_changed(relation_id=rid, remote_unit=unit)
|
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
|
|
|
|
|
|
|
|
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)
|
2014-02-25 12:34:13 +01:00
|
|
|
def upgrade_charm():
|
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,
|
|
|
|
group='keystone',
|
|
|
|
peer_interface='cluster',
|
|
|
|
ensure_local_user=True)
|
2014-10-29 22:30:35 -05:00
|
|
|
update_nrpe_config()
|
2014-03-28 10:43:32 +00:00
|
|
|
synchronize_ca()
|
2014-02-26 16:54:26 +00:00
|
|
|
if eligible_leader(CLUSTER_RES):
|
|
|
|
log('Cluster leader - ensuring endpoint configuration'
|
|
|
|
' is up to date')
|
2014-02-26 17:30:34 +00:00
|
|
|
time.sleep(10)
|
2014-02-26 16:54:26 +00:00
|
|
|
ensure_initial_admin(config)
|
2014-04-02 12:28:40 +01:00
|
|
|
# Deal with interface changes for icehouse
|
|
|
|
for r_id in relation_ids('identity-service'):
|
|
|
|
for unit in relation_list(r_id):
|
|
|
|
identity_changed(relation_id=r_id,
|
|
|
|
remote_unit=unit)
|
2014-02-25 12:34:13 +01:00
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
nrpe.add_init_service_checks(nrpe_setup, services(), current_unit)
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|