]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/nfs/export: accept a JSON or ganesha EXPORT config
authorSage Weil <sage@newdream.net>
Wed, 30 Jun 2021 22:25:02 +0000 (18:25 -0400)
committerSage Weil <sage@newdream.net>
Wed, 14 Jul 2021 20:20:11 +0000 (16:20 -0400)
Signed-off-by: Sage Weil <sage@newdream.net>
src/pybind/mgr/nfs/export.py
src/pybind/mgr/nfs/module.py

index fe55755119510105769b875367b58ea38a608ef9..87d392e4d3716ebf26f8e8253d4fa63b44086158 100644 (file)
@@ -392,15 +392,28 @@ class ExportMgr:
         try:
             if not export_config:
                 raise NFSInvalidOperation("Empty Config!!")
-            j = json.loads(export_config)
+            try:
+                j = json.loads(export_config)
+            except ValueError:
+                # okay, not JSON.  is it an EXPORT block?
+                try:
+                    blocks = GaneshaConfParser(export_config).parse()
+                    exports = [
+                        Export.from_export_block(block, cluster_id)
+                        for block in blocks
+                    ]
+                    j = [export.to_dict() for export in exports]
+                except Exception as ex:
+                    raise NFSInvalidOperation(f"Input must be JSON or a ganesha EXPORT block: {ex}")
+
             # check export type
             if isinstance(j, list):
                 ret, out, err = (0, '', '')
                 for export in j:
                     try:
                         r, o, e = self._apply_export(cluster_id, export)
-                    except Exception as e:
-                        r, o, e = exception_handler(e, f'Failed to apply export: {e}')
+                    except Exception as ex:
+                        r, o, e = exception_handler(ex, f'Failed to apply export: {ex}')
                         if r:
                             ret = r
                     if o:
index c2cdfa1f9ed4478440e40f1bbfa01947f14765e8..157ff046fab7c28f6baac9486235930f48144523 100644 (file)
@@ -84,11 +84,9 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         return self.export_mgr.get_export(cluster_id=cluster_id, pseudo_path=pseudo_path)
 
     @CLICommand('nfs export apply', perm='rw')
-    @CLICheckNonemptyFileInput(desc='Export JSON specification')
+    @CLICheckNonemptyFileInput(desc='Export JSON or Ganesha EXPORT specification')
     def _cmd_nfs_export_apply(self, cluster_id: str, inbuf: str) -> Tuple[int, str, str]:
-        """Create or update an export by `-i <json_file>`"""
-        # The export <json_file> is passed to -i and it's processing
-        # is handled by the Ceph CLI.
+        """Create or update an export by `-i <json_or_ganesha_export_file>`"""
         return self.export_mgr.apply_export(cluster_id, export_config=inbuf)
 
     @CLICommand('nfs cluster create', perm='rw')