Skip to content

Commit 73a7602

Browse files
committed
mgr/dashboard: rgw policy group management api
Fixes: https://tracker.ceph.com/issues/66238 Signed-off-by: Nizamudeen A <[email protected]>
1 parent 35b6248 commit 73a7602

File tree

2 files changed

+111
-4
lines changed

2 files changed

+111
-4
lines changed

src/pybind/mgr/dashboard/controllers/rgw.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
from ..security import Permission, Scope
1515
from ..services.auth import AuthManager, JwtManager
1616
from ..services.ceph_service import CephService
17-
from ..services.rgw_client import NoRgwDaemonsException, RgwClient, RgwMultisite
17+
from ..services.rgw_client import NoRgwDaemonsException, RgwClient, RgwMultisite, \
18+
SyncStatus
1819
from ..tools import json_str_to_object, str_to_bool
1920
from . import APIDoc, APIRouter, BaseController, CreatePermission, \
2021
CRUDCollectionMethod, CRUDEndpoint, Endpoint, EndpointDoc, ReadPermission, \
21-
RESTController, UIRouter, UpdatePermission, allow_empty_body
22+
RESTController, UIRouter, UpdatePermission, allow_empty_body, DeletePermission
2223
from ._crud import CRUDMeta, Form, FormField, FormTaskInfo, Icon, MethodType, \
2324
TableAction, Validator, VerticalContainer
2425
from ._version import APIVersion
@@ -114,15 +115,51 @@ def migrate(self, daemon_name=None, realm_name=None, zonegroup_name=None, zone_n
114115

115116
@APIRouter('rgw/multisite', Scope.RGW)
116117
@APIDoc("RGW Multisite Management API", "RgwMultisite")
117-
class RgwMultisiteSyncStatus(RESTController):
118-
@RESTController.Collection(method='GET', path='/sync_status')
118+
class RgwMultisiteController(RESTController):
119+
@Endpoint(path='/sync_status')
120+
@EndpointDoc("Get the sync status")
119121
@allow_empty_body
120122
# pylint: disable=W0102,W0613
121123
def get_sync_status(self):
122124
multisite_instance = RgwMultisite()
123125
result = multisite_instance.get_multisite_sync_status()
124126
return result
125127

128+
@Endpoint(path='/sync-policy')
129+
@EndpointDoc("Get the sync policy")
130+
@ReadPermission
131+
def get_sync_policy(self, bucket_name = ''):
132+
multisite_instance = RgwMultisite()
133+
return multisite_instance.get_sync_policy(bucket_name)
134+
135+
@Endpoint(path='/sync-policy-group')
136+
@EndpointDoc("Get the sync policy group")
137+
@ReadPermission
138+
def get_sync_policy_group(self, group_id: str, bucket_name=''):
139+
multisite_instance = RgwMultisite()
140+
return multisite_instance.get_sync_policy_group(group_id, bucket_name)
141+
142+
@Endpoint(method='POST', path='/sync-policy-group')
143+
@EndpointDoc("Create the sync policy group")
144+
@CreatePermission
145+
def create_sync_policy_group(self, group_id: str, status: SyncStatus, bucket_name=''):
146+
multisite_instance = RgwMultisite()
147+
return multisite_instance.create_sync_policy_group(group_id, status, bucket_name)
148+
149+
@Endpoint(method='PUT', path='/sync-policy-group')
150+
@EndpointDoc("Update the sync policy group")
151+
@UpdatePermission
152+
def update_sync_policy_group(self, group_id: str, status: SyncStatus, bucket_name=''):
153+
multisite_instance = RgwMultisite()
154+
return multisite_instance.update_sync_policy_group(group_id, status, bucket_name)
155+
156+
@Endpoint(method='DELETE', path='/sync-policy-group')
157+
@EndpointDoc("Remove the sync policy group")
158+
@DeletePermission
159+
def remove_sync_policy_group(self, group_id: str, bucket_name=''):
160+
multisite_instance = RgwMultisite()
161+
return multisite_instance.remove_sync_policy_group(group_id, bucket_name)
162+
126163

127164
@APIRouter('/rgw/daemon', Scope.RGW)
128165
@APIDoc("RGW Daemon Management API", "RgwDaemon")

src/pybind/mgr/dashboard/services/rgw_client.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111
import xml.etree.ElementTree as ET # noqa: N814
1212
from subprocess import SubprocessError
13+
from enum import Enum
1314

1415
from mgr_util import build_url, name_to_config_section
1516

@@ -983,6 +984,11 @@ def perform_validations(self, retention_period_days, retention_period_years, mod
983984
raise DashboardException(msg=msg, component='rgw')
984985
return retention_period_days, retention_period_years
985986

987+
class SyncStatus(Enum):
988+
enabled = 'enabled'
989+
allowed = 'allowed'
990+
forbidden = 'forbidden'
991+
986992

987993
class RgwMultisite:
988994
def migrate_to_multisite(self, realm_name: str, zonegroup_name: str, zone_name: str,
@@ -1744,3 +1750,67 @@ def get_primary_zonedata(self, data):
17441750
return match.group(1)
17451751

17461752
return ''
1753+
1754+
def get_sync_policy(self, bucket_name: str = ''):
1755+
rgw_sync_policy_cmd = ['sync', 'policy', 'get']
1756+
if bucket_name:
1757+
rgw_sync_policy_cmd += ['--bucket', bucket_name]
1758+
try:
1759+
exit_code, out, _ = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)
1760+
if exit_code > 0:
1761+
raise DashboardException('Unable to get sync policy',
1762+
http_status_code=500, component='rgw')
1763+
return out
1764+
except SubprocessError as error:
1765+
raise DashboardException(error, http_status_code=500, component='rgw')
1766+
1767+
def get_sync_policy_group(self, group_id: str, bucket_name: str = ''):
1768+
rgw_sync_policy_cmd = ['sync', 'group', 'get', '--group-id', group_id]
1769+
if bucket_name:
1770+
rgw_sync_policy_cmd += ['--bucket', bucket_name]
1771+
try:
1772+
exit_code, out, _ = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)
1773+
if exit_code > 0:
1774+
raise DashboardException('Unable to get sync policy',
1775+
http_status_code=500, component='rgw')
1776+
return out
1777+
except SubprocessError as error:
1778+
raise DashboardException(error, http_status_code=500, component='rgw')
1779+
1780+
def create_sync_policy_group(self, group_id: str, status: SyncStatus, bucket_name: str = ''):
1781+
rgw_sync_policy_cmd = ['sync', 'group', 'create', '--group-id', group_id,
1782+
'--status', SyncStatus[status].value]
1783+
if bucket_name:
1784+
rgw_sync_policy_cmd += ['--bucket', bucket_name]
1785+
try:
1786+
exit_code, _, _ = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)
1787+
if exit_code > 0:
1788+
raise DashboardException('Unable to create sync policy',
1789+
http_status_code=500, component='rgw')
1790+
except SubprocessError as error:
1791+
raise DashboardException(error, http_status_code=500, component='rgw')
1792+
1793+
def update_sync_policy_group(self, group_id: str, status: SyncStatus, bucket_name: str = ''):
1794+
rgw_sync_policy_cmd = ['sync', 'group', 'modify', '--group-id', group_id,
1795+
'--status', SyncStatus[status].value]
1796+
if bucket_name:
1797+
rgw_sync_policy_cmd += ['--bucket', bucket_name]
1798+
try:
1799+
exit_code, _, _ = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)
1800+
if exit_code > 0:
1801+
raise DashboardException('Unable to update sync policy',
1802+
http_status_code=500, component='rgw')
1803+
except SubprocessError as error:
1804+
raise DashboardException(error, http_status_code=500, component='rgw')
1805+
1806+
def remove_sync_policy_group(self, group_id: str, bucket_name=''):
1807+
rgw_sync_policy_cmd = ['sync', 'group', 'remove', '--group-id', group_id]
1808+
if bucket_name:
1809+
rgw_sync_policy_cmd += ['--bucket', bucket_name]
1810+
try:
1811+
exit_code, _, _ = mgr.send_rgwadmin_command(rgw_sync_policy_cmd)
1812+
if exit_code > 0:
1813+
raise DashboardException('Unable to remove sync policy',
1814+
http_status_code=500, component='rgw')
1815+
except SubprocessError as error:
1816+
raise DashboardException(error, http_status_code=500, component='rgw')

0 commit comments

Comments
 (0)