2017-11-05 12:47:42 +11:00
|
|
|
#!/usr/bin/env python3
|
2016-07-01 17:43:29 +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.
|
|
|
|
|
2018-04-26 12:52:35 +01:00
|
|
|
import base64
|
|
|
|
import json
|
2016-04-04 14:06:37 +00:00
|
|
|
import platform
|
2013-07-30 20:39:44 -07:00
|
|
|
import sys
|
2016-04-18 17:32:19 +00:00
|
|
|
import uuid
|
2017-02-09 11:57:45 +00:00
|
|
|
import yaml
|
2017-03-09 12:51:25 +00:00
|
|
|
import os
|
2018-04-26 12:52:35 +01:00
|
|
|
import subprocess
|
2018-07-03 13:31:56 +02:00
|
|
|
import grp
|
|
|
|
import shutil
|
2013-07-18 19:37:30 -07:00
|
|
|
|
2017-02-07 10:12:11 +01:00
|
|
|
|
|
|
|
import charmhelpers.core.unitdata as unitdata
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
from charmhelpers.core.hookenv import (
|
|
|
|
Hooks,
|
|
|
|
config,
|
2014-03-25 10:12:03 +01:00
|
|
|
is_relation_made,
|
2018-06-14 10:12:28 +00:00
|
|
|
local_unit,
|
2013-07-18 19:37:30 -07:00
|
|
|
log,
|
|
|
|
relation_ids,
|
2017-03-09 12:51:25 +00:00
|
|
|
remote_service_name,
|
2016-02-09 15:55:14 +00:00
|
|
|
related_units,
|
2013-09-03 17:16:15 -07:00
|
|
|
relation_get,
|
2013-07-18 19:37:30 -07:00
|
|
|
relation_set,
|
|
|
|
service_name,
|
2013-07-30 20:39:44 -07:00
|
|
|
UnregisteredHookError,
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
2017-03-09 12:51:25 +00:00
|
|
|
from charmhelpers.core.templating import (
|
|
|
|
render
|
|
|
|
)
|
2013-07-18 19:37:30 -07:00
|
|
|
from charmhelpers.core.host import (
|
2015-03-03 12:57:50 +00:00
|
|
|
service_restart,
|
2018-08-06 15:45:10 -07:00
|
|
|
service_stop,
|
2018-04-26 12:52:35 +01:00
|
|
|
write_file,
|
|
|
|
umount,
|
2013-09-20 17:40:54 +01:00
|
|
|
)
|
|
|
|
from charmhelpers.fetch import (
|
2013-07-18 19:37:30 -07:00
|
|
|
apt_install,
|
2015-03-02 14:55:03 +00:00
|
|
|
apt_purge,
|
2013-07-18 19:37:30 -07:00
|
|
|
apt_update,
|
2013-08-01 12:53:09 -07:00
|
|
|
filter_installed_packages,
|
2018-04-26 12:52:35 +01:00
|
|
|
add_source,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
|
|
|
configure_installation_source,
|
|
|
|
openstack_upgrade_available,
|
2016-04-01 11:47:46 +00:00
|
|
|
is_unit_paused_set,
|
|
|
|
pausable_restart_on_change as restart_on_change,
|
2018-08-06 15:45:10 -07:00
|
|
|
series_upgrade_prepare,
|
|
|
|
series_upgrade_complete,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
|
|
|
|
2014-11-19 17:53:16 -06:00
|
|
|
from charmhelpers.contrib.storage.linux.ceph import (
|
|
|
|
ensure_ceph_keyring,
|
|
|
|
CephBrokerRq,
|
2015-02-06 13:09:18 -05:00
|
|
|
delete_keyring,
|
2015-08-27 09:04:55 +00:00
|
|
|
send_request_if_needed,
|
2015-09-07 09:43:08 +01:00
|
|
|
is_request_complete,
|
2017-06-07 18:39:10 +01:00
|
|
|
is_broker_action_done,
|
|
|
|
mark_broker_action_done,
|
2014-11-19 17:53:16 -06:00
|
|
|
)
|
2013-09-27 17:20:42 +01:00
|
|
|
from charmhelpers.payload.execd import execd_preinstall
|
2013-07-18 19:37:30 -07:00
|
|
|
from nova_compute_utils import (
|
2013-09-03 17:16:15 -07:00
|
|
|
create_libvirt_secret,
|
2013-07-18 21:41:07 -07:00
|
|
|
determine_packages,
|
2013-07-18 19:37:30 -07:00
|
|
|
import_authorized_keys,
|
|
|
|
import_keystone_ca_cert,
|
2013-07-30 20:39:44 -07:00
|
|
|
initialize_ssh_keys,
|
2013-07-18 19:37:30 -07:00
|
|
|
migration_enabled,
|
|
|
|
do_openstack_upgrade,
|
|
|
|
public_ssh_key,
|
2013-07-18 21:41:07 -07:00
|
|
|
restart_map,
|
2014-11-17 13:45:12 +10:00
|
|
|
services,
|
2013-07-18 19:37:30 -07:00
|
|
|
register_configs,
|
2013-09-20 17:50:33 +01:00
|
|
|
NOVA_CONF,
|
2013-12-16 12:33:45 +00:00
|
|
|
ceph_config_file, CEPH_SECRET,
|
2017-03-09 12:51:25 +00:00
|
|
|
CEPH_BACKEND_SECRET,
|
2014-02-19 16:03:50 +10:00
|
|
|
enable_shell, disable_shell,
|
2015-02-11 13:20:35 -05:00
|
|
|
configure_lxd,
|
2014-05-06 21:58:56 +00:00
|
|
|
fix_path_ownership,
|
2014-10-15 06:51:47 +00:00
|
|
|
assert_charm_supports_ipv6,
|
2015-08-13 10:11:23 +01:00
|
|
|
install_hugepages,
|
2015-11-25 12:48:50 +00:00
|
|
|
get_hugepage_number,
|
2016-04-01 11:47:46 +00:00
|
|
|
assess_status,
|
2016-04-04 14:06:37 +00:00
|
|
|
set_ppc64_cpu_smt_state,
|
2016-07-10 10:59:47 +08:00
|
|
|
destroy_libvirt_network,
|
2016-04-21 15:14:23 -07:00
|
|
|
network_manager,
|
2016-09-14 11:40:57 +01:00
|
|
|
libvirt_daemon,
|
2017-03-29 14:31:46 +01:00
|
|
|
LIBVIRT_TYPES,
|
2018-04-26 12:52:35 +01:00
|
|
|
configure_local_ephemeral_storage,
|
2018-08-06 15:45:10 -07:00
|
|
|
pause_unit_helper,
|
|
|
|
resume_unit_helper,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
|
|
|
|
2014-09-17 14:49:43 +08:00
|
|
|
from charmhelpers.contrib.network.ip import (
|
2017-03-07 08:33:13 -08:00
|
|
|
get_relation_ip,
|
2013-07-18 19:37:30 -07:00
|
|
|
)
|
|
|
|
|
2015-09-23 13:11:45 +01:00
|
|
|
from charmhelpers.core.unitdata import kv
|
|
|
|
|
2014-11-11 22:28:08 +00:00
|
|
|
from nova_compute_context import (
|
2016-06-29 23:51:25 +01:00
|
|
|
nova_metadata_requirement,
|
2014-11-11 22:28:08 +00:00
|
|
|
CEPH_SECRET_UUID,
|
2016-04-21 15:14:23 -07:00
|
|
|
assert_libvirt_rbd_imagebackend_allowed,
|
|
|
|
NovaAPIAppArmorContext,
|
|
|
|
NovaComputeAppArmorContext,
|
|
|
|
NovaNetworkAppArmorContext,
|
2014-11-11 22:28:08 +00:00
|
|
|
)
|
2015-01-12 12:04:00 +00:00
|
|
|
from charmhelpers.contrib.charmsupport import nrpe
|
2014-11-26 10:39:42 -03:00
|
|
|
from charmhelpers.core.sysctl import create as create_sysctl
|
2016-03-22 21:00:45 +00:00
|
|
|
from charmhelpers.contrib.hardening.harden import harden
|
2014-11-26 10:39:42 -03:00
|
|
|
|
2014-06-12 10:40:30 +01:00
|
|
|
from socket import gethostname
|
2013-09-03 17:16:15 -07:00
|
|
|
|
2018-04-26 12:52:35 +01:00
|
|
|
import charmhelpers.contrib.openstack.vaultlocker as vaultlocker
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
hooks = Hooks()
|
|
|
|
CONFIGS = register_configs()
|
2017-09-22 13:25:42 +00:00
|
|
|
MIGRATION_AUTH_TYPES = ["ssh"]
|
2018-08-06 15:45:10 -07:00
|
|
|
LIBVIRTD_PID = '/var/run/libvirtd.pid'
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
2015-09-22 14:53:11 +01:00
|
|
|
@hooks.hook('install.real')
|
2016-03-22 21:00:45 +00:00
|
|
|
@harden()
|
2013-07-18 19:37:30 -07:00
|
|
|
def install():
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set('maintenance', 'Executing pre-install')
|
2013-09-27 17:20:42 +01:00
|
|
|
execd_preinstall()
|
2013-07-18 19:37:30 -07:00
|
|
|
configure_installation_source(config('openstack-origin'))
|
2015-04-15 14:21:42 +00:00
|
|
|
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set('maintenance', 'Installing apt packages')
|
2013-07-18 19:37:30 -07:00
|
|
|
apt_update()
|
2013-07-18 21:41:07 -07:00
|
|
|
apt_install(determine_packages(), fatal=True)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('config-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2016-03-22 21:00:45 +00:00
|
|
|
@harden()
|
2013-07-18 19:37:30 -07:00
|
|
|
def config_changed():
|
2018-08-06 15:45:10 -07:00
|
|
|
|
|
|
|
if is_unit_paused_set():
|
|
|
|
log("Do not run config_changed when paused", "WARNING")
|
|
|
|
return
|
|
|
|
|
2018-04-26 12:52:35 +01:00
|
|
|
if config('ephemeral-unmount'):
|
|
|
|
umount(config('ephemeral-unmount'), persist=True)
|
|
|
|
|
2014-09-18 20:55:05 +08:00
|
|
|
if config('prefer-ipv6'):
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set('maintenance', 'configuring ipv6')
|
2014-09-26 19:20:20 +01:00
|
|
|
assert_charm_supports_ipv6()
|
2014-09-18 20:55:05 +08:00
|
|
|
|
2017-09-22 13:25:42 +00:00
|
|
|
if (migration_enabled() and
|
|
|
|
config('migration-auth-type') not in MIGRATION_AUTH_TYPES):
|
|
|
|
message = ("Invalid migration-auth-type")
|
|
|
|
status_set('blocked', message)
|
|
|
|
raise Exception(message)
|
2014-04-01 17:01:37 +01:00
|
|
|
global CONFIGS
|
2016-04-18 17:32:19 +00:00
|
|
|
send_remote_restart = False
|
2017-12-21 14:55:43 +00:00
|
|
|
if not config('action-managed-upgrade'):
|
2015-04-15 14:21:42 +00:00
|
|
|
if openstack_upgrade_available('nova-common'):
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set('maintenance', 'Running openstack upgrade')
|
2015-10-06 15:38:12 +00:00
|
|
|
do_openstack_upgrade(CONFIGS)
|
2016-04-18 17:32:19 +00:00
|
|
|
send_remote_restart = True
|
2013-07-18 19:37:30 -07:00
|
|
|
|
2017-02-09 11:57:45 +00:00
|
|
|
sysctl_settings = config('sysctl')
|
|
|
|
if sysctl_settings:
|
|
|
|
sysctl_dict = yaml.safe_load(sysctl_settings)
|
|
|
|
sysctl_dict['vm.swappiness'] = sysctl_dict.get('vm.swappiness', 1)
|
|
|
|
create_sysctl(yaml.dump(sysctl_dict),
|
|
|
|
'/etc/sysctl.d/50-nova-compute.conf')
|
2014-11-26 10:39:42 -03:00
|
|
|
|
2016-07-12 16:25:06 +02:00
|
|
|
destroy_libvirt_network('default')
|
2016-07-10 10:59:47 +08:00
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
if migration_enabled() and config('migration-auth-type') == 'ssh':
|
|
|
|
# Check-in with nova-c-c and register new ssh key, if it has just been
|
|
|
|
# generated.
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set('maintenance', 'SSH key exchange')
|
2013-07-30 20:39:44 -07:00
|
|
|
initialize_ssh_keys()
|
2014-04-03 17:18:05 +01:00
|
|
|
import_authorized_keys()
|
2013-12-16 10:10:19 +00:00
|
|
|
|
|
|
|
if config('enable-resize') is True:
|
2013-12-16 12:33:45 +00:00
|
|
|
enable_shell(user='nova')
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set('maintenance', 'SSH key exchange')
|
2013-12-16 10:10:19 +00:00
|
|
|
initialize_ssh_keys(user='nova')
|
2014-04-03 17:48:13 +01:00
|
|
|
import_authorized_keys(user='nova', prefix='nova')
|
2013-12-16 12:33:45 +00:00
|
|
|
else:
|
|
|
|
disable_shell(user='nova')
|
2013-12-16 10:10:19 +00:00
|
|
|
|
2014-03-31 16:30:14 +01:00
|
|
|
if config('instances-path') is not None:
|
2014-02-19 14:40:50 +10:00
|
|
|
fp = config('instances-path')
|
2014-02-19 14:53:05 +10:00
|
|
|
fix_path_ownership(fp, user='nova')
|
2014-02-19 14:40:50 +10:00
|
|
|
|
2013-12-16 10:10:19 +00:00
|
|
|
[compute_joined(rid) for rid in relation_ids('cloud-compute')]
|
2013-07-18 19:37:30 -07:00
|
|
|
|
2015-11-25 12:48:50 +00:00
|
|
|
for rid in relation_ids('neutron-plugin'):
|
2016-04-18 17:32:19 +00:00
|
|
|
neutron_plugin_joined(rid, remote_restart=send_remote_restart)
|
2015-11-25 12:48:50 +00:00
|
|
|
|
2015-04-24 10:43:58 -03:00
|
|
|
if is_relation_made("nrpe-external-master"):
|
|
|
|
update_nrpe_config()
|
2014-10-29 22:30:36 -05:00
|
|
|
|
2015-08-19 15:07:10 +00:00
|
|
|
if config('hugepages'):
|
|
|
|
install_hugepages()
|
2015-08-13 10:11:23 +01:00
|
|
|
|
2016-04-04 14:06:37 +00:00
|
|
|
# Disable smt for ppc64, required for nova/libvirt/kvm
|
|
|
|
arch = platform.machine()
|
|
|
|
log('CPU architecture: {}'.format(arch))
|
|
|
|
if arch in ['ppc64el', 'ppc64le']:
|
|
|
|
set_ppc64_cpu_smt_state('off')
|
|
|
|
|
2017-02-14 12:26:48 +00:00
|
|
|
# NOTE(jamespage): trigger any configuration related changes
|
2017-03-29 14:31:46 +01:00
|
|
|
# for cephx permissions restrictions and
|
|
|
|
# keys on disk for ceph-access backends
|
2017-02-14 12:26:48 +00:00
|
|
|
for rid in relation_ids('ceph'):
|
|
|
|
for unit in related_units(rid):
|
|
|
|
ceph_changed(rid=rid, unit=unit)
|
2017-03-29 14:31:46 +01:00
|
|
|
for rid in relation_ids('ceph-access'):
|
|
|
|
for unit in related_units(rid):
|
|
|
|
ceph_access(rid=rid, unit=unit)
|
2016-02-09 15:55:14 +00:00
|
|
|
|
2013-07-30 19:40:47 -07:00
|
|
|
CONFIGS.write_all()
|
|
|
|
|
2016-04-21 15:14:23 -07:00
|
|
|
NovaComputeAppArmorContext().setup_aa_profile()
|
|
|
|
if (network_manager() in ['flatmanager', 'flatdhcpmanager'] and
|
|
|
|
config('multi-host').lower() == 'yes'):
|
|
|
|
NovaAPIAppArmorContext().setup_aa_profile()
|
|
|
|
NovaNetworkAppArmorContext().setup_aa_profile()
|
|
|
|
|
2018-04-26 12:52:35 +01:00
|
|
|
install_vaultlocker()
|
|
|
|
|
|
|
|
configure_local_ephemeral_storage()
|
|
|
|
|
|
|
|
|
|
|
|
def install_vaultlocker():
|
|
|
|
"""Determine whether vaultlocker is required and install"""
|
|
|
|
if config('encrypt'):
|
|
|
|
installed = len(filter_installed_packages(['vaultlocker'])) == 0
|
|
|
|
if not installed:
|
|
|
|
add_source('ppa:openstack-charmers/vaultlocker')
|
|
|
|
apt_update(fatal=True)
|
|
|
|
apt_install('vaultlocker', fatal=True)
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-joined')
|
2013-10-17 20:25:15 +01:00
|
|
|
def amqp_joined(relation_id=None):
|
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
username=config('rabbit-user'),
|
|
|
|
vhost=config('rabbit-vhost'))
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('amqp-relation-changed')
|
2014-01-30 12:46:46 +01:00
|
|
|
@hooks.hook('amqp-relation-departed')
|
|
|
|
@restart_on_change(restart_map())
|
2014-02-13 09:49:17 +01:00
|
|
|
def amqp_changed():
|
2014-01-30 12:46:46 +01:00
|
|
|
if 'amqp' not in CONFIGS.complete_contexts():
|
|
|
|
log('amqp relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
@hooks.hook('image-service-relation-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def image_service_changed():
|
|
|
|
if 'image-service' not in CONFIGS.complete_contexts():
|
|
|
|
log('image-service relation incomplete. Peer not ready?')
|
|
|
|
return
|
2013-09-20 17:50:33 +01:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
2016-06-17 18:38:26 +03:00
|
|
|
@hooks.hook('ephemeral-backend-relation-changed',
|
|
|
|
'ephemeral-backend-relation-broken')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def ephemeral_backend_hook():
|
|
|
|
if 'ephemeral-backend' not in CONFIGS.complete_contexts():
|
|
|
|
log('ephemeral-backend relation incomplete. Peer not ready?')
|
|
|
|
return
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
@hooks.hook('cloud-compute-relation-joined')
|
|
|
|
def compute_joined(rid=None):
|
2014-06-12 10:40:30 +01:00
|
|
|
# NOTE(james-page) in MAAS environments the actual hostname is a CNAME
|
|
|
|
# record so won't get scanned based on private-address which is an IP
|
|
|
|
# add the hostname configured locally to the relation.
|
|
|
|
settings = {
|
2017-03-07 08:33:13 -08:00
|
|
|
'hostname': gethostname(),
|
2017-07-05 16:58:00 +08:00
|
|
|
'private-address': get_relation_ip(
|
|
|
|
'cloud-compute', cidr_network=config('os-internal-network')),
|
2014-06-12 10:40:30 +01:00
|
|
|
}
|
2017-03-07 08:33:13 -08:00
|
|
|
|
2013-12-16 10:10:19 +00:00
|
|
|
if migration_enabled():
|
|
|
|
auth_type = config('migration-auth-type')
|
2014-06-12 10:40:30 +01:00
|
|
|
settings['migration_auth_type'] = auth_type
|
2013-12-16 10:10:19 +00:00
|
|
|
if auth_type == 'ssh':
|
|
|
|
settings['ssh_public_key'] = public_ssh_key()
|
|
|
|
relation_set(relation_id=rid, **settings)
|
|
|
|
if config('enable-resize'):
|
2014-06-12 10:40:30 +01:00
|
|
|
settings['nova_ssh_public_key'] = public_ssh_key(user='nova')
|
2013-12-16 10:10:19 +00:00
|
|
|
relation_set(relation_id=rid, **settings)
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('cloud-compute-relation-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def compute_changed():
|
2013-07-30 19:40:47 -07:00
|
|
|
# rewriting all configs to pick up possible net or vol manager
|
|
|
|
# config advertised from controller.
|
|
|
|
CONFIGS.write_all()
|
2013-07-18 19:37:30 -07:00
|
|
|
import_authorized_keys()
|
2013-12-16 10:10:19 +00:00
|
|
|
import_authorized_keys(user='nova', prefix='nova')
|
2013-07-18 19:37:30 -07:00
|
|
|
import_keystone_ca_cert()
|
|
|
|
|
|
|
|
|
2017-03-29 14:31:46 +01:00
|
|
|
@hooks.hook('ceph-access-relation-joined')
|
2013-07-18 19:37:30 -07:00
|
|
|
@hooks.hook('ceph-relation-joined')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2013-07-18 19:37:30 -07:00
|
|
|
def ceph_joined():
|
2017-03-29 14:31:46 +01:00
|
|
|
pkgs = filter_installed_packages(['ceph-common'])
|
|
|
|
if pkgs:
|
|
|
|
status_set('maintenance', 'Installing ceph-common package')
|
|
|
|
apt_install(pkgs, fatal=True)
|
|
|
|
# Bug 1427660
|
|
|
|
if not is_unit_paused_set() and config('virt-type') in LIBVIRT_TYPES:
|
|
|
|
service_restart(libvirt_daemon())
|
2013-07-18 19:37:30 -07:00
|
|
|
|
|
|
|
|
2015-08-27 09:04:55 +00:00
|
|
|
def get_ceph_request():
|
|
|
|
rq = CephBrokerRq()
|
2017-02-14 12:26:48 +00:00
|
|
|
if (config('libvirt-image-backend') == 'rbd' and
|
|
|
|
assert_libvirt_rbd_imagebackend_allowed()):
|
|
|
|
name = config('rbd-pool')
|
|
|
|
replicas = config('ceph-osd-replication-count')
|
|
|
|
weight = config('ceph-pool-weight')
|
|
|
|
rq.add_op_create_pool(name=name, replica_count=replicas, weight=weight,
|
|
|
|
group='vms')
|
|
|
|
if config('restrict-ceph-pools'):
|
2018-05-31 17:04:33 +02:00
|
|
|
rq.add_op_request_access_to_group(
|
|
|
|
name="volumes",
|
|
|
|
object_prefix_permissions={'class-read': ['rbd_children']},
|
|
|
|
permission='rwx')
|
|
|
|
rq.add_op_request_access_to_group(
|
|
|
|
name="images",
|
|
|
|
object_prefix_permissions={'class-read': ['rbd_children']},
|
|
|
|
permission='rwx')
|
|
|
|
rq.add_op_request_access_to_group(
|
|
|
|
name="vms",
|
|
|
|
object_prefix_permissions={'class-read': ['rbd_children']},
|
|
|
|
permission='rwx')
|
2015-08-27 09:04:55 +00:00
|
|
|
return rq
|
|
|
|
|
|
|
|
|
2013-07-18 19:37:30 -07:00
|
|
|
@hooks.hook('ceph-relation-changed')
|
2013-07-18 21:41:07 -07:00
|
|
|
@restart_on_change(restart_map())
|
2016-02-09 15:55:14 +00:00
|
|
|
def ceph_changed(rid=None, unit=None):
|
2013-07-18 19:37:30 -07:00
|
|
|
if 'ceph' not in CONFIGS.complete_contexts():
|
|
|
|
log('ceph relation incomplete. Peer not ready?')
|
|
|
|
return
|
2014-11-11 14:11:34 +00:00
|
|
|
|
2014-11-11 21:23:57 +00:00
|
|
|
if not ensure_ceph_keyring(service=service_name(), user='nova',
|
|
|
|
group='nova'):
|
2013-07-18 19:37:30 -07:00
|
|
|
log('Could not create ceph keyring: peer not ready?')
|
|
|
|
return
|
2013-07-30 20:39:44 -07:00
|
|
|
|
2013-10-10 12:41:00 +01:00
|
|
|
CONFIGS.write(ceph_config_file())
|
2013-09-20 17:50:33 +01:00
|
|
|
CONFIGS.write(CEPH_SECRET)
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
2013-07-30 20:39:44 -07:00
|
|
|
|
2013-09-03 17:16:15 -07:00
|
|
|
# With some refactoring, this can move into NovaComputeCephContext
|
|
|
|
# and allow easily extended to support other compute flavors.
|
2016-02-09 15:55:14 +00:00
|
|
|
key = relation_get(attribute='key', rid=rid, unit=unit)
|
|
|
|
if config('virt-type') in ['kvm', 'qemu', 'lxc'] and key:
|
2013-09-20 17:50:33 +01:00
|
|
|
create_libvirt_secret(secret_file=CEPH_SECRET,
|
2016-02-09 15:55:14 +00:00
|
|
|
secret_uuid=CEPH_SECRET_UUID, key=key)
|
2013-09-03 17:16:15 -07:00
|
|
|
|
2017-02-14 12:26:48 +00:00
|
|
|
if is_request_complete(get_ceph_request()):
|
|
|
|
log('Request complete')
|
|
|
|
# Ensure that nova-compute is restarted since only now can we
|
|
|
|
# guarantee that ceph resources are ready, but only if not paused.
|
2017-06-07 18:39:10 +01:00
|
|
|
if (not is_unit_paused_set() and
|
|
|
|
not is_broker_action_done('nova_compute_restart', rid,
|
|
|
|
unit)):
|
2017-02-14 12:26:48 +00:00
|
|
|
service_restart('nova-compute')
|
2017-06-07 18:39:10 +01:00
|
|
|
mark_broker_action_done('nova_compute_restart', rid, unit)
|
2017-02-14 12:26:48 +00:00
|
|
|
else:
|
|
|
|
send_request_if_needed(get_ceph_request())
|
2014-11-11 14:11:34 +00:00
|
|
|
|
2013-07-30 20:39:44 -07:00
|
|
|
|
2015-02-06 13:09:18 -05:00
|
|
|
@hooks.hook('ceph-relation-broken')
|
|
|
|
def ceph_broken():
|
|
|
|
service = service_name()
|
|
|
|
delete_keyring(service=service)
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
|
2017-10-02 17:59:34 -03:00
|
|
|
@hooks.hook('amqp-relation-broken', 'image-service-relation-broken')
|
2013-08-20 12:10:36 -07:00
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def relation_broken():
|
|
|
|
CONFIGS.write_all()
|
|
|
|
|
|
|
|
|
2013-10-17 20:25:15 +01:00
|
|
|
@hooks.hook('upgrade-charm')
|
2016-03-22 21:00:45 +00:00
|
|
|
@harden()
|
2013-10-17 20:25:15 +01:00
|
|
|
def upgrade_charm():
|
2015-08-13 10:16:35 +01:00
|
|
|
# NOTE: ensure psutil install for hugepages configuration
|
2015-09-25 15:12:01 -07:00
|
|
|
status_set('maintenance', 'Installing apt packages')
|
2015-08-13 10:16:35 +01:00
|
|
|
apt_install(filter_installed_packages(['python-psutil']))
|
2013-10-17 20:25:15 +01:00
|
|
|
for r_id in relation_ids('amqp'):
|
|
|
|
amqp_joined(relation_id=r_id)
|
2015-04-24 10:43:58 -03:00
|
|
|
|
|
|
|
if is_relation_made('nrpe-external-master'):
|
|
|
|
update_nrpe_config()
|
2013-10-17 20:25:15 +01:00
|
|
|
|
2018-07-03 13:31:56 +02:00
|
|
|
# Fix previously wrongly created path permissions
|
|
|
|
# LP: https://bugs.launchpad.net/charm-cinder-ceph/+bug/1779676
|
|
|
|
asok_path = '/var/run/ceph/'
|
|
|
|
gid = grp.getgrnam("kvm").gr_gid
|
|
|
|
if gid and os.path.isdir(asok_path) and gid != os.stat(asok_path).st_gid:
|
|
|
|
log("{} not owned by group 'kvm', fixing permissions."
|
|
|
|
.format(asok_path))
|
|
|
|
shutil.chown(asok_path, group='kvm')
|
|
|
|
|
2013-10-17 20:25:15 +01:00
|
|
|
|
2013-11-29 15:35:28 +00:00
|
|
|
@hooks.hook('nova-ceilometer-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def nova_ceilometer_relation_changed():
|
2013-11-29 15:57:59 +00:00
|
|
|
CONFIGS.write_all()
|
2013-11-29 15:35:28 +00:00
|
|
|
|
|
|
|
|
2014-11-17 13:45:12 +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)
|
2016-12-01 11:56:21 +00:00
|
|
|
monitored_services = services()
|
|
|
|
try:
|
|
|
|
# qemu-kvm is a one-shot service
|
|
|
|
monitored_services.remove('qemu-kvm')
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
nrpe.add_init_service_checks(nrpe_setup, monitored_services, current_unit)
|
2015-01-12 12:04:00 +00:00
|
|
|
nrpe_setup.write()
|
2014-10-29 22:30:36 -05:00
|
|
|
|
|
|
|
|
2015-11-25 12:48:50 +00:00
|
|
|
@hooks.hook('neutron-plugin-relation-joined')
|
2016-04-18 17:32:19 +00:00
|
|
|
def neutron_plugin_joined(relid=None, remote_restart=False):
|
|
|
|
rel_settings = {
|
2016-12-07 12:06:11 +01:00
|
|
|
'hugepage_number': get_hugepage_number(),
|
|
|
|
'default_availability_zone': config('default-availability-zone')
|
2016-04-18 17:32:19 +00:00
|
|
|
}
|
|
|
|
if remote_restart:
|
|
|
|
rel_settings['restart-trigger'] = str(uuid.uuid4())
|
2015-11-25 12:48:50 +00:00
|
|
|
relation_set(relation_id=relid,
|
2016-04-18 17:32:19 +00:00
|
|
|
**rel_settings)
|
2015-11-25 12:48:50 +00:00
|
|
|
|
|
|
|
|
2015-02-04 16:31:09 +00:00
|
|
|
@hooks.hook('neutron-plugin-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def neutron_plugin_changed():
|
2016-06-29 23:51:25 +01:00
|
|
|
enable_nova_metadata, _ = nova_metadata_requirement()
|
|
|
|
if enable_nova_metadata:
|
2015-02-04 16:31:09 +00:00
|
|
|
apt_update()
|
2015-11-16 11:53:00 +00:00
|
|
|
apt_install(filter_installed_packages(['nova-api-metadata']),
|
|
|
|
fatal=True)
|
2015-03-02 14:55:03 +00:00
|
|
|
else:
|
|
|
|
apt_purge('nova-api-metadata', fatal=True)
|
2017-02-07 10:12:11 +01:00
|
|
|
service_restart_handler(default_service='nova-compute')
|
2015-02-04 16:31:09 +00:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
|
|
|
|
2017-02-07 10:12:11 +01:00
|
|
|
# TODO(jamespage): Move this into charmhelpers for general reuse.
|
|
|
|
def service_restart_handler(relation_id=None, unit=None,
|
|
|
|
default_service=None):
|
|
|
|
'''Handler for detecting requests from subordinate
|
|
|
|
charms for restarts of services'''
|
|
|
|
restart_nonce = relation_get(attribute='restart-nonce',
|
|
|
|
unit=unit,
|
|
|
|
rid=relation_id)
|
|
|
|
db = unitdata.kv()
|
|
|
|
nonce_key = 'restart-nonce'
|
|
|
|
if restart_nonce != db.get(nonce_key):
|
|
|
|
if not is_unit_paused_set():
|
|
|
|
service = relation_get(attribute='remote-service',
|
|
|
|
unit=unit,
|
|
|
|
rid=relation_id) or default_service
|
|
|
|
if service:
|
|
|
|
service_restart(service)
|
|
|
|
db.set(nonce_key, restart_nonce)
|
|
|
|
db.flush()
|
|
|
|
|
|
|
|
|
2015-09-23 13:11:45 +01:00
|
|
|
@hooks.hook('lxd-relation-joined')
|
|
|
|
def lxd_joined(relid=None):
|
|
|
|
relation_set(relation_id=relid,
|
|
|
|
user='nova')
|
|
|
|
|
|
|
|
|
2015-09-22 15:22:50 +01:00
|
|
|
@hooks.hook('lxd-relation-changed')
|
2017-06-06 09:30:29 +02:00
|
|
|
@restart_on_change(restart_map())
|
2015-09-23 13:11:45 +01:00
|
|
|
def lxc_changed():
|
|
|
|
nonce = relation_get('nonce')
|
|
|
|
db = kv()
|
|
|
|
if nonce and db.get('lxd-nonce') != nonce:
|
|
|
|
db.set('lxd-nonce', nonce)
|
|
|
|
configure_lxd(user='nova')
|
2017-06-06 09:30:29 +02:00
|
|
|
CONFIGS.write(NOVA_CONF)
|
2015-09-23 13:11:45 +01:00
|
|
|
|
2015-07-23 22:24:48 -04:00
|
|
|
|
2017-03-09 12:51:25 +00:00
|
|
|
@hooks.hook('ceph-access-relation-changed')
|
|
|
|
def ceph_access(rid=None, unit=None):
|
|
|
|
'''Setup libvirt secret for specific ceph backend access'''
|
|
|
|
key = relation_get('key', unit, rid)
|
|
|
|
uuid = relation_get('secret-uuid', unit, rid)
|
2017-03-29 14:31:46 +01:00
|
|
|
if key and uuid:
|
|
|
|
remote_service = remote_service_name(rid)
|
|
|
|
if config('virt-type') in LIBVIRT_TYPES:
|
|
|
|
secrets_filename = CEPH_BACKEND_SECRET.format(remote_service)
|
|
|
|
render(os.path.basename(CEPH_SECRET), secrets_filename,
|
|
|
|
context={'ceph_secret_uuid': uuid,
|
|
|
|
'service_name': remote_service})
|
|
|
|
create_libvirt_secret(secret_file=secrets_filename,
|
|
|
|
secret_uuid=uuid,
|
|
|
|
key=key)
|
|
|
|
# NOTE(jamespage): LXD ceph integration via host rbd mapping, so
|
|
|
|
# install keyring for rbd commands to use
|
|
|
|
ensure_ceph_keyring(service=remote_service,
|
|
|
|
user='nova', group='nova',
|
|
|
|
key=key)
|
2017-03-09 12:51:25 +00:00
|
|
|
|
|
|
|
|
2018-04-26 12:52:35 +01:00
|
|
|
@hooks.hook('secrets-storage-relation-joined')
|
|
|
|
def secrets_storage_joined(relation_id=None):
|
|
|
|
relation_set(relation_id=relation_id,
|
|
|
|
secret_backend=vaultlocker.VAULTLOCKER_BACKEND,
|
|
|
|
isolated=True,
|
|
|
|
access_address=get_relation_ip('secrets-storage'),
|
|
|
|
hostname=gethostname())
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('secrets-storage-relation-changed')
|
|
|
|
def secrets_storage_changed():
|
|
|
|
vault_ca = relation_get('vault_ca')
|
|
|
|
if vault_ca:
|
|
|
|
vault_ca = base64.decodestring(json.loads(vault_ca).encode())
|
|
|
|
write_file('/usr/local/share/ca-certificates/vault-ca.crt',
|
|
|
|
vault_ca, perms=0o644)
|
|
|
|
subprocess.check_call(['update-ca-certificates', '--fresh'])
|
|
|
|
configure_local_ephemeral_storage()
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('storage.real')
|
|
|
|
def storage_changed():
|
|
|
|
configure_local_ephemeral_storage()
|
|
|
|
|
|
|
|
|
2018-06-14 10:12:28 +00:00
|
|
|
@hooks.hook('cloud-credentials-relation-joined')
|
|
|
|
def cloud_credentials_joined():
|
|
|
|
svc_name = local_unit().split('/')[0].replace('-', '_')
|
|
|
|
relation_set(username=svc_name)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('cloud-credentials-relation-changed')
|
|
|
|
@restart_on_change(restart_map())
|
|
|
|
def cloud_credentials_changed():
|
|
|
|
CONFIGS.write(NOVA_CONF)
|
|
|
|
|
|
|
|
|
2016-03-22 21:00:45 +00:00
|
|
|
@hooks.hook('update-status')
|
|
|
|
@harden()
|
|
|
|
def update_status():
|
|
|
|
log('Updating status.')
|
|
|
|
|
|
|
|
|
2018-08-06 15:45:10 -07:00
|
|
|
@hooks.hook('pre-series-upgrade')
|
|
|
|
def pre_series_upgrade():
|
|
|
|
log("Running prepare series upgrade hook", "INFO")
|
|
|
|
series_upgrade_prepare(
|
|
|
|
pause_unit_helper, CONFIGS)
|
|
|
|
|
|
|
|
|
|
|
|
@hooks.hook('post-series-upgrade')
|
|
|
|
def post_series_upgrade():
|
|
|
|
log("Running complete series upgrade hook", "INFO")
|
|
|
|
service_stop('nova-compute')
|
|
|
|
service_stop('libvirt-bin')
|
|
|
|
# After package upgrade the service is broken and leaves behind a
|
|
|
|
# PID file which causes the service to fail to start.
|
|
|
|
# Remove this before restart
|
|
|
|
if os.path.exists(LIBVIRTD_PID):
|
|
|
|
os.unlink(LIBVIRTD_PID)
|
|
|
|
series_upgrade_complete(
|
|
|
|
resume_unit_helper, CONFIGS)
|
|
|
|
|
|
|
|
|
2013-07-30 20:39:44 -07:00
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
hooks.execute(sys.argv)
|
|
|
|
except UnregisteredHookError as e:
|
|
|
|
log('Unknown hook {} - skipping.'.format(e))
|
2016-04-01 11:47:46 +00:00
|
|
|
assess_status(CONFIGS)
|
2013-07-30 20:39:44 -07:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|