]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: Add CLI command for RGW share creation
authorShweta Sodani <ssodani@redhat.com>
Mon, 20 Apr 2026 09:14:01 +0000 (14:44 +0530)
committerShweta Sodani <Shweta.Sodani@ibm.com>
Thu, 25 Jun 2026 16:19:45 +0000 (21:49 +0530)
- Add 'smb share create rgw' CLI command
- Import rgw module for credential management
- Fetch RGW credentials using radosgw-admin
- Create Share resource with RGWStorage backend
- Handle errors from credential fetching

This enables users to create SMB shares backed by RGW buckets,
similar to 'nfs export create rgw' functionality.

Example usage:
  ceph smb share create rgw mysmb share1 mybucket

Signed-off-by: Shweta Sodani <ssodani@redhat.com>
src/pybind/mgr/smb/module.py

index 9badbe574600770e9c59cf2be9af2caaaf442445..185d1b1718d84191886b6445bcd20672be67a7ec 100644 (file)
@@ -25,6 +25,7 @@ from . import (
     rados_store,
     resources,
     results,
+    rgw,
     sqlite_store,
     utils,
 )
@@ -101,6 +102,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             authorizer=authorizer,
             orch=self._orch_backend(enable_orch=uo),
             earmark_resolver=earmark_resolver,
+            tool_execer=self,
         )
 
     def _backend_store(self, store_conf: str = '') -> ConfigStore:
@@ -615,6 +617,48 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             if cid == cluster_id
         ]
 
+    @SMBCLICommand('share create rgw', perm='rw')
+    def share_create_rgw(
+        self,
+        cluster_id: str,
+        share_id: str,
+        bucket: str,
+        share_name: str = '',
+        user_id: str = '',
+        readonly: bool = False,
+    ) -> results.Result:
+        """Create an SMB share backed by RGW"""
+        try:
+            # Pass 'self' which conforms to ToolExecer protocol
+            (
+                fetched_user_id,
+                access_key,
+                secret_key,
+            ) = rgw.fetch_rgw_credentials(self, bucket, user_id)
+
+            share = resources.Share(
+                cluster_id=cluster_id,
+                share_id=share_id,
+                name=share_name or share_id,
+                readonly=readonly,
+                rgw=resources.RGWStorage(
+                    bucket=bucket,
+                    user_id=fetched_user_id,
+                    access_key_id=access_key,
+                    secret_access_key=secret_key,
+                ),
+            )
+            return self._apply_res([share], create_only=True).one()
+        except ValueError as e:
+            # Create a minimal share resource for error reporting
+            error_share = resources.Share(
+                cluster_id=cluster_id,
+                share_id=share_id,
+                name=share_name or share_id,
+                rgw=resources.RGWStorage(bucket='error'),
+            )
+            return results.ErrorResult(error_share, msg=str(e))
+
     @SMBCLICommand('share create', perm='rw')
     def share_create(
         self,