From 137090dac07f95c3af0b09afc19da210b085019b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 26 May 2021 14:37:34 -0400 Subject: [PATCH] mgr/nfs: add --addr to 'nfs export create' Ganesha exports can have multiple client blocks with addresses and access modes/squash behavior. This cannot easily be exposed via a CLI. However, providing no client address restriction is pretty useful to users since it allows full access to the mount point with no restrictions. Add an --addr argument that creates a single client block. Set the top export-level access_type to 'none' and squash to 'none' in this case. Signed-off-by: Sage Weil --- src/pybind/mgr/nfs/export.py | 12 ++++++++---- src/pybind/mgr/nfs/module.py | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/pybind/mgr/nfs/export.py b/src/pybind/mgr/nfs/export.py index cc8c8c657bc..4469389ab61 100644 --- a/src/pybind/mgr/nfs/export.py +++ b/src/pybind/mgr/nfs/export.py @@ -430,7 +430,8 @@ class FSExport(ExportMgr): log.info("Export user created is {}".format(json_res[0]['entity'])) return json_res[0]['entity'], json_res[0]['key'] - def create_export(self, fs_name, cluster_id, pseudo_path, read_only, path, squash): + def create_export(self, fs_name, cluster_id, pseudo_path, read_only, path, squash, + clients=[]): if not check_fs(self.mgr, fs_name): raise FSNotFound(fs_name) @@ -444,9 +445,12 @@ class FSExport(ExportMgr): ex_id = self._gen_export_id() user_id = f"{cluster_id}{ex_id}" user_out, key = self._create_user_key(user_id, path, fs_name, read_only) - access_type = "RW" - if read_only: + if clients: + access_type = "none" + elif read_only: access_type = "RO" + else: + access_type = "RW" ex_dict = { 'path': self.format_path(path), 'pseudo': pseudo_path, @@ -455,7 +459,7 @@ class FSExport(ExportMgr): 'squash': squash, 'fsal': {"name": "CEPH", "user_id": user_id, "fs_name": fs_name, "sec_label_xattr": ""}, - 'clients': [] + 'clients': clients } export = Export.from_dict(ex_id, ex_dict) export.fsal.cephx_key = key diff --git a/src/pybind/mgr/nfs/module.py b/src/pybind/mgr/nfs/module.py index 1a0abedef14..ebb95cd91ef 100644 --- a/src/pybind/mgr/nfs/module.py +++ b/src/pybind/mgr/nfs/module.py @@ -29,16 +29,25 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): fsname: str, clusterid: str, binding: str, - path: str = '/', - readonly: bool = False, + path: Optional[str] = '/', + readonly: Optional[bool] = False, + addr: Optional[str] = None, squash: str = 'none', ) -> Tuple[int, str, str]: """Create a cephfs export""" # TODO Extend export creation for rgw. + clients = [] + if addr: + clients = [{ + 'addresses': [addr], + 'access_type': 'ro' if readonly else 'rw', + 'squash': squash, + }] + squash = 'none' return self.export_mgr.create_export(fsal_type='cephfs', fs_name=fsname, cluster_id=clusterid, pseudo_path=binding, read_only=readonly, path=path, - squash=squash) + squash=squash, clients=clients) @CLICommand('nfs export rm', perm='rw') def _cmd_nfs_export_rm(self, clusterid: str, binding: str) -> Tuple[int, str, str]: -- 2.39.5