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:
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')