2016-07-01 17:10:07 +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.
|
|
|
|
|
2014-01-23 16:14:44 +00:00
|
|
|
from charmhelpers.core.hookenv import (
|
2019-01-23 17:51:46 +00:00
|
|
|
config,
|
2014-01-23 16:14:44 +00:00
|
|
|
service_name,
|
2014-04-02 09:13:47 +01:00
|
|
|
is_relation_made,
|
2017-03-09 12:59:06 +00:00
|
|
|
leader_get,
|
2014-01-23 16:14:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
from charmhelpers.contrib.openstack.context import (
|
|
|
|
OSContextGenerator,
|
|
|
|
)
|
|
|
|
|
2017-03-29 15:33:32 +01:00
|
|
|
from charmhelpers.contrib.openstack.utils import (
|
|
|
|
get_os_codename_package,
|
|
|
|
CompareOpenStackReleases,
|
|
|
|
)
|
2014-04-02 09:13:47 +01:00
|
|
|
|
2018-05-10 11:48:38 +01:00
|
|
|
CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf'
|
|
|
|
|
|
|
|
|
|
|
|
def ceph_config_file():
|
|
|
|
return CHARM_CEPH_CONF.format(service_name())
|
|
|
|
|
2014-01-23 16:14:44 +00:00
|
|
|
|
|
|
|
class CephSubordinateContext(OSContextGenerator):
|
|
|
|
interfaces = ['ceph-cinder']
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
"""
|
|
|
|
Used to generate template context to be added to cinder.conf in the
|
|
|
|
presence of a ceph relation.
|
|
|
|
"""
|
|
|
|
if not is_relation_made('ceph', 'key'):
|
|
|
|
return {}
|
|
|
|
service = service_name()
|
2017-03-07 11:10:22 -08:00
|
|
|
os_codename = get_os_codename_package('cinder-common')
|
2017-03-29 15:33:32 +01:00
|
|
|
if CompareOpenStackReleases(os_codename) >= "icehouse":
|
2014-04-02 09:13:47 +01:00
|
|
|
volume_driver = 'cinder.volume.drivers.rbd.RBDDriver'
|
|
|
|
else:
|
|
|
|
volume_driver = 'cinder.volume.driver.RBDDriver'
|
2018-09-05 14:31:15 +01:00
|
|
|
|
2019-01-23 17:51:46 +00:00
|
|
|
if config('rbd-pool-name'):
|
|
|
|
pool_name = config('rbd-pool-name')
|
|
|
|
else:
|
|
|
|
pool_name = service
|
2018-09-05 14:31:15 +01:00
|
|
|
section = {service: [('volume_backend_name', service),
|
|
|
|
('volume_driver', volume_driver),
|
2019-01-23 17:51:46 +00:00
|
|
|
('rbd_pool', pool_name),
|
2018-09-05 14:31:15 +01:00
|
|
|
('rbd_user', service),
|
|
|
|
('rbd_secret_uuid', leader_get('secret-uuid')),
|
|
|
|
('rbd_ceph_conf', ceph_config_file())]}
|
|
|
|
|
2018-09-27 12:10:03 +01:00
|
|
|
if CompareOpenStackReleases(os_codename) >= "mitaka":
|
|
|
|
section[service].append(('report_discard_supported', True))
|
|
|
|
|
2018-09-05 14:31:15 +01:00
|
|
|
if CompareOpenStackReleases(os_codename) >= "queens":
|
|
|
|
section[service].append(('rbd_exclusive_cinder_pool', True))
|
|
|
|
|
|
|
|
return {'cinder': {'/etc/cinder/cinder.conf': {'sections': section}}}
|