import json
import logging
+from functools import wraps
from typing import List
from smb.enums import Intent
}
+def raise_on_failure(func):
+ @wraps(func)
+ def wrapper(*args, **kwargs):
+ result = func(*args, **kwargs)
+
+ if isinstance(result, dict) and result.get('success') is False:
+ msg = 'Operation failed'
+
+ # Extracts the result msg from either of two possible response structures:
+ if 'results' in result:
+ msg = result['results'][0].get('msg', msg)
+ elif 'msg' in result:
+ msg = result['msg']
+ raise DashboardException(msg=msg, component='smb')
+
+ return result
+
+ return wrapper
+
+
@APIRouter('/smb/cluster', Scope.SMB)
@APIDoc("SMB Cluster Management API", "SMB")
class SMBCluster(RESTController):
"""
return mgr.remote('smb', 'show', [f'{self._resource}.{cluster_id}'])
+ @raise_on_failure
@CreatePermission
@EndpointDoc("Create smb cluster",
parameters={
[f'{self._resource}.{cluster_id}' if cluster_id else self._resource])
return res['resources'] if 'resources' in res else res
+ @raise_on_failure
@DeletePermission
- @EndpointDoc("Remove smb shares",
+ @EndpointDoc("Remove an smb share",
parameters={
'cluster_id': (str, 'Unique identifier for the cluster'),
'share_id': (str, 'Unique identifier for the share')