From: Sage Weil Date: Thu, 27 May 2021 23:25:40 +0000 (-0400) Subject: mgr/nfs: add 'nfs export import' command X-Git-Tag: v16.2.7~116^2~114 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=8d358fd5430b090dcbde3df147c178703d4b500e;p=ceph.git mgr/nfs: add 'nfs export import' command Allow import of JSON to create a new export. Similar to 'update', which allows an import of JSON to update an existing export. Signed-off-by: Sage Weil (cherry picked from commit 778674a9c728b2b04f1b6922005798303475d352) --- diff --git a/src/pybind/mgr/nfs/export.py b/src/pybind/mgr/nfs/export.py index dd624b48314..5c71672d7a7 100644 --- a/src/pybind/mgr/nfs/export.py +++ b/src/pybind/mgr/nfs/export.py @@ -415,3 +415,16 @@ class FSExport(ExportMgr): export_ls.remove(old_export) restart_nfs_service(self.mgr, new_export.cluster_id) return 0, "Successfully updated export", "" + + def import_export(self, new_export): + for k in ['cluster_id', 'path', 'pseudo']: + if k not in new_export: + raise NFSInvalidOperation(f'Export missing required field {k}') + if new_export.get('cluster_id') not in self.exports: + raise ClusterNotFound() + self.rados_namespace = new_export['cluster_id'] + + export = Export.from_dict(self._gen_export_id(), new_export) + export.validate(self.mgr) + self._save_export(export) + return f'Added export {export.pseudo}' diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index ebb95cd91ef..1969025a4d1 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -49,6 +49,12 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): read_only=readonly, path=path, squash=squash, clients=clients) + @CLICommand('nfs export import', perm='rw') + def _cmd_nfs_export_import(self, + inbuf: str) -> Tuple[int, str, str]: + """Create one or more exports from JSON specification""" + return self.export_mgr.import_export(inbuf) + @CLICommand('nfs export rm', perm='rw') def _cmd_nfs_export_rm(self, clusterid: str, binding: str) -> Tuple[int, str, str]: """Remove a cephfs export"""