From: Sage Weil Date: Wed, 30 Jun 2021 22:25:02 +0000 (-0400) Subject: mgr/nfs/export: accept a JSON or ganesha EXPORT config X-Git-Tag: v16.2.7~116^2~50 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4c98c26d095cad5408ddab0602aaaf88d143f3f8;p=ceph.git mgr/nfs/export: accept a JSON or ganesha EXPORT config Signed-off-by: Sage Weil (cherry picked from commit 6b2ccb2049484d2325bd2189410165093217a766) --- diff --git a/src/pybind/mgr/nfs/export.py b/src/pybind/mgr/nfs/export.py index fe5575511951..87d392e4d371 100644 --- a/src/pybind/mgr/nfs/export.py +++ b/src/pybind/mgr/nfs/export.py @@ -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: diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index c2cdfa1f9ed4..157ff046fab7 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -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 `""" - # The export is passed to -i and it's processing - # is handled by the Ceph CLI. + """Create or update an export by `-i `""" return self.export_mgr.apply_export(cluster_id, export_config=inbuf) @CLICommand('nfs cluster create', perm='rw')