2019-03-13 12:29:17 +00:00
|
|
|
#!/usr/bin/env python3
|
2016-06-22 15:25:52 +01:00
|
|
|
#
|
|
|
|
# Copyright 2016 Canonical Ltd
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
2013-10-14 17:10:30 +01:00
|
|
|
|
2013-11-29 15:34:44 +00:00
|
|
|
import json
|
2019-03-13 12:29:17 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
_path = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
_root = os.path.abspath(os.path.join(_path, '..'))
|
|
|
|
|
|
|
|
|
|
|
|
def _add_path(path):
|
|
|
|
if path not in sys.path:
|
|
|
|
sys.path.insert(1, path)
|
|
|
|
|
|
|
|
|
|
|
|
_add_path(_root)
|
|
|
|
|
|
|
|
|
2013-10-14 17:10:30 +01:00
|
|
|
from charmhelpers.fetch import (
|
|
|
|
apt_install, filter_installed_packages,
|
|
|
|
apt_update
|
|
|
|
)
|
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks, UnregisteredHookError,
|
2013-11-29 15:34:44 +00:00
|
|
|
log,
|
2015-04-14 13:06:52 -03:00
|
|
|
is_relation_made,
|
2014-11-18 15:51:05 +10:00
|
|
|
relation_set,
|
2015-10-09 02:59:01 +00:00
|
|
|
status_set,
|
2017-07-31 13:16:44 +01:00
|
|
|
relation_ids,
|
2019-02-26 14:35:53 +01:00
|
|
|
config,
|
2013-10-14 17:10:30 +01:00
|
|
|
)
|
2018-11-15 14:12:22 +00:00
|
|
|
from charmhelpers.core.host import (
|
|
|
|
service_restart
|
|
|
|
)
|
2013-10-18 16:58:17 +01:00
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
2016-03-18 15:52:44 +00:00
|
|
|
pausable_restart_on_change as restart_on_change,
|
2013-10-18 16:58:17 +01:00
|
|
|
)
|
|
|
|
from ceilometer_utils import (
|
|
|
|
restart_map,
|
2014-11-18 15:51:05 +10:00
|
|
|
services,
|
2013-10-18 16:58:17 +01:00
|
|
|
register_configs,
|
2014-04-01 17:53:45 +01:00
|
|
|
NOVA_SETTINGS,
|
2016-03-18 15:52:44 +00:00
|
|
|
assess_status,
|
2016-12-09 14:01:14 +00:00
|
|
|
get_packages,
|
2021-09-28 14:19:08 +02:00
|
|
|
releases_packages_map,
|
2018-11-15 14:12:22 +00:00
|
|
|
remove_old_packages,
|
2013-10-14 17:10:30 +01:00
|
|
|
)
|
2015-01-26 08:00:21 +00:00
|
|
|
from charmhelpers.contrib.charmsupport import nrpe
|
2014-11-18 15:51:05 +10:00
|
|
|
|
2013-10-14 17:10:30 +01:00
|
|
|
hooks = Hooks()
|
2013-10-18 16:58:17 +01:00
|
|
|
CONFIGS = register_configs()
|
2013-10-14 17:10:30 +01:00
|
|
|
|
|
|
|
|
2017-11-24 09:21:44 +00:00
|
|
|
@hooks.hook('install.real')
|
2013-10-14 17:10:30 +01:00
|
|
|
def install():
|
2015-10-09 02:59:01 +00:00
|
|
|
status_set('maintenance', 'Installing apt packages')
|
2013-10-14 17:10:30 +01:00
|
|
|
apt_update(fatal=True)
|
2018-10-17 12:07:16 +01:00
|
|
|
# Install -common package so we get accurate version determination
|
|
|
|
apt_install(filter_installed_packages(['ceilometer-common']),
|
|
|
|
fatal=True)
|
2016-12-09 14:01:14 +00:00
|
|
|
apt_install(
|
|
|
|
filter_installed_packages(get_packages()),
|
|
|
|
fatal=True)
|
2013-10-14 17:10:30 +01:00
|
|
|
|
2013-11-29 15:34:44 +00:00
|
|
|
|
|
|
|
@hooks.hook('nova-ceilometer-relation-joined')
|
2017-07-31 13:16:44 +01:00
|
|
|
def nova_ceilometer_joined(relation_id=None):
|
2021-09-28 14:19:08 +02:00
|
|
|
relation_set(
|
|
|
|
relation_id=relation_id,
|
|
|
|
relation_settings={
|
|
|
|
'subordinate_configuration': json.dumps(NOVA_SETTINGS),
|
|
|
|
'releases-packages-map': json.dumps(
|
|
|
|
releases_packages_map(), sort_keys=True),
|
|
|
|
'services': json.dumps(services())
|
|
|
|
})
|
2013-10-14 17:10:30 +01:00
|
|
|
|
|
|
|
|
2017-02-16 11:17:53 -08:00
|
|
|
@hooks.hook("ceilometer-service-relation-changed")
|
2013-10-18 16:58:17 +01:00
|
|
|
@restart_on_change(restart_map())
|
2013-10-14 17:10:30 +01:00
|
|
|
def ceilometer_changed():
|
2013-10-18 16:58:17 +01:00
|
|
|
CONFIGS.write_all()
|
2015-04-14 13:06:52 -03:00
|
|
|
if is_relation_made('nrpe-external-master'):
|
|
|
|
update_nrpe_config()
|
2013-10-14 17:10:30 +01:00
|
|
|
|
|
|
|
|
2017-02-16 11:17:53 -08:00
|
|
|
@hooks.hook("upgrade-charm")
|
|
|
|
def upgrade_charm():
|
|
|
|
apt_install(
|
|
|
|
filter_installed_packages(get_packages()),
|
|
|
|
fatal=True)
|
2021-11-29 15:17:44 +01:00
|
|
|
|
2018-11-15 14:12:22 +00:00
|
|
|
packages_removed = remove_old_packages()
|
2021-11-29 15:17:44 +01:00
|
|
|
if packages_removed:
|
|
|
|
# NOTE(lourot): this code path is run when python2 packages have been
|
|
|
|
# purged and python3 packages installed. In this case it is best to
|
|
|
|
# restart the ceilometer-agent-compute service.
|
2018-11-15 14:12:22 +00:00
|
|
|
log("Package purge detected, restarting services", "INFO")
|
|
|
|
for s in services():
|
2021-11-29 15:17:44 +01:00
|
|
|
# NOTE(lourot): if the principal nova-compute unit is paused, the
|
|
|
|
# ceilometer-agent-compute service, depending on the nova-compute
|
|
|
|
# service, will refuse to start, but this call won't raise. It'll
|
|
|
|
# just return False. This can safely be ignored: all services will
|
|
|
|
# finally be started when unpausing nova-compute.
|
2018-11-15 14:12:22 +00:00
|
|
|
service_restart(s)
|
2021-11-29 15:17:44 +01:00
|
|
|
|
2017-07-31 13:16:44 +01:00
|
|
|
# NOTE(jamespage): Ensure any changes to nova presented data are made
|
|
|
|
# during charm upgrades.
|
|
|
|
for rid in relation_ids('nova-ceilometer'):
|
|
|
|
nova_ceilometer_joined(rid)
|
2017-02-16 11:17:53 -08:00
|
|
|
|
|
|
|
|
2018-11-11 15:52:22 +00:00
|
|
|
@hooks.hook('nova-ceilometer-relation-changed')
|
2014-04-01 17:53:45 +01:00
|
|
|
@hooks.hook('config-changed')
|
|
|
|
@restart_on_change(restart_map(), stopstart=True)
|
|
|
|
def config_changed():
|
2018-11-11 15:52:22 +00:00
|
|
|
apt_install(filter_installed_packages(get_packages()), fatal=True)
|
2015-04-14 13:06:52 -03:00
|
|
|
if is_relation_made('nrpe-external-master'):
|
|
|
|
update_nrpe_config()
|
2014-04-01 17:53:45 +01:00
|
|
|
CONFIGS.write_all()
|
|
|
|
|
2014-11-18 15:51:05 +10:00
|
|
|
|
|
|
|
@hooks.hook('nrpe-external-master-relation-joined',
|
|
|
|
'nrpe-external-master-relation-changed')
|
|
|
|
def update_nrpe_config():
|
2015-01-26 08:00:21 +00:00
|
|
|
# python-dbus is used by check_upstart_job
|
2014-11-18 15:51:05 +10:00
|
|
|
apt_install('python-dbus')
|
2015-01-26 08:00:21 +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-11-18 15:51:05 +10:00
|
|
|
|
|
|
|
|
2019-02-26 14:35:53 +01:00
|
|
|
@hooks.hook('amqp-relation-joined')
|
|
|
|
def amqp_joined(relation_id=None):
|
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
username=config('rabbit-user'),
|
|
|
|
vhost=config('rabbit-vhost'))
|
|
|
|
|
|
|
|
|
2019-07-24 10:36:28 +01:00
|
|
|
@hooks.hook('update-status')
|
|
|
|
def dummy_update_status():
|
|
|
|
"""Dummy function to silence missing hook log entry"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-02-26 14:35:53 +01:00
|
|
|
@hooks.hook('amqp-relation-changed',
|
|
|
|
'amqp-relation-departed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def amqp_changed():
|
|
|
|
if 'amqp' not in CONFIGS.complete_contexts():
|
|
|
|
log('amqp relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
|
2013-10-14 17:10:30 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
|
|
|
log('Unknown hook {} - skipping.'.format(e))
|
2016-03-18 15:52:44 +00:00
|
|
|
# set_os_workload_status(CONFIGS, REQUIRED_INTERFACES)
|
|
|
|
assess_status(CONFIGS)
|