]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/smb: allow show command to collapse or keep full objects list
authorJohn Mulligan <jmulligan@redhat.com>
Wed, 12 Mar 2025 17:07:21 +0000 (13:07 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 1 Apr 2025 12:02:39 +0000 (08:02 -0400)
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 <jmulligan@redhat.com>
src/pybind/mgr/smb/enums.py
src/pybind/mgr/smb/module.py

index 12b788f980fd78fded5455230ba80fba5ad35fb2..7f7b04df55936e6b042b9954c8cd453257a38356 100644 (file)
@@ -102,3 +102,8 @@ class SMBClustering(_StrEnum):
     DEFAULT = 'default'
     ALWAYS = 'always'
     NEVER = 'never'
+
+
+class ShowResults(_StrEnum):
+    FULL = 'full'
+    COLLAPSED = 'collapsed'
index 4512ad6add336d4731df8dfac8c2c2da76992f5e..17c6db14b512b6cdacd241cb1950d2fe0b675985 100644 (file)
@@ -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."""