]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/smb: adapt SMBCommand to use CLICommandBase
authorSamuel Just <sjust@redhat.com>
Mon, 24 Nov 2025 17:36:15 +0000 (09:36 -0800)
committerSamuel Just <sjust@redhat.com>
Wed, 17 Dec 2025 17:41:16 +0000 (17:41 +0000)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/pybind/mgr/smb/cli.py
src/pybind/mgr/smb/module.py

index ab92253d21ad4b33a1c904b702886da7671b31a8..f6a97dc8748e113c6c3ba9e040888263fd07bf2e 100644 (file)
@@ -1,11 +1,11 @@
-from typing import Any, Callable, Iterator, Tuple
+from typing import Any, Callable, Iterator, Tuple, no_type_check
 
 import contextlib
 import errno
 import functools
 
 import object_format
-from mgr_module import CLICommand
+from mgr_module import CLICommandBase
 
 from . import resourcelib
 from .proto import Self
@@ -20,7 +20,7 @@ class _cmdlet:
         return self._func(*args, **kwargs)
 
 
-class SMBCommand:
+class SMBCLICommandBase(CLICommandBase):
     """A combined decorator and descriptor. Sets up the common parts of the
     CLICommand and object formatter.
     As a descriptor, it returns objects that can be called and wrap the
@@ -29,7 +29,7 @@ class SMBCommand:
 
     Example:
     >>> class Example:
-    ...     @SMBCommand('share foo', perm='r')
+    ...     @SMBCLICommand('share foo', perm='r')
     ...     def foo(self):
     ...         return {'test': 1}
     ...
@@ -39,12 +39,11 @@ class SMBCommand:
     """
 
     def __init__(self, name: str, perm: str) -> None:
-        self._name = name
-        self._perm = perm
+        super().__init__(f"smb {name}", perm)
 
+    @no_type_check
     def __call__(self, func: Callable) -> Self:
         self._func = func
-        cc = CLICommand(f'smb {self._name}', perm=self._perm)
         # the smb module assumes that it will always be used with python
         # versions sufficiently new enough to always use ordered dicts
         # (builtin).  We dont want the json/yaml sorted by keys losing our
@@ -54,11 +53,14 @@ class SMBCommand:
             sort_json=False,
             sort_yaml=False,
         )
+
         rsp = object_format.Responder(_fmt)
         ewrap = error_wrapper()
-        self._command = cc(rsp(ewrap(func)))
+        self._command = super().__call__(rsp(ewrap(func)))
+
         return self
 
+    @no_type_check
     def __get__(self, obj: Any, objtype: Any = None) -> _cmdlet:
         return _cmdlet(
             self._func.__get__(obj, objtype),
@@ -66,6 +68,9 @@ class SMBCommand:
         )
 
 
+SMBCLICommand = SMBCLICommandBase.make_registry_subtype("SMBCLICommand")
+
+
 class InvalidInputValue(object_format.ErrorResponseBase):
     def format_response(self) -> Tuple[int, str, str]:
         return -errno.EINVAL, "", str(self)
index ac076b559fd28b73436ff9998ebb5a58d7aecd9b..1983234e2ebd8de3d4ceb18e13aad3ea8a6044fe 100644 (file)
@@ -18,6 +18,7 @@ from . import (
     sqlite_store,
     utils,
 )
+from .cli import SMBCLICommand
 from .enums import (
     AuthMode,
     InputPasswordFilter,
@@ -36,6 +37,7 @@ log = logging.getLogger(__name__)
 
 
 class Module(orchestrator.OrchestratorClientMixin, MgrModule):
+    CLICommand = SMBCLICommand
     MODULE_OPTIONS: List[Option] = [
         Option(
             'update_orchestration',
@@ -169,7 +171,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             all_results = all_results.convert_results(out_op)
         return all_results
 
-    @cli.SMBCommand('apply', perm='rw')
+    @SMBCLICommand('apply', perm='rw')
     def apply_resources(
         self,
         inbuf: str,
@@ -192,12 +194,12 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
                 [results.InvalidResourceResult(err.resource_data, str(err))]
             )
 
-    @cli.SMBCommand('cluster ls', perm='r')
+    @SMBCLICommand('cluster ls', perm='r')
     def cluster_ls(self) -> List[str]:
         """List smb clusters by ID"""
         return [cid for cid in self._handler.cluster_ids()]
 
-    @cli.SMBCommand('cluster create', perm='rw')
+    @SMBCLICommand('cluster create', perm='rw')
     def cluster_create(
         self,
         cluster_id: str,
@@ -330,7 +332,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             password_filter_out=password_filter_out,
         ).squash(cluster)
 
-    @cli.SMBCommand('cluster rm', perm='rw')
+    @SMBCLICommand('cluster rm', perm='rw')
     def cluster_rm(
         self,
         cluster_id: str,
@@ -342,7 +344,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             [cluster], password_filter_out=password_filter
         ).one()
 
-    @cli.SMBCommand('share ls', perm='r')
+    @SMBCLICommand('share ls', perm='r')
     def share_ls(self, cluster_id: str) -> List[str]:
         """List smb shares in a cluster by ID"""
         return [
@@ -351,7 +353,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             if cid == cluster_id
         ]
 
-    @cli.SMBCommand('share create', perm='rw')
+    @SMBCLICommand('share create', perm='rw')
     def share_create(
         self,
         cluster_id: str,
@@ -378,7 +380,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         )
         return self._apply_res([share], create_only=True).one()
 
-    @cli.SMBCommand('share rm', perm='rw')
+    @SMBCLICommand('share rm', perm='rw')
     def share_rm(self, cluster_id: str, share_id: str) -> results.Result:
         """Remove an smb share"""
         share = resources.RemovedShare(
@@ -386,7 +388,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         )
         return self._apply_res([share]).one()
 
-    @cli.SMBCommand("show", perm="r")
+    @SMBCLICommand("show", perm="r")
     def show(
         self,
         resource_names: Optional[List[str]] = None,