From: John Mulligan Date: Wed, 12 Mar 2025 17:07:21 +0000 (-0400) Subject: mgr/smb: allow show command to collapse or keep full objects list X-Git-Tag: v20.3.0~184^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=39a1eb2b8c9bcf91c56433edaefadda1932e4198;p=ceph.git mgr/smb: allow show command to collapse or keep full objects list Previously, the `ceph smb show` command would "collapse" the output to one single resource if exactly one resource matched, as opposed to emitting a resource list with one single item. Add new switch, `--results=[collapsed|full]`, that will either continue the default behavior (collapsed) or retain the output as a resource list object (full). Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/smb/enums.py b/src/pybind/mgr/smb/enums.py index 12b788f980fd..7f7b04df5593 100644 --- a/src/pybind/mgr/smb/enums.py +++ b/src/pybind/mgr/smb/enums.py @@ -102,3 +102,8 @@ class SMBClustering(_StrEnum): DEFAULT = 'default' ALWAYS = 'always' NEVER = 'never' + + +class ShowResults(_StrEnum): + FULL = 'full' + COLLAPSED = 'collapsed' diff --git a/src/pybind/mgr/smb/module.py b/src/pybind/mgr/smb/module.py index 4512ad6add33..17c6db14b512 100644 --- a/src/pybind/mgr/smb/module.py +++ b/src/pybind/mgr/smb/module.py @@ -21,6 +21,7 @@ from . import ( from .enums import ( AuthMode, JoinSourceType, + ShowResults, SMBClustering, UserGroupSourceType, ) @@ -334,8 +335,12 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): ) return self._handler.apply([share]).one() - @cli.SMBCommand('show', perm='r') - def show(self, resource_names: Optional[List[str]] = None) -> Simplified: + @cli.SMBCommand("show", perm="r") + def show( + self, + resource_names: Optional[List[str]] = None, + results: ShowResults = ShowResults.COLLAPSED, + ) -> Simplified: """Show resources fetched from the local config store based on resource type or resource type and id(s). """ @@ -346,9 +351,9 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule): resources = self._handler.matching_resources(resource_names) except handler.InvalidResourceMatch as err: raise cli.InvalidInputValue(str(err)) from err - if len(resources) == 1: + if len(resources) == 1 and results is ShowResults.COLLAPSED: return resources[0].to_simplified() - return {'resources': [r.to_simplified() for r in resources]} + return {"resources": [r.to_simplified() for r in resources]} def submit_smb_spec(self, spec: SMBSpec) -> None: """Submit a new or updated smb spec object to ceph orchestration."""