Add ceph-mds relation

This relation is very similar to the ceph-client relation so add
it to this repo so they can share code. This will retire the
seperate repo *1 and also require an update to the central
index of interfaces to point at the new location.

*1 https://github.com/openstack/charm-interface-ceph-mds
*2 https://juju.github.io/layer-index/

Change-Id: I9f438bb678da1b69d8161390aad2cf58907bc1b5
This commit is contained in:
Liam Young 2020-08-17 08:20:34 +00:00
parent fc168f4e7b
commit 1f86962275
6 changed files with 144 additions and 0 deletions

1
ceph-mds Symbolic link
View File

@ -0,0 +1 @@
src/ceph_mds

45
src/ceph_mds/README.md Normal file
View File

@ -0,0 +1,45 @@
# Overview
This interface layer handles the communication between the Ceph Monitor
and a client that requires an admin key.
# Usage
## Requires
This interface layer will set the following states, as appropriate:
* `{relation_name}.connected` The ceph client has been related to a provider.
* `{relation_name}.pools.available` The pools requested have been created,
The following accessors will be available:
- key - The mds cephx key
- admin_key - The cephx admin key
- auth - Whether or not strict auth is supported
- mon_hosts - The public addresses list of the monitor cluster
Client example:
```python
@when('ceph-mds.connected')
def storage_ceph_connected(ceph):
ceph.announce_mds_name()
ceph.initialize_mds(hookenv.service_name())
@when('ceph-mds.pools.available')
def ceph_connected(ceph_info):
charm_ceph_conf = os.path.join(os.sep, 'etc', 'ceph', 'ceph.conf')
cephx_key = os.path.join(os.sep, 'etc', 'ceph', 'ceph.client.admin.keyring')
ceph_context = {
'auth_supported': ceph_client.auth,
'mon_hosts': ceph_client.mon_hosts,
}
with open(charm_ceph_conf, 'w') as cephconf:
cephconf.write(render_template('ceph.conf', ceph_context))
# Write out the cephx_key also
with open(cephx_key, 'w') as cephconf:
cephconf.write(ceph_client.key)
```

0
src/ceph_mds/__init__.py Normal file
View File

View File

@ -0,0 +1,3 @@
name: ceph-mds
summary: Ceph MDS Client Interface
version: 1

1
src/ceph_mds/lib Symbolic link
View File

@ -0,0 +1 @@
../lib

94
src/ceph_mds/requires.py Normal file
View File

@ -0,0 +1,94 @@
# Copyright 2020 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.
import socket
from .lib import base_requires
from charms.reactive import (
when,
)
from charmhelpers.contrib.storage.linux.ceph import (
CephBrokerRq,
)
class CephClient(base_requires.CephRequires):
ceph_pool_app_name = 'cephfs'
@when('endpoint.{endpoint_name}.joined')
def joined(self):
super().joined()
@when('endpoint.{endpoint_name}.changed')
def changed(self):
super().changed()
@when('endpoint.{endpoint_name}.departed')
def departed(self):
super().changed()
@when('endpoint.{endpoint_name}.broken')
def broken(self):
super().broken()
def fsid(self):
return self.all_joined_units.received.get('fsid')
def mds_key(self):
"""Retrieve the cephx key for the local mds unit"""
return self.all_joined_units.received.get(
'{}_mds_key'.format(socket.gethostname()))
def initial_ceph_response(self):
data = {
'mds_key': self.mds_key(),
'fsid': self.fsid(),
'auth': self.auth(),
'mon_hosts': self.mon_hosts()
}
return data
def announce_mds_name(self):
for relation in self.relations:
relation.to_publish_raw['mds-name'] = socket.gethostname()
def request_cephfs(self, name):
rq = self.get_current_request() or CephBrokerRq()
rq.add_op({
'op': 'create-cephfs',
'mds_name': name,
'data_pool': "{}_data".format(name),
'metadata_pool': "{}_metadata".format(name)})
self.send_request_if_needed(rq)
def initialize_mds(self, name, replicas=3):
"""
Request pool setup and mds creation
@param name: name of mds pools to create
@param replicas: number of replicas for supporting pools
"""
self.create_replicated_pool(
name="{}_data".format(name),
replicas=replicas,
weight=None,
app_name=self.ceph_pool_app_name)
self.create_replicated_pool(
name="{}_metadata".format(name),
replicas=replicas,
weight=None,
app_name=self.ceph_pool_app_name)
self.request_cephfs(name)