]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs: add 'nfs export import' command
authorSage Weil <sage@newdream.net>
Thu, 27 May 2021 23:25:40 +0000 (19:25 -0400)
committerSebastian Wagner <sewagner@redhat.com>
Thu, 9 Sep 2021 14:17:46 +0000 (16:17 +0200)
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 <sage@newdream.net>
(cherry picked from commit 778674a9c728b2b04f1b6922005798303475d352)

src/pybind/mgr/nfs/export.py
src/pybind/mgr/nfs/module.py

index dd624b48314a924005befe9898e2b519ead4e1b9..5c71672d7a73e69a65e0aae72ce544e06ed82a14 100644 (file)
@@ -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}'
index ebb95cd91ef35e7b40a59c1fc91ba62e9212a01e..1969025a4d1451512c4f4f173caa53fc01d28788 100644 (file)
@@ -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"""