mgr/smb: Add CLI command for RGW share creation

- 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>
This commit is contained in:
Shweta Sodani 2026-04-20 14:44:01 +05:30 committed by Shweta Sodani
parent 9b4fbb3f22
commit 6a3f3103a8

View 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,