From 26d948735aaa360cc0494bbb3268b355d1ad61ad Mon Sep 17 00:00:00 2001 From: Varsha Rao Date: Thu, 19 Dec 2019 17:33:39 +0530 Subject: [PATCH] mgr: Add "ceph fs nfs delete " to delete exports Fixes: https://tracker.ceph.com/issues/44193 Signed-off-by: Varsha Rao --- src/pybind/mgr/volumes/fs/nfs.py | 31 +++++++++++++++++++++++++++++++ src/pybind/mgr/volumes/module.py | 12 +++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/volumes/fs/nfs.py b/src/pybind/mgr/volumes/fs/nfs.py index 9ef45aa57a7b1..93c607c6c273c 100644 --- a/src/pybind/mgr/volumes/fs/nfs.py +++ b/src/pybind/mgr/volumes/fs/nfs.py @@ -138,6 +138,12 @@ class GaneshaConf(object): for daemon_id, conf_blocks in daemon_map.items(): self._write_raw_config(conf_blocks, "conf-{}".format(daemon_id)) + def _delete_export(self, export_id): + self._persist_daemon_configuration() + with self.mgr.rados.open_ioctx(self.rados_pool) as ioctx: + if self.rados_namespace: + ioctx.set_namespace(self.rados_namespace) + ioctx.remove_object("export-{}".format(export_id)) def _save_export(self, export): self.fill_keys(export) @@ -152,9 +158,26 @@ class GaneshaConf(object): self._save_export(export) return ex_id + def remove_export(self, export_id): + if export_id not in self.exports: + return None + export = self.exports[export_id] + del self.exports[export_id] + self._delete_export(export_id) + return export + + def has_export(self, export_id): + return export_id in self.exports + def list_daemons(self): return [daemon_id for daemon_id in self.daemons_conf_blocks] + def reload_daemons(self, daemons): + with self.mgr.rados.open_ioctx(self.rados_pool) as ioctx: + if self.rados_namespace: + ioctx.set_namespace(self.rados_namespace) + for daemon_id in daemons: + ioctx.notify("conf-{}".format(daemon_id)) def create_instance(orch): return GaneshaConf("a", "nfs-ganesha", "ganesha", orch) @@ -178,6 +201,14 @@ def create_export(ganesha_conf): log.info("Export ID is {}".format(ex_id)) return 0, "", "" +def delete_export(ganesha_conf, ex_id): + if not ganesha_conf.has_export(ex_id): + return 0, "No exports available","" + log.info("Export detected for id:{}".format(ex_id)) + export = ganesha_conf.remove_export(ex_id) + ganesha_conf.reload_daemons(export.daemons) + return 0, "", "" + def check_fsal_valid(fs_map): fsmap_res = [{'id': fs['id'], 'name': fs['mdsmap']['fs_name']} for fs in fs_map['filesystems']] diff --git a/src/pybind/mgr/volumes/module.py b/src/pybind/mgr/volumes/module.py index 45a86884ede5c..f0ae8192cc013 100644 --- a/src/pybind/mgr/volumes/module.py +++ b/src/pybind/mgr/volumes/module.py @@ -5,7 +5,7 @@ from mgr_module import MgrModule import orchestrator from .fs.volume import VolumeClient -from .fs.nfs import check_fsal_valid, create_instance, create_export +from .fs.nfs import check_fsal_valid, create_instance, create_export, delete_export class Module(orchestrator.OrchestratorClientMixin, MgrModule): COMMANDS = [ @@ -218,6 +218,12 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): 'desc': "Create dummy exports", 'perm': 'rw' }, + { + 'cmd': 'fs nfs delete ' + 'name=export_id,type=CephInt,req=true ', + 'desc': "Delete nfs exports", + 'perm': 'rw' + }, # volume ls [recursive] # subvolume ls @@ -387,3 +393,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): if check_fsal_valid(self.vc.mgr.get('fs_map')): instance = create_instance(self) return create_export(instance) + + def _cmd_fs_nfs_delete(self, inbuf, cmd): + instance = create_instance(self) + return delete_export(instance, cmd['export_id']) -- 2.39.5