2013-08-01 20:42:16 -07:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2013-08-15 14:57:06 -07:00
|
|
|
import os
|
|
|
|
import shutil
|
2013-08-01 20:42:16 -07:00
|
|
|
import sys
|
2013-11-01 14:52:58 -07:00
|
|
|
import uuid
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2015-03-29 21:09:18 +01:00
|
|
|
from subprocess import (
|
|
|
|
check_call,
|
|
|
|
)
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
from urlparse import urlparse
|
|
|
|
|
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks,
|
|
|
|
UnregisteredHookError,
|
|
|
|
config,
|
2013-08-15 14:57:06 -07:00
|
|
|
charm_dir,
|
2014-03-20 11:18:23 +01:00
|
|
|
is_relation_made,
|
2013-08-01 20:42:16 -07:00
|
|
|
log,
|
2014-08-28 07:30:54 +00:00
|
|
|
local_unit,
|
2014-03-24 13:01:12 +01:00
|
|
|
ERROR,
|
2013-08-01 20:42:16 -07:00
|
|
|
relation_get,
|
|
|
|
relation_ids,
|
|
|
|
relation_set,
|
2014-05-23 17:24:52 +02:00
|
|
|
related_units,
|
2013-08-01 20:42:16 -07:00
|
|
|
open_port,
|
|
|
|
unit_get,
|
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.core.host import (
|
2014-05-15 08:25:56 +01:00
|
|
|
restart_on_change,
|
|
|
|
service_running,
|
|
|
|
service_stop,
|
2015-03-30 18:26:30 +01:00
|
|
|
service_reload,
|
2014-09-26 15:46:53 +00:00
|
|
|
service_restart,
|
2013-09-20 17:29:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.fetch import (
|
2014-08-21 17:04:33 +08:00
|
|
|
apt_install,
|
|
|
|
apt_update,
|
2014-04-29 14:44:23 +01:00
|
|
|
filter_installed_packages
|
2013-08-01 20:42:16 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
2015-04-15 14:17:56 +00:00
|
|
|
config_value_changed,
|
2013-08-01 20:42:16 -07:00
|
|
|
configure_installation_source,
|
2015-04-15 14:17:56 +00:00
|
|
|
git_install_requested,
|
2013-08-01 20:42:16 -07:00
|
|
|
openstack_upgrade_available,
|
2014-10-01 08:01:04 +00:00
|
|
|
os_release,
|
2014-10-20 10:15:18 +00:00
|
|
|
os_requires_version,
|
2014-09-27 01:17:47 +08:00
|
|
|
sync_db_with_multi_ipv6_addresses
|
2013-08-01 20:42:16 -07:00
|
|
|
)
|
|
|
|
|
2013-08-14 09:02:36 -07:00
|
|
|
from charmhelpers.contrib.openstack.neutron import (
|
2013-08-12 13:55:41 -07:00
|
|
|
network_manager,
|
|
|
|
neutron_plugin_attribute,
|
|
|
|
)
|
|
|
|
|
2014-05-16 09:04:20 +00:00
|
|
|
from nova_cc_context import (
|
2014-07-14 14:24:30 +00:00
|
|
|
NeutronAPIContext,
|
|
|
|
NovaCellContext,
|
2014-07-16 10:45:44 +01:00
|
|
|
)
|
2014-05-16 09:04:20 +00:00
|
|
|
|
2014-08-11 15:37:20 +00:00
|
|
|
from charmhelpers.contrib.peerstorage import (
|
|
|
|
peer_retrieve,
|
|
|
|
peer_echo,
|
2014-07-16 10:45:44 +01:00
|
|
|
)
|
2014-05-16 09:04:20 +00:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
from nova_cc_utils import (
|
2013-08-14 09:02:36 -07:00
|
|
|
api_port,
|
2013-08-01 20:42:16 -07:00
|
|
|
auth_token_config,
|
2014-08-11 13:42:11 +00:00
|
|
|
cmd_all_services,
|
2013-08-01 20:42:16 -07:00
|
|
|
determine_endpoints,
|
|
|
|
determine_packages,
|
|
|
|
determine_ports,
|
2014-08-11 13:42:11 +00:00
|
|
|
disable_services,
|
2013-08-01 20:42:16 -07:00
|
|
|
do_openstack_upgrade,
|
2014-08-11 13:42:11 +00:00
|
|
|
enable_services,
|
2015-04-15 14:17:56 +00:00
|
|
|
git_install,
|
2013-08-01 20:42:16 -07:00
|
|
|
keystone_ca_cert_b64,
|
2014-09-26 15:46:53 +00:00
|
|
|
migrate_neutron_database,
|
|
|
|
migrate_nova_database,
|
2013-08-14 09:02:36 -07:00
|
|
|
neutron_plugin,
|
2013-08-01 20:42:16 -07:00
|
|
|
save_script_rc,
|
2014-09-09 13:01:37 +00:00
|
|
|
services,
|
2013-08-01 20:42:16 -07:00
|
|
|
ssh_compute_add,
|
2013-08-10 09:49:47 +01:00
|
|
|
ssh_compute_remove,
|
2014-05-02 18:07:52 +02:00
|
|
|
ssh_known_hosts_lines,
|
|
|
|
ssh_authorized_keys_lines,
|
2013-08-01 20:42:16 -07:00
|
|
|
register_configs,
|
|
|
|
restart_map,
|
|
|
|
volume_service,
|
|
|
|
CLUSTER_RES,
|
2013-09-25 14:12:21 +01:00
|
|
|
NOVA_CONF,
|
|
|
|
QUANTUM_CONF,
|
|
|
|
NEUTRON_CONF,
|
2014-07-25 15:39:57 +01:00
|
|
|
QUANTUM_API_PASTE,
|
2014-07-09 14:30:59 +01:00
|
|
|
console_attributes,
|
2014-07-25 15:39:57 +01:00
|
|
|
service_guard,
|
|
|
|
guard_map,
|
2014-09-09 13:01:37 +00:00
|
|
|
get_topics,
|
2014-10-15 06:49:03 +00:00
|
|
|
setup_ipv6,
|
2013-08-01 20:42:16 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.hahelpers.cluster import (
|
2015-03-09 16:18:52 +00:00
|
|
|
is_elected_leader,
|
2013-08-01 20:42:16 -07:00
|
|
|
get_hacluster_config,
|
|
|
|
)
|
|
|
|
|
2013-09-27 17:18:25 +01:00
|
|
|
from charmhelpers.payload.execd import execd_preinstall
|
|
|
|
|
2014-07-04 12:49:08 +01:00
|
|
|
from charmhelpers.contrib.openstack.ip import (
|
|
|
|
canonical_url,
|
2015-07-22 13:33:03 +08:00
|
|
|
PUBLIC, INTERNAL, ADMIN,
|
|
|
|
resolve_address,
|
2014-07-04 12:49:08 +01:00
|
|
|
)
|
2013-09-27 17:18:25 +01:00
|
|
|
|
2014-07-16 14:15:48 +01:00
|
|
|
from charmhelpers.contrib.network.ip import (
|
|
|
|
get_iface_for_address,
|
2014-09-26 12:29:28 +01:00
|
|
|
get_netmask_for_address,
|
|
|
|
get_address_in_network,
|
2014-09-30 14:48:02 +08:00
|
|
|
get_ipv6_addr,
|
|
|
|
is_ipv6
|
2014-07-16 14:15:48 +01:00
|
|
|
)
|
|
|
|
|
2014-09-30 09:24:17 +01:00
|
|
|
from charmhelpers.contrib.openstack.context import ADDRESS_TYPES
|
|
|
|
|
2015-01-12 12:04:00 +00:00
|
|
|
from charmhelpers.contrib.charmsupport import nrpe
|
2014-10-29 22:30:36 -05:00
|
|
|
|
2015-05-22 11:32:59 -03:00
|
|
|
try:
|
|
|
|
FileNotFoundError
|
|
|
|
except NameError:
|
|
|
|
# python3 compatibility
|
|
|
|
FileNotFoundError = IOError
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
hooks = Hooks()
|
|
|
|
CONFIGS = register_configs()
|
2015-03-18 00:44:06 -03:00
|
|
|
COLO_CONSOLEAUTH = 'inf: res_nova_consoleauth grp_nova_vips'
|
|
|
|
AGENT_CONSOLEAUTH = 'ocf:openstack:nova-consoleauth'
|
|
|
|
AGENT_CA_PARAMS = 'op monitor interval="5s"'
|
2015-05-22 11:32:59 -03:00
|
|
|
NOVA_CONSOLEAUTH_OVERRIDE = '/etc/init/nova-consoleauth.override'
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook()
|
|
|
|
def install():
|
2013-09-27 17:18:25 +01:00
|
|
|
execd_preinstall()
|
2013-08-01 20:42:16 -07:00
|
|
|
configure_installation_source(config('openstack-origin'))
|
2015-04-15 14:17:56 +00:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
apt_update()
|
|
|
|
apt_install(determine_packages(), fatal=True)
|
2013-08-15 14:57:06 -07:00
|
|
|
|
2015-04-15 14:17:56 +00:00
|
|
|
git_install(config('openstack-origin-git'))
|
|
|
|
|
2013-08-15 14:57:06 -07:00
|
|
|
_files = os.path.join(charm_dir(), 'files')
|
|
|
|
if os.path.isdir(_files):
|
|
|
|
for f in os.listdir(_files):
|
|
|
|
f = os.path.join(_files, f)
|
2014-11-06 17:32:28 +10:00
|
|
|
if os.path.isfile(f):
|
|
|
|
log('Installing %s to /usr/bin' % f)
|
|
|
|
shutil.copy2(f, '/usr/bin')
|
2013-08-01 20:42:16 -07:00
|
|
|
[open_port(port) for port in determine_ports()]
|
2014-08-12 10:21:56 +00:00
|
|
|
log('Disabling services into db relation joined')
|
2014-08-11 13:42:11 +00:00
|
|
|
disable_services()
|
|
|
|
cmd_all_services('stop')
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
2013-08-12 10:50:39 -07:00
|
|
|
@hooks.hook('config-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2014-02-16 19:44:30 +01:00
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
2013-08-01 20:42:16 -07:00
|
|
|
def config_changed():
|
2014-09-18 20:23:54 +08:00
|
|
|
if config('prefer-ipv6'):
|
|
|
|
setup_ipv6()
|
2014-09-26 20:15:49 +01:00
|
|
|
sync_db_with_multi_ipv6_addresses(config('database'),
|
2014-09-30 14:59:57 +08:00
|
|
|
config('database-user'),
|
2014-09-30 13:42:04 +01:00
|
|
|
relation_prefix='nova')
|
2014-09-18 20:23:54 +08:00
|
|
|
|
2014-04-01 15:59:00 +01:00
|
|
|
global CONFIGS
|
2015-04-15 14:17:56 +00:00
|
|
|
if git_install_requested():
|
|
|
|
if config_value_changed('openstack-origin-git'):
|
|
|
|
git_install(config('openstack-origin-git'))
|
|
|
|
else:
|
|
|
|
if openstack_upgrade_available('nova-common'):
|
|
|
|
CONFIGS = do_openstack_upgrade()
|
|
|
|
[neutron_api_relation_joined(rid=rid, remote_restart=True)
|
|
|
|
for rid in relation_ids('neutron-api')]
|
2013-08-01 20:42:16 -07:00
|
|
|
save_script_rc()
|
|
|
|
configure_https()
|
2013-08-10 18:35:37 +01:00
|
|
|
CONFIGS.write_all()
|
2014-07-10 08:59:32 +00:00
|
|
|
if console_attributes('protocol'):
|
2015-04-15 14:17:56 +00:00
|
|
|
if not git_install_requested():
|
|
|
|
apt_update()
|
2015-06-12 14:03:50 +01:00
|
|
|
packages = console_attributes('packages') or []
|
|
|
|
filtered = filter_installed_packages(packages)
|
|
|
|
if filtered:
|
|
|
|
apt_install(filtered, fatal=True)
|
|
|
|
|
2014-07-10 08:59:32 +00:00
|
|
|
[compute_joined(rid=rid)
|
|
|
|
for rid in relation_ids('cloud-compute')]
|
2015-06-12 14:03:50 +01:00
|
|
|
|
2014-06-25 16:24:48 +01:00
|
|
|
for r_id in relation_ids('identity-service'):
|
2014-07-16 14:19:17 +01:00
|
|
|
identity_joined(rid=r_id)
|
2014-09-09 13:01:37 +00:00
|
|
|
for rid in relation_ids('zeromq-configuration'):
|
|
|
|
zeromq_configuration_relation_joined(rid)
|
2014-09-26 12:29:28 +01:00
|
|
|
[cluster_joined(rid) for rid in relation_ids('cluster')]
|
2014-10-29 22:30:36 -05:00
|
|
|
update_nrpe_config()
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2015-05-22 11:32:59 -03:00
|
|
|
update_nova_consoleauth_config()
|
2015-02-18 14:59:28 -03:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-joined')
|
2013-10-17 20:18:20 +01:00
|
|
|
def amqp_joined(relation_id=None):
|
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
username=config('rabbit-user'), vhost=config('rabbit-vhost'))
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-changed')
|
2014-01-30 12:26:36 +01:00
|
|
|
@hooks.hook('amqp-relation-departed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2013-08-01 20:42:16 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def amqp_changed():
|
|
|
|
if 'amqp' not in CONFIGS.complete_contexts():
|
|
|
|
log('amqp relation incomplete. Peer not ready?')
|
|
|
|
return
|
2013-09-25 14:12:21 +01:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2014-05-15 08:26:56 +00:00
|
|
|
if not is_relation_made('neutron-api'):
|
|
|
|
if network_manager() == 'quantum':
|
|
|
|
CONFIGS.write(QUANTUM_CONF)
|
|
|
|
if network_manager() == 'neutron':
|
|
|
|
CONFIGS.write(NEUTRON_CONF)
|
2014-04-25 16:46:42 +00:00
|
|
|
[nova_cell_relation_joined(rid=rid)
|
2014-05-13 16:44:49 +01:00
|
|
|
for rid in relation_ids('cell')]
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
2014-09-26 15:46:53 +00:00
|
|
|
def conditional_neutron_migration():
|
2014-10-21 13:14:49 +00:00
|
|
|
if os_release('nova-common') <= 'icehouse':
|
2015-04-22 14:39:04 +00:00
|
|
|
log('Not running neutron database migration as migrations are handled '
|
2014-10-01 08:01:04 +00:00
|
|
|
'by the neutron-server process.')
|
2015-04-22 13:49:57 +00:00
|
|
|
elif os_release('nova-common') >= 'kilo':
|
2015-04-22 14:39:04 +00:00
|
|
|
log('Not running neutron database migration as migrations are by '
|
2015-04-22 14:36:20 +00:00
|
|
|
'the neutron-api charm.')
|
2014-09-26 15:46:53 +00:00
|
|
|
else:
|
|
|
|
migrate_neutron_database()
|
|
|
|
# neutron-api service may have appeared while the migration was
|
|
|
|
# running so prod it just in case
|
|
|
|
[neutron_api_relation_joined(rid=rid, remote_restart=True)
|
|
|
|
for rid in relation_ids('neutron-api')]
|
|
|
|
if 'neutron-server' in services():
|
|
|
|
service_restart('neutron-server')
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('shared-db-relation-joined')
|
|
|
|
def db_joined():
|
2014-04-10 17:05:53 +01:00
|
|
|
if is_relation_made('pgsql-nova-db') or \
|
|
|
|
is_relation_made('pgsql-neutron-db'):
|
2014-03-20 11:18:23 +01:00
|
|
|
# error, postgresql is used
|
|
|
|
e = ('Attempting to associate a mysql database when there is already '
|
|
|
|
'associated a postgresql one')
|
2014-03-24 12:36:04 +01:00
|
|
|
log(e, level=ERROR)
|
2014-03-24 13:01:12 +01:00
|
|
|
raise Exception(e)
|
2014-03-24 15:31:59 +01:00
|
|
|
|
2013-08-10 14:35:17 +01:00
|
|
|
if network_manager() in ['quantum', 'neutron']:
|
2014-09-30 13:42:04 +01:00
|
|
|
config_neutron = True
|
|
|
|
else:
|
|
|
|
config_neutron = False
|
|
|
|
|
2014-08-06 20:46:50 +08:00
|
|
|
if config('prefer-ipv6'):
|
2014-09-26 20:15:49 +01:00
|
|
|
sync_db_with_multi_ipv6_addresses(config('database'),
|
2014-09-30 14:48:02 +08:00
|
|
|
config('database-user'),
|
2014-09-30 13:42:04 +01:00
|
|
|
relation_prefix='nova')
|
|
|
|
|
|
|
|
if config_neutron:
|
|
|
|
sync_db_with_multi_ipv6_addresses(config('neutron-database'),
|
|
|
|
config('neutron-database-user'),
|
|
|
|
relation_prefix='neutron')
|
2014-08-06 20:46:50 +08:00
|
|
|
else:
|
|
|
|
host = unit_get('private-address')
|
2014-09-27 01:17:47 +08:00
|
|
|
relation_set(nova_database=config('database'),
|
|
|
|
nova_username=config('database-user'),
|
|
|
|
nova_hostname=host)
|
2014-08-06 20:46:50 +08:00
|
|
|
|
2014-09-30 13:42:04 +01:00
|
|
|
if config_neutron:
|
|
|
|
# XXX: Renaming relations from quantum_* to neutron_* here.
|
|
|
|
relation_set(neutron_database=config('neutron-database'),
|
|
|
|
neutron_username=config('neutron-database-user'),
|
|
|
|
neutron_hostname=host)
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
2014-03-20 11:18:23 +01:00
|
|
|
@hooks.hook('pgsql-nova-db-relation-joined')
|
|
|
|
def pgsql_nova_db_joined():
|
|
|
|
if is_relation_made('shared-db'):
|
|
|
|
# raise error
|
2014-04-10 17:05:53 +01:00
|
|
|
e = ('Attempting to associate a postgresql database'
|
|
|
|
' when there is already associated a mysql one')
|
2014-03-24 12:36:04 +01:00
|
|
|
log(e, level=ERROR)
|
2014-03-24 13:01:12 +01:00
|
|
|
raise Exception(e)
|
2014-03-20 11:18:23 +01:00
|
|
|
|
2014-03-25 10:00:50 +01:00
|
|
|
relation_set(database=config('database'))
|
2014-03-20 11:18:23 +01:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('pgsql-neutron-db-relation-joined')
|
|
|
|
def pgsql_neutron_db_joined():
|
|
|
|
if is_relation_made('shared-db'):
|
|
|
|
# raise error
|
2014-04-10 17:05:53 +01:00
|
|
|
e = ('Attempting to associate a postgresql database'
|
|
|
|
' when there is already associated a mysql one')
|
2014-03-24 12:36:04 +01:00
|
|
|
log(e, level=ERROR)
|
2014-03-24 13:01:12 +01:00
|
|
|
raise Exception(e)
|
2014-03-20 11:18:23 +01:00
|
|
|
|
2014-03-25 10:00:50 +01:00
|
|
|
relation_set(database=config('neutron-database'))
|
2014-03-20 11:18:23 +01:00
|
|
|
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
@hooks.hook('shared-db-relation-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2013-08-01 20:42:16 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def db_changed():
|
|
|
|
if 'shared-db' not in CONFIGS.complete_contexts():
|
|
|
|
log('shared-db relation incomplete. Peer not ready?')
|
|
|
|
return
|
2014-04-11 17:41:42 +01:00
|
|
|
CONFIGS.write_all()
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2015-03-09 16:18:52 +00:00
|
|
|
if is_elected_leader(CLUSTER_RES):
|
2014-08-28 07:30:54 +00: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.
|
|
|
|
allowed_units = relation_get('nova_allowed_units')
|
2015-04-21 16:28:53 +01:00
|
|
|
if allowed_units and local_unit() in allowed_units.split():
|
|
|
|
migrate_nova_database()
|
|
|
|
log('Triggering remote cloud-compute restarts.')
|
|
|
|
[compute_joined(rid=rid, remote_restart=True)
|
|
|
|
for rid in relation_ids('cloud-compute')]
|
|
|
|
log('Triggering remote cell restarts.')
|
|
|
|
[nova_cell_relation_joined(rid=rid, remote_restart=True)
|
|
|
|
for rid in relation_ids('cell')]
|
|
|
|
conditional_neutron_migration()
|
|
|
|
else:
|
|
|
|
log('allowed_units either not presented, or local unit '
|
|
|
|
'not in acl list: %s' % repr(allowed_units))
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
2014-03-20 11:18:23 +01:00
|
|
|
@hooks.hook('pgsql-nova-db-relation-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2014-03-20 11:18:23 +01:00
|
|
|
@restart_on_change(restart_map())
|
2014-03-24 12:36:04 +01:00
|
|
|
def postgresql_nova_db_changed():
|
|
|
|
if 'pgsql-nova-db' not in CONFIGS.complete_contexts():
|
2014-03-27 12:46:44 +01:00
|
|
|
log('pgsql-nova-db relation incomplete. Peer not ready?')
|
2014-03-20 11:18:23 +01:00
|
|
|
return
|
2014-04-11 17:41:42 +01:00
|
|
|
CONFIGS.write_all()
|
2014-03-20 11:18:23 +01:00
|
|
|
|
2015-03-09 16:18:52 +00:00
|
|
|
if is_elected_leader(CLUSTER_RES):
|
2014-09-26 15:46:53 +00:00
|
|
|
migrate_nova_database()
|
2014-03-20 11:18:23 +01:00
|
|
|
log('Triggering remote cloud-compute restarts.')
|
|
|
|
[compute_joined(rid=rid, remote_restart=True)
|
|
|
|
for rid in relation_ids('cloud-compute')]
|
2014-09-26 15:46:53 +00:00
|
|
|
conditional_neutron_migration()
|
2014-03-20 11:18:23 +01:00
|
|
|
|
2014-03-31 12:56:09 +01:00
|
|
|
|
2014-03-24 12:36:04 +01:00
|
|
|
@hooks.hook('pgsql-neutron-db-relation-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2014-03-24 12:36:04 +01:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def postgresql_neutron_db_changed():
|
|
|
|
if network_manager() in ['neutron', 'quantum']:
|
|
|
|
plugin = neutron_plugin()
|
|
|
|
# DB config might have been moved to main neutron.conf in H?
|
|
|
|
CONFIGS.write(neutron_plugin_attribute(plugin, 'config'))
|
|
|
|
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
@hooks.hook('image-service-relation-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2013-08-01 20:42:16 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def image_service_changed():
|
|
|
|
if 'image-service' not in CONFIGS.complete_contexts():
|
|
|
|
log('image-service relation incomplete. Peer not ready?')
|
|
|
|
return
|
2013-09-25 14:12:21 +01:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-08-01 20:42:16 -07:00
|
|
|
# TODO: special case config flag for essex (strip protocol)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('identity-service-relation-joined')
|
|
|
|
def identity_joined(rid=None):
|
2014-07-04 12:49:08 +01:00
|
|
|
public_url = canonical_url(CONFIGS, PUBLIC)
|
|
|
|
internal_url = canonical_url(CONFIGS, INTERNAL)
|
|
|
|
admin_url = canonical_url(CONFIGS, ADMIN)
|
2014-06-25 16:24:48 +01:00
|
|
|
relation_set(relation_id=rid, **determine_endpoints(public_url,
|
2014-06-27 11:37:18 +01:00
|
|
|
internal_url,
|
|
|
|
admin_url))
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('identity-service-relation-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2013-08-01 20:42:16 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def identity_changed():
|
|
|
|
if 'identity-service' not in CONFIGS.complete_contexts():
|
|
|
|
log('identity-service relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write('/etc/nova/api-paste.ini')
|
2013-09-25 14:12:21 +01:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2014-05-15 08:26:56 +00:00
|
|
|
if not is_relation_made('neutron-api'):
|
|
|
|
if network_manager() == 'quantum':
|
|
|
|
CONFIGS.write(QUANTUM_API_PASTE)
|
|
|
|
CONFIGS.write(QUANTUM_CONF)
|
|
|
|
save_novarc()
|
|
|
|
if network_manager() == 'neutron':
|
|
|
|
CONFIGS.write(NEUTRON_CONF)
|
2013-08-14 09:02:36 -07:00
|
|
|
[compute_joined(rid) for rid in relation_ids('cloud-compute')]
|
2013-09-30 15:58:45 +01:00
|
|
|
[quantum_joined(rid) for rid in relation_ids('quantum-network-service')]
|
2013-10-30 18:59:34 -07:00
|
|
|
[nova_vmware_relation_joined(rid) for rid in relation_ids('nova-vmware')]
|
2014-06-29 08:21:38 +01:00
|
|
|
[neutron_api_relation_joined(rid) for rid in relation_ids('neutron-api')]
|
2013-08-19 15:15:34 -07:00
|
|
|
configure_https()
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('nova-volume-service-relation-joined',
|
|
|
|
'cinder-volume-service-relation-joined')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2013-08-01 20:42:16 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def volume_joined():
|
2013-09-25 14:12:21 +01:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-08-01 20:42:16 -07:00
|
|
|
# kick identity_joined() to publish possibly new nova-volume endpoint.
|
|
|
|
[identity_joined(rid) for rid in relation_ids('identity-service')]
|
|
|
|
|
|
|
|
|
|
|
|
def _auth_config():
|
|
|
|
'''Grab all KS auth token config from api-paste.ini, or return empty {}'''
|
|
|
|
ks_auth_host = auth_token_config('auth_host')
|
|
|
|
if not ks_auth_host:
|
|
|
|
# if there is no auth_host set, identity-service changed hooks
|
|
|
|
# have not fired, yet.
|
|
|
|
return {}
|
|
|
|
cfg = {
|
|
|
|
'auth_host': ks_auth_host,
|
|
|
|
'auth_port': auth_token_config('auth_port'),
|
2014-02-27 09:26:38 +00:00
|
|
|
'auth_protocol': auth_token_config('auth_protocol'),
|
|
|
|
'service_protocol': auth_token_config('service_protocol'),
|
2013-08-01 20:42:16 -07:00
|
|
|
'service_port': auth_token_config('service_port'),
|
|
|
|
'service_username': auth_token_config('admin_user'),
|
|
|
|
'service_password': auth_token_config('admin_password'),
|
|
|
|
'service_tenant_name': auth_token_config('admin_tenant_name'),
|
|
|
|
'auth_uri': auth_token_config('auth_uri'),
|
2013-08-15 14:57:06 -07:00
|
|
|
# quantum-gateway interface deviates a bit.
|
|
|
|
'keystone_host': ks_auth_host,
|
|
|
|
'service_tenant': auth_token_config('admin_tenant_name'),
|
2013-08-01 20:42:16 -07:00
|
|
|
}
|
|
|
|
return cfg
|
|
|
|
|
|
|
|
|
2013-08-15 15:47:37 -07:00
|
|
|
def save_novarc():
|
|
|
|
auth = _auth_config()
|
|
|
|
# XXX hard-coded http
|
2014-02-27 09:26:38 +00:00
|
|
|
ks_url = '%s://%s:%s/v2.0' % (auth['auth_protocol'],
|
|
|
|
auth['auth_host'], auth['auth_port'])
|
2013-08-15 15:47:37 -07:00
|
|
|
with open('/etc/quantum/novarc', 'wb') as out:
|
|
|
|
out.write('export OS_USERNAME=%s\n' % auth['service_username'])
|
|
|
|
out.write('export OS_PASSWORD=%s\n' % auth['service_password'])
|
|
|
|
out.write('export OS_TENANT_NAME=%s\n' % auth['service_tenant_name'])
|
|
|
|
out.write('export OS_AUTH_URL=%s\n' % ks_url)
|
|
|
|
out.write('export OS_REGION_NAME=%s\n' % config('region'))
|
|
|
|
|
|
|
|
|
2014-05-21 14:47:14 +00:00
|
|
|
def neutron_settings():
|
|
|
|
neutron_settings = {}
|
2014-06-23 13:22:26 +01:00
|
|
|
if is_relation_made('neutron-api', 'neutron-plugin'):
|
2014-06-24 12:43:28 +01:00
|
|
|
neutron_api_info = NeutronAPIContext()()
|
2014-05-21 14:47:14 +00:00
|
|
|
neutron_settings.update({
|
|
|
|
# XXX: Rename these relations settings?
|
2014-06-24 12:43:28 +01:00
|
|
|
'quantum_plugin': neutron_api_info['neutron_plugin'],
|
2014-05-21 14:47:14 +00:00
|
|
|
'region': config('region'),
|
2014-06-23 12:07:35 +01:00
|
|
|
'quantum_security_groups':
|
2014-06-24 12:43:28 +01:00
|
|
|
neutron_api_info['neutron_security_groups'],
|
|
|
|
'quantum_url': neutron_api_info['neutron_url'],
|
2014-05-21 14:47:14 +00:00
|
|
|
})
|
|
|
|
else:
|
|
|
|
neutron_settings.update({
|
2013-08-14 09:02:36 -07:00
|
|
|
# XXX: Rename these relations settings?
|
|
|
|
'quantum_plugin': neutron_plugin(),
|
|
|
|
'region': config('region'),
|
2013-09-24 15:08:06 +01:00
|
|
|
'quantum_security_groups': config('quantum-security-groups'),
|
2014-07-04 12:49:08 +01:00
|
|
|
'quantum_url': "{}:{}".format(canonical_url(CONFIGS, INTERNAL),
|
2014-06-25 16:24:48 +01:00
|
|
|
str(api_port('neutron-server'))),
|
2013-08-14 09:02:36 -07:00
|
|
|
})
|
2014-06-24 12:43:28 +01:00
|
|
|
neutron_url = urlparse(neutron_settings['quantum_url'])
|
|
|
|
neutron_settings['quantum_host'] = neutron_url.hostname
|
|
|
|
neutron_settings['quantum_port'] = neutron_url.port
|
2014-05-21 14:47:14 +00:00
|
|
|
return neutron_settings
|
2013-08-15 15:47:37 -07:00
|
|
|
|
2014-06-20 09:59:07 +01:00
|
|
|
|
2013-10-29 19:28:46 -07:00
|
|
|
def keystone_compute_settings():
|
2013-08-01 20:42:16 -07:00
|
|
|
ks_auth_config = _auth_config()
|
2013-10-29 19:28:46 -07:00
|
|
|
rel_settings = {}
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2013-08-10 14:35:17 +01:00
|
|
|
if network_manager() in ['quantum', 'neutron']:
|
2013-08-01 20:42:16 -07:00
|
|
|
if ks_auth_config:
|
|
|
|
rel_settings.update(ks_auth_config)
|
2014-05-21 14:47:14 +00:00
|
|
|
rel_settings.update(neutron_settings())
|
2013-08-01 20:42:16 -07:00
|
|
|
ks_ca = keystone_ca_cert_b64()
|
|
|
|
if ks_auth_config and ks_ca:
|
|
|
|
rel_settings['ca_cert'] = ks_ca
|
2013-10-29 19:28:46 -07:00
|
|
|
return rel_settings
|
|
|
|
|
|
|
|
|
2014-07-09 14:09:15 +01:00
|
|
|
def console_settings():
|
|
|
|
rel_settings = {}
|
2014-07-10 08:37:39 +01:00
|
|
|
proto = console_attributes('protocol')
|
|
|
|
if not proto:
|
2014-07-09 14:09:15 +01:00
|
|
|
return {}
|
2014-07-10 08:37:39 +01:00
|
|
|
rel_settings['console_keymap'] = config('console-keymap')
|
|
|
|
rel_settings['console_access_protocol'] = proto
|
2015-07-22 13:33:03 +08:00
|
|
|
|
|
|
|
scheme = 'http'
|
|
|
|
if config('console-access-ssl-cert') and config('console-access-ssl-key'):
|
|
|
|
scheme = 'https'
|
|
|
|
|
|
|
|
address = resolve_address(endpoint_type=PUBLIC)
|
|
|
|
if is_ipv6(address):
|
|
|
|
address = "[{}]".format(address)
|
|
|
|
|
2014-07-30 10:49:59 +00:00
|
|
|
if config('console-proxy-ip') == 'local':
|
2015-07-22 13:33:03 +08:00
|
|
|
proxy_base_addr = '%s://%s' % (scheme, address)
|
2014-07-09 14:09:15 +01:00
|
|
|
else:
|
2015-07-22 13:33:03 +08:00
|
|
|
proxy_base_addr = "%s://%s" % (scheme, config('console-proxy-ip'))
|
2014-07-10 08:37:39 +01:00
|
|
|
if proto == 'vnc':
|
|
|
|
protocols = ['novnc', 'xvpvnc']
|
|
|
|
else:
|
|
|
|
protocols = [proto]
|
|
|
|
for _proto in protocols:
|
|
|
|
rel_settings['console_proxy_%s_address' % (_proto)] = \
|
2014-07-10 09:04:00 +00:00
|
|
|
"%s:%s%s" % (proxy_base_addr,
|
2014-07-10 11:11:13 +01:00
|
|
|
console_attributes('proxy-port', proto=_proto),
|
|
|
|
console_attributes('proxy-page', proto=_proto))
|
2014-07-10 08:59:32 +00:00
|
|
|
rel_settings['console_proxy_%s_host' % (_proto)] = \
|
|
|
|
urlparse(proxy_base_addr).hostname
|
2014-07-10 08:37:39 +01:00
|
|
|
rel_settings['console_proxy_%s_port' % (_proto)] = \
|
2014-07-10 09:07:28 +01:00
|
|
|
console_attributes('proxy-port', proto=_proto)
|
2014-07-10 08:37:39 +01:00
|
|
|
|
2014-07-09 14:09:15 +01:00
|
|
|
return rel_settings
|
|
|
|
|
|
|
|
|
2013-10-29 19:28:46 -07:00
|
|
|
@hooks.hook('cloud-compute-relation-joined')
|
2013-11-01 14:52:58 -07:00
|
|
|
def compute_joined(rid=None, remote_restart=False):
|
2014-07-30 10:20:43 +00:00
|
|
|
cons_settings = console_settings()
|
|
|
|
relation_set(relation_id=rid, **cons_settings)
|
2013-10-29 19:28:46 -07:00
|
|
|
rel_settings = {
|
|
|
|
'network_manager': network_manager(),
|
|
|
|
'volume_service': volume_service(),
|
|
|
|
# (comment from bash vers) XXX Should point to VIP if clustered, or
|
|
|
|
# this may not even be needed.
|
|
|
|
'ec2_host': unit_get('private-address'),
|
|
|
|
}
|
2013-11-01 14:52:58 -07:00
|
|
|
# update relation setting if we're attempting to restart remote
|
|
|
|
# services
|
|
|
|
if remote_restart:
|
|
|
|
rel_settings['restart_trigger'] = str(uuid.uuid4())
|
|
|
|
|
2013-10-29 19:28:46 -07:00
|
|
|
rel_settings.update(keystone_compute_settings())
|
2013-08-14 09:02:36 -07:00
|
|
|
relation_set(relation_id=rid, **rel_settings)
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
2013-08-12 13:53:00 -07:00
|
|
|
@hooks.hook('cloud-compute-relation-changed')
|
2014-06-24 12:53:08 +02:00
|
|
|
def compute_changed(rid=None, unit=None):
|
|
|
|
rel_settings = relation_get(rid=rid, unit=unit)
|
2014-05-27 14:15:42 +02:00
|
|
|
if 'migration_auth_type' not in rel_settings:
|
|
|
|
return
|
|
|
|
if rel_settings['migration_auth_type'] == 'ssh':
|
2014-06-24 12:53:08 +02:00
|
|
|
key = rel_settings.get('ssh_public_key')
|
2013-08-10 09:49:47 +01:00
|
|
|
if not key:
|
|
|
|
log('SSH migration set but peer did not publish key.')
|
|
|
|
return
|
2014-06-24 12:53:08 +02:00
|
|
|
ssh_compute_add(key, rid=rid, unit=unit)
|
2014-04-30 14:13:22 +02:00
|
|
|
index = 0
|
2014-06-24 12:53:08 +02:00
|
|
|
for line in ssh_known_hosts_lines(unit=unit):
|
2014-07-16 10:45:44 +01:00
|
|
|
relation_set(
|
|
|
|
relation_id=rid,
|
|
|
|
relation_settings={
|
|
|
|
'known_hosts_{}'.format(index): line})
|
2014-05-02 18:07:52 +02:00
|
|
|
index += 1
|
2014-05-23 17:24:52 +02:00
|
|
|
relation_set(relation_id=rid, known_hosts_max_index=index)
|
2014-05-02 18:07:52 +02:00
|
|
|
index = 0
|
2014-06-24 12:53:08 +02:00
|
|
|
for line in ssh_authorized_keys_lines(unit=unit):
|
2014-07-16 10:45:44 +01:00
|
|
|
relation_set(
|
|
|
|
relation_id=rid,
|
|
|
|
relation_settings={
|
|
|
|
'authorized_keys_{}'.format(index): line})
|
2014-05-02 18:07:52 +02:00
|
|
|
index += 1
|
2014-05-23 17:24:52 +02:00
|
|
|
relation_set(relation_id=rid, authorized_keys_max_index=index)
|
2014-05-27 15:43:49 +02:00
|
|
|
if 'nova_ssh_public_key' not in rel_settings:
|
|
|
|
return
|
2014-05-27 14:15:42 +02:00
|
|
|
if rel_settings['nova_ssh_public_key']:
|
|
|
|
ssh_compute_add(rel_settings['nova_ssh_public_key'],
|
2014-06-24 12:53:08 +02:00
|
|
|
rid=rid, unit=unit, user='nova')
|
2014-05-06 15:43:57 +02:00
|
|
|
index = 0
|
2014-06-24 12:53:08 +02:00
|
|
|
for line in ssh_known_hosts_lines(unit=unit, user='nova'):
|
2014-07-16 10:45:44 +01:00
|
|
|
relation_set(
|
|
|
|
relation_id=rid,
|
|
|
|
relation_settings={
|
|
|
|
'{}_known_hosts_{}'.format(
|
|
|
|
'nova',
|
|
|
|
index): line})
|
2014-05-06 15:43:57 +02:00
|
|
|
index += 1
|
2014-07-16 10:45:44 +01:00
|
|
|
relation_set(
|
|
|
|
relation_id=rid,
|
|
|
|
relation_settings={
|
|
|
|
'{}_known_hosts_max_index'.format('nova'): index})
|
2014-05-06 15:43:57 +02:00
|
|
|
index = 0
|
2014-06-24 12:53:08 +02:00
|
|
|
for line in ssh_authorized_keys_lines(unit=unit, user='nova'):
|
2014-07-16 10:45:44 +01:00
|
|
|
relation_set(
|
|
|
|
relation_id=rid,
|
|
|
|
relation_settings={
|
|
|
|
'{}_authorized_keys_{}'.format(
|
|
|
|
'nova',
|
|
|
|
index): line})
|
2014-05-06 15:43:57 +02:00
|
|
|
index += 1
|
2014-07-16 10:45:44 +01:00
|
|
|
relation_set(
|
|
|
|
relation_id=rid,
|
|
|
|
relation_settings={
|
|
|
|
'{}_authorized_keys_max_index'.format('nova'): index})
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
2013-09-05 17:28:22 -07:00
|
|
|
@hooks.hook('cloud-compute-relation-departed')
|
2013-08-10 09:49:47 +01:00
|
|
|
def compute_departed():
|
2013-09-05 17:28:22 -07:00
|
|
|
ssh_compute_remove(public_key=relation_get('ssh_public_key'))
|
2013-08-10 09:49:47 +01:00
|
|
|
|
|
|
|
|
2013-08-10 14:35:17 +01:00
|
|
|
@hooks.hook('neutron-network-service-relation-joined',
|
|
|
|
'quantum-network-service-relation-joined')
|
2013-08-01 20:42:16 -07:00
|
|
|
def quantum_joined(rid=None):
|
2014-05-21 14:47:14 +00:00
|
|
|
rel_settings = neutron_settings()
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
# inform quantum about local keystone auth config
|
|
|
|
ks_auth_config = _auth_config()
|
|
|
|
rel_settings.update(ks_auth_config)
|
|
|
|
|
|
|
|
# must pass the keystone CA cert, if it exists.
|
|
|
|
ks_ca = keystone_ca_cert_b64()
|
|
|
|
if ks_auth_config and ks_ca:
|
|
|
|
rel_settings['ca_cert'] = ks_ca
|
2013-10-23 09:55:26 -07:00
|
|
|
relation_set(relation_id=rid, **rel_settings)
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
2014-09-26 12:29:28 +01:00
|
|
|
@hooks.hook('cluster-relation-joined')
|
|
|
|
def cluster_joined(relation_id=None):
|
2014-09-30 09:24:17 +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}
|
|
|
|
)
|
2014-09-30 14:48:02 +08:00
|
|
|
if config('prefer-ipv6'):
|
|
|
|
private_addr = get_ipv6_addr(exc_list=[config('vip')])[0]
|
2014-10-02 10:22:36 +01:00
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
relation_settings={'private-address': private_addr})
|
2014-09-26 12:29:28 +01:00
|
|
|
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
@hooks.hook('cluster-relation-changed',
|
2015-03-13 11:51:30 +00:00
|
|
|
'cluster-relation-departed',
|
|
|
|
'leader-settings-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2014-02-16 19:44:30 +01:00
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
2013-08-01 20:42:16 -07:00
|
|
|
def cluster_changed():
|
|
|
|
CONFIGS.write_all()
|
2014-09-12 14:57:42 +01:00
|
|
|
if relation_ids('cluster'):
|
2014-10-20 14:43:49 +01:00
|
|
|
peer_echo(includes=['dbsync_state'])
|
2014-08-12 10:21:56 +00:00
|
|
|
dbsync_state = peer_retrieve('dbsync_state')
|
|
|
|
if dbsync_state == 'complete':
|
|
|
|
enable_services()
|
|
|
|
cmd_all_services('start')
|
|
|
|
else:
|
|
|
|
log('Database sync not ready. Shutting down services')
|
|
|
|
disable_services()
|
|
|
|
cmd_all_services('stop')
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ha-relation-joined')
|
|
|
|
def ha_joined():
|
2014-08-06 20:46:50 +08:00
|
|
|
cluster_config = get_hacluster_config()
|
2013-08-01 20:42:16 -07:00
|
|
|
resources = {
|
|
|
|
'res_nova_haproxy': 'lsb:haproxy',
|
|
|
|
}
|
|
|
|
resource_params = {
|
2015-02-17 12:57:15 -03:00
|
|
|
'res_nova_haproxy': 'op monitor interval="5s"',
|
2013-08-01 20:42:16 -07:00
|
|
|
}
|
2014-08-06 20:46:50 +08:00
|
|
|
|
2014-07-16 14:15:48 +01:00
|
|
|
vip_group = []
|
2014-08-06 20:46:50 +08:00
|
|
|
for vip in cluster_config['vip'].split():
|
2014-09-30 14:48:02 +08:00
|
|
|
if is_ipv6(vip):
|
|
|
|
res_nova_vip = 'ocf:heartbeat:IPv6addr'
|
|
|
|
vip_params = 'ipv6addr'
|
|
|
|
else:
|
|
|
|
res_nova_vip = 'ocf:heartbeat:IPaddr2'
|
|
|
|
vip_params = 'ip'
|
|
|
|
|
2014-11-12 09:40:22 +00:00
|
|
|
iface = (get_iface_for_address(vip) or
|
|
|
|
config('vip_iface'))
|
|
|
|
netmask = (get_netmask_for_address(vip) or
|
|
|
|
config('vip_cidr'))
|
|
|
|
|
2014-07-16 14:15:48 +01:00
|
|
|
if iface is not None:
|
|
|
|
vip_key = 'res_nova_{}_vip'.format(iface)
|
2014-08-06 20:46:50 +08:00
|
|
|
resources[vip_key] = res_nova_vip
|
2014-07-16 14:15:48 +01:00
|
|
|
resource_params[vip_key] = (
|
2014-08-06 20:46:50 +08:00
|
|
|
'params {ip}="{vip}" cidr_netmask="{netmask}"'
|
|
|
|
' nic="{iface}"'.format(ip=vip_params,
|
|
|
|
vip=vip,
|
2014-07-16 14:15:48 +01:00
|
|
|
iface=iface,
|
2014-11-12 09:40:22 +00:00
|
|
|
netmask=netmask)
|
2014-07-16 14:15:48 +01:00
|
|
|
)
|
|
|
|
vip_group.append(vip_key)
|
|
|
|
|
2014-09-04 10:20:50 +01:00
|
|
|
if len(vip_group) >= 1:
|
2014-07-16 14:15:48 +01:00
|
|
|
relation_set(groups={'grp_nova_vips': ' '.join(vip_group)})
|
2014-07-16 14:19:17 +01:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
init_services = {
|
|
|
|
'res_nova_haproxy': 'haproxy'
|
|
|
|
}
|
|
|
|
clones = {
|
|
|
|
'cl_nova_haproxy': 'res_nova_haproxy'
|
|
|
|
}
|
2015-02-18 15:22:26 -03:00
|
|
|
colocations = {}
|
2015-02-18 14:59:28 -03:00
|
|
|
|
|
|
|
if config('single-nova-consoleauth') and console_attributes('protocol'):
|
2015-03-18 00:44:06 -03:00
|
|
|
colocations['vip_consoleauth'] = COLO_CONSOLEAUTH
|
2015-02-18 14:59:28 -03:00
|
|
|
init_services['res_nova_consoleauth'] = 'nova-consoleauth'
|
2015-03-18 00:44:06 -03:00
|
|
|
resources['res_nova_consoleauth'] = AGENT_CONSOLEAUTH
|
|
|
|
resource_params['res_nova_consoleauth'] = AGENT_CA_PARAMS
|
2015-02-18 14:59:28 -03:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
relation_set(init_services=init_services,
|
2014-08-06 20:46:50 +08:00
|
|
|
corosync_bindiface=cluster_config['ha-bindiface'],
|
|
|
|
corosync_mcastport=cluster_config['ha-mcastport'],
|
2013-08-01 20:42:16 -07:00
|
|
|
resources=resources,
|
|
|
|
resource_params=resource_params,
|
2015-02-17 12:57:15 -03:00
|
|
|
clones=clones,
|
|
|
|
colocations=colocations)
|
2013-08-01 20:42:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('ha-relation-changed')
|
|
|
|
def ha_changed():
|
2013-08-16 17:36:55 -07:00
|
|
|
clustered = relation_get('clustered')
|
|
|
|
if not clustered or clustered in [None, 'None', '']:
|
2013-08-01 20:42:16 -07:00
|
|
|
log('ha_changed: hacluster subordinate not fully clustered.')
|
|
|
|
return
|
2014-07-31 10:03:29 +08:00
|
|
|
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
2014-09-04 08:55:09 +00:00
|
|
|
if not is_relation_made('neutron-api'):
|
|
|
|
if network_manager() == 'quantum':
|
|
|
|
CONFIGS.write(QUANTUM_CONF)
|
|
|
|
if network_manager() == 'neutron':
|
|
|
|
CONFIGS.write(NEUTRON_CONF)
|
2014-07-31 10:03:29 +08:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
log('Cluster configured, notifying other services and updating '
|
|
|
|
'keystone endpoint configuration')
|
|
|
|
for rid in relation_ids('identity-service'):
|
|
|
|
identity_joined(rid=rid)
|
|
|
|
|
2015-05-22 11:32:59 -03:00
|
|
|
update_nova_consoleauth_config()
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
|
2014-08-12 06:50:23 +00:00
|
|
|
@hooks.hook('shared-db-relation-broken',
|
|
|
|
'pgsql-nova-db-relation-broken')
|
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
|
|
|
def db_departed():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
for r_id in relation_ids('cluster'):
|
|
|
|
relation_set(relation_id=r_id, dbsync_state='incomplete')
|
2014-08-12 10:07:44 +00:00
|
|
|
disable_services()
|
|
|
|
cmd_all_services('stop')
|
|
|
|
|
2014-08-12 06:50:23 +00:00
|
|
|
|
2013-08-20 12:06:15 -07:00
|
|
|
@hooks.hook('amqp-relation-broken',
|
|
|
|
'cinder-volume-service-relation-broken',
|
|
|
|
'identity-service-relation-broken',
|
|
|
|
'image-service-relation-broken',
|
|
|
|
'nova-volume-service-relation-broken',
|
2014-03-20 11:18:23 +01:00
|
|
|
'pgsql-neutron-db-relation-broken',
|
2013-08-20 12:06:15 -07:00
|
|
|
'quantum-network-service-relation-broken')
|
2014-07-29 13:25:27 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2013-08-20 12:06:15 -07:00
|
|
|
def relation_broken():
|
|
|
|
CONFIGS.write_all()
|
2014-04-25 16:46:42 +00:00
|
|
|
[nova_cell_relation_joined(rid=rid)
|
2014-05-13 16:44:49 +01:00
|
|
|
for rid in relation_ids('cell')]
|
2013-08-20 12:06:15 -07:00
|
|
|
|
|
|
|
|
2013-08-01 20:42:16 -07: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)
|
|
|
|
|
2015-03-29 21:09:18 +01:00
|
|
|
# TODO: improve this by checking if local CN certs are available
|
|
|
|
# first then checking reload status (see LP #1433114).
|
2015-03-30 18:26:30 +01:00
|
|
|
service_reload('apache2', restart_on_failure=True)
|
2015-03-29 21:09:18 +01:00
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
for rid in relation_ids('identity-service'):
|
|
|
|
identity_joined(rid=rid)
|
|
|
|
|
|
|
|
|
2013-10-08 17:51:27 -07:00
|
|
|
@hooks.hook()
|
2013-10-30 18:59:34 -07:00
|
|
|
def nova_vmware_relation_joined(rid=None):
|
2013-10-29 19:28:46 -07:00
|
|
|
rel_settings = {'network_manager': network_manager()}
|
|
|
|
|
|
|
|
ks_auth = _auth_config()
|
|
|
|
if ks_auth:
|
|
|
|
rel_settings.update(ks_auth)
|
|
|
|
rel_settings.update({
|
|
|
|
'quantum_plugin': neutron_plugin(),
|
|
|
|
'quantum_security_groups': config('quantum-security-groups'),
|
2014-07-04 12:49:08 +01:00
|
|
|
'quantum_url': "{}:{}".format(canonical_url(CONFIGS, INTERNAL),
|
2014-06-25 16:24:48 +01:00
|
|
|
str(api_port('neutron-server')))})
|
2013-10-29 19:28:46 -07:00
|
|
|
|
2013-10-30 18:59:34 -07:00
|
|
|
relation_set(relation_id=rid, **rel_settings)
|
2013-10-08 17:51:27 -07:00
|
|
|
|
|
|
|
|
2013-10-14 12:15:50 -07:00
|
|
|
@hooks.hook('nova-vmware-relation-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2013-10-10 09:04:40 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def nova_vmware_relation_changed():
|
|
|
|
CONFIGS.write('/etc/nova/nova.conf')
|
|
|
|
|
|
|
|
|
2013-10-17 20:18:20 +01:00
|
|
|
@hooks.hook('upgrade-charm')
|
|
|
|
def upgrade_charm():
|
2014-04-29 14:44:23 +01:00
|
|
|
apt_install(filter_installed_packages(determine_packages()),
|
|
|
|
fatal=True)
|
2013-10-17 20:18:20 +01:00
|
|
|
for r_id in relation_ids('amqp'):
|
|
|
|
amqp_joined(relation_id=r_id)
|
2014-03-04 17:06:08 +00:00
|
|
|
for r_id in relation_ids('identity-service'):
|
2014-03-04 17:07:06 +00:00
|
|
|
identity_joined(rid=r_id)
|
2014-05-27 14:15:42 +02:00
|
|
|
for r_id in relation_ids('cloud-compute'):
|
|
|
|
for unit in related_units(r_id):
|
|
|
|
compute_changed(r_id, unit)
|
2014-10-29 22:30:36 -05:00
|
|
|
update_nrpe_config()
|
2015-05-22 11:32:59 -03:00
|
|
|
update_nova_consoleauth_config()
|
2013-10-17 20:18:20 +01:00
|
|
|
|
|
|
|
|
2014-09-28 11:56:50 +00:00
|
|
|
# remote_restart is defaulted to true as nova-cells may have started the
|
2014-09-28 14:11:26 +00:00
|
|
|
# nova-cell process before the db migration was run so it will need a
|
|
|
|
# kick
|
2014-05-13 16:44:49 +01:00
|
|
|
@hooks.hook('cell-relation-joined')
|
2014-09-28 11:56:50 +00:00
|
|
|
def nova_cell_relation_joined(rid=None, remote_restart=True):
|
2014-10-07 09:59:18 +00:00
|
|
|
rel_settings = {
|
2014-10-13 17:18:58 +01:00
|
|
|
'nova_url': "%s:8774/v2" % canonical_url(CONFIGS, INTERNAL)
|
2014-10-07 09:59:18 +00:00
|
|
|
}
|
2014-05-04 16:15:41 +00:00
|
|
|
if remote_restart:
|
2014-10-07 09:59:18 +00:00
|
|
|
rel_settings['restart_trigger'] = str(uuid.uuid4())
|
|
|
|
relation_set(relation_id=rid, **rel_settings)
|
2014-04-25 16:46:42 +00:00
|
|
|
|
2014-05-04 09:55:23 -05:00
|
|
|
|
2014-05-13 16:44:49 +01:00
|
|
|
@hooks.hook('cell-relation-changed')
|
2014-10-13 17:18:58 +01:00
|
|
|
@restart_on_change(restart_map())
|
2014-04-25 16:46:42 +00:00
|
|
|
def nova_cell_relation_changed():
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
2014-07-11 10:14:57 +01:00
|
|
|
|
2014-07-14 14:24:30 +00:00
|
|
|
def get_cell_type():
|
2014-09-28 14:11:26 +00:00
|
|
|
cell_info = NovaCellContext()()
|
2014-07-14 14:24:30 +00:00
|
|
|
if 'cell_type' in cell_info:
|
|
|
|
return cell_info['cell_type']
|
|
|
|
return None
|
|
|
|
|
2014-09-28 14:11:26 +00:00
|
|
|
|
2014-05-15 08:25:56 +01:00
|
|
|
@hooks.hook('neutron-api-relation-joined')
|
2014-09-26 15:46:53 +00:00
|
|
|
def neutron_api_relation_joined(rid=None, remote_restart=False):
|
2014-05-15 08:25:56 +01:00
|
|
|
with open('/etc/init/neutron-server.override', 'wb') as out:
|
|
|
|
out.write('manual\n')
|
2014-05-16 10:52:19 +00:00
|
|
|
if os.path.isfile(NEUTRON_CONF):
|
|
|
|
os.rename(NEUTRON_CONF, NEUTRON_CONF + '_unused')
|
2014-05-15 08:25:56 +01:00
|
|
|
if service_running('neutron-server'):
|
|
|
|
service_stop('neutron-server')
|
2014-05-16 10:52:19 +00:00
|
|
|
for id_rid in relation_ids('identity-service'):
|
|
|
|
identity_joined(rid=id_rid)
|
2014-09-26 15:46:53 +00:00
|
|
|
rel_settings = {
|
|
|
|
'nova_url': canonical_url(CONFIGS, INTERNAL) + ":8774/v2"
|
|
|
|
}
|
2014-07-14 14:24:30 +00:00
|
|
|
if get_cell_type():
|
2014-09-28 14:11:26 +00:00
|
|
|
rel_settings['cell_type'] = get_cell_type()
|
2014-09-26 15:46:53 +00:00
|
|
|
if remote_restart:
|
|
|
|
rel_settings['restart_trigger'] = str(uuid.uuid4())
|
|
|
|
relation_set(relation_id=rid, **rel_settings)
|
2014-04-25 16:46:42 +00:00
|
|
|
|
2014-06-20 09:59:07 +01:00
|
|
|
|
2014-05-08 19:36:17 +00:00
|
|
|
@hooks.hook('neutron-api-relation-changed')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2014-05-15 14:58:51 +00:00
|
|
|
@restart_on_change(restart_map())
|
2014-05-08 19:36:17 +00:00
|
|
|
def neutron_api_relation_changed():
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
2014-05-16 09:04:20 +00:00
|
|
|
for rid in relation_ids('cloud-compute'):
|
|
|
|
compute_joined(rid=rid)
|
2014-05-21 14:38:01 +00:00
|
|
|
for rid in relation_ids('quantum-network-service'):
|
|
|
|
quantum_joined(rid=rid)
|
2014-05-08 19:36:17 +00:00
|
|
|
|
2014-06-20 09:59:07 +01:00
|
|
|
|
2014-05-15 08:25:56 +01:00
|
|
|
@hooks.hook('neutron-api-relation-broken')
|
2014-07-29 12:50:07 +01:00
|
|
|
@service_guard(guard_map(), CONFIGS,
|
|
|
|
active=config('service-guard'))
|
2014-05-15 14:58:51 +00:00
|
|
|
@restart_on_change(restart_map())
|
2014-05-15 08:25:56 +01:00
|
|
|
def neutron_api_relation_broken():
|
|
|
|
if os.path.isfile('/etc/init/neutron-server.override'):
|
|
|
|
os.remove('/etc/init/neutron-server.override')
|
2014-05-15 14:58:51 +00:00
|
|
|
CONFIGS.write_all()
|
2014-05-21 14:47:14 +00:00
|
|
|
for rid in relation_ids('cloud-compute'):
|
|
|
|
compute_joined(rid=rid)
|
|
|
|
for rid in relation_ids('quantum-network-service'):
|
|
|
|
quantum_joined(rid=rid)
|
2013-10-17 20:18:20 +01:00
|
|
|
|
2014-06-20 09:59:07 +01:00
|
|
|
|
2014-09-09 13:01:37 +00:00
|
|
|
@hooks.hook('zeromq-configuration-relation-joined')
|
2015-03-16 16:13:02 +00:00
|
|
|
@os_requires_version('kilo', 'nova-common')
|
2014-09-09 13:01:37 +00:00
|
|
|
def zeromq_configuration_relation_joined(relid=None):
|
|
|
|
relation_set(relation_id=relid,
|
|
|
|
topics=" ".join(get_topics()),
|
|
|
|
users="nova")
|
|
|
|
|
|
|
|
|
2014-11-18 11:21:15 +10:00
|
|
|
@hooks.hook('nrpe-external-master-relation-joined',
|
|
|
|
'nrpe-external-master-relation-changed')
|
2014-10-29 22:30:36 -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:36 -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:29:22 +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:29:22 +10:00
|
|
|
nrpe.add_haproxy_checks(nrpe_setup, current_unit)
|
2015-01-12 12:04:00 +00:00
|
|
|
nrpe_setup.write()
|
2014-06-20 09:59:07 +01:00
|
|
|
|
2015-01-09 15:50:01 +00:00
|
|
|
|
2014-11-20 13:51:44 -03:00
|
|
|
@hooks.hook('memcache-relation-joined',
|
|
|
|
'memcache-relation-departed',
|
|
|
|
'memcache-relation-changed',
|
|
|
|
'memcache-relation-broken')
|
2014-10-24 10:20:36 -03:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def memcached_joined():
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
|
|
|
|
2014-09-09 13:01:37 +00:00
|
|
|
@hooks.hook('zeromq-configuration-relation-changed')
|
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
|
|
|
def zeromq_configuration_relation_changed():
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
|
|
|
|
2015-05-22 11:32:59 -03:00
|
|
|
def update_nova_consoleauth_config():
|
|
|
|
"""
|
|
|
|
Configure nova-consoleauth pacemaker resources
|
|
|
|
"""
|
|
|
|
relids = relation_ids('ha')
|
|
|
|
if len(relids) == 0:
|
|
|
|
log('Related to {} ha services'.format(len(relids)), level='DEBUG')
|
|
|
|
ha_relid = None
|
|
|
|
data = {}
|
|
|
|
else:
|
|
|
|
ha_relid = relids[0]
|
|
|
|
data = relation_get(rid=ha_relid) or {}
|
|
|
|
|
|
|
|
# initialize keys in case this is a new dict
|
|
|
|
data.setdefault('delete_resources', [])
|
|
|
|
for k in ['colocations', 'init_services', 'resources', 'resource_params']:
|
|
|
|
data.setdefault(k, {})
|
|
|
|
|
|
|
|
if config('single-nova-consoleauth') and console_attributes('protocol'):
|
|
|
|
for item in ['vip_consoleauth', 'res_nova_consoleauth']:
|
|
|
|
try:
|
|
|
|
data['delete_resources'].remove(item)
|
|
|
|
except ValueError:
|
|
|
|
pass # nothing to remove, we are good
|
|
|
|
|
|
|
|
# the new pcmkr resources have to be added to the existing ones
|
|
|
|
data['colocations']['vip_consoleauth'] = COLO_CONSOLEAUTH
|
|
|
|
data['init_services']['res_nova_consoleauth'] = 'nova-consoleauth'
|
|
|
|
data['resources']['res_nova_consoleauth'] = AGENT_CONSOLEAUTH
|
|
|
|
data['resource_params']['res_nova_consoleauth'] = AGENT_CA_PARAMS
|
|
|
|
|
|
|
|
for rid in relation_ids('ha'):
|
|
|
|
relation_set(rid, **data)
|
|
|
|
|
|
|
|
# nova-consoleauth will be managed by pacemaker, so mark it as manual
|
2015-05-22 15:19:15 -03:00
|
|
|
if relation_ids('ha'):
|
|
|
|
with open(NOVA_CONSOLEAUTH_OVERRIDE, 'w') as fp:
|
|
|
|
fp.write('manual\n')
|
|
|
|
fp.flush()
|
2015-05-22 11:32:59 -03:00
|
|
|
|
|
|
|
elif (not config('single-nova-consoleauth')
|
|
|
|
and console_attributes('protocol')):
|
|
|
|
for item in ['vip_consoleauth', 'res_nova_consoleauth']:
|
|
|
|
if item not in data['delete_resources']:
|
|
|
|
data['delete_resources'].append(item)
|
|
|
|
|
|
|
|
# remove them from the rel, so they aren't recreated when the hook
|
|
|
|
# is recreated
|
|
|
|
data['colocations'].pop('vip_consoleauth', None)
|
|
|
|
data['init_services'].pop('res_nova_consoleauth', None)
|
|
|
|
data['resources'].pop('res_nova_consoleauth', None)
|
|
|
|
data['resource_params'].pop('res_nova_consoleauth', None)
|
|
|
|
|
|
|
|
for rid in relation_ids('ha'):
|
|
|
|
relation_set(rid, **data)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.remove(NOVA_CONSOLEAUTH_OVERRIDE)
|
|
|
|
except FileNotFoundError as e:
|
|
|
|
log(str(e), level='DEBUG')
|
|
|
|
|
|
|
|
|
2013-08-01 20:42:16 -07:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
|
|
|
log('Unknown hook {} - skipping.'.format(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|