From 1f86962275407c8f7752e6457e2bc0e22869b46f Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 17 Aug 2020 08:20:34 +0000 Subject: [PATCH] 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 --- ceph-mds | 1 + src/ceph_mds/README.md | 45 ++++++++++++++++++ src/ceph_mds/__init__.py | 0 src/ceph_mds/interface.yaml | 3 ++ src/ceph_mds/lib | 1 + src/ceph_mds/requires.py | 94 +++++++++++++++++++++++++++++++++++++ 6 files changed, 144 insertions(+) create mode 120000 ceph-mds create mode 100644 src/ceph_mds/README.md create mode 100644 src/ceph_mds/__init__.py create mode 100644 src/ceph_mds/interface.yaml create mode 120000 src/ceph_mds/lib create mode 100644 src/ceph_mds/requires.py diff --git a/ceph-mds b/ceph-mds new file mode 120000 index 0000000..dd1ccf9 --- /dev/null +++ b/ceph-mds @@ -0,0 +1 @@ +src/ceph_mds \ No newline at end of file diff --git a/src/ceph_mds/README.md b/src/ceph_mds/README.md new file mode 100644 index 0000000..479c8db --- /dev/null +++ b/src/ceph_mds/README.md @@ -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) +``` diff --git a/src/ceph_mds/__init__.py b/src/ceph_mds/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/ceph_mds/interface.yaml b/src/ceph_mds/interface.yaml new file mode 100644 index 0000000..b1ad500 --- /dev/null +++ b/src/ceph_mds/interface.yaml @@ -0,0 +1,3 @@ +name: ceph-mds +summary: Ceph MDS Client Interface +version: 1 diff --git a/src/ceph_mds/lib b/src/ceph_mds/lib new file mode 120000 index 0000000..dc598c5 --- /dev/null +++ b/src/ceph_mds/lib @@ -0,0 +1 @@ +../lib \ No newline at end of file diff --git a/src/ceph_mds/requires.py b/src/ceph_mds/requires.py new file mode 100644 index 0000000..bcb3ef7 --- /dev/null +++ b/src/ceph_mds/requires.py @@ -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)