From 3a7f8e5e37b81fc3ffe4f809f8cf7ce5bd9206d2 Mon Sep 17 00:00:00 2001 From: sunlan Date: Mon, 24 Jun 2024 16:29:38 +0800 Subject: [PATCH] mgr/dashboard: add restful api for creating crush rule with type of 'erasure' Fixes: https://tracker.ceph.com/issues/66490 Signed-off-by: sunlan --- qa/tasks/mgr/dashboard/test_crush_rule.py | 13 ++++++++++ .../mgr/dashboard/controllers/crush_rule.py | 26 +++++++++++++------ src/pybind/mgr/dashboard/openapi.yaml | 6 ++++- 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_crush_rule.py b/qa/tasks/mgr/dashboard/test_crush_rule.py index aa2250b1d2a..d5230f0d098 100644 --- a/qa/tasks/mgr/dashboard/test_crush_rule.py +++ b/qa/tasks/mgr/dashboard/test_crush_rule.py @@ -82,3 +82,16 @@ class CrushRuleTest(DashboardTestCase): 'nodes': JList(JObj({}, allow_unknown=True)), 'roots': JList(int) })) + + @DashboardTestCase.RunAs('test', 'test', ['pool-manager', 'cluster-manager']) + def test_create_erasure_with_ssd(self): + data = self._get('/api/osd/0') + self.assertStatus(200) + device_class = data['osd_metadata']['default_device_class'] + self.create_and_delete_rule({ + 'pool_type': 'erasure', + 'name': 'some_erasure_crush_rule', + 'profile': 'default', + 'failure_domain': 'osd', + 'device_class': device_class + }) diff --git a/src/pybind/mgr/dashboard/controllers/crush_rule.py b/src/pybind/mgr/dashboard/controllers/crush_rule.py index 250f657b2ba..dd0ab91ba4d 100644 --- a/src/pybind/mgr/dashboard/controllers/crush_rule.py +++ b/src/pybind/mgr/dashboard/controllers/crush_rule.py @@ -38,14 +38,24 @@ class CrushRule(RESTController): return r raise NotFound('No such crush rule') - def create(self, name, root, failure_domain, device_class=None): - rule = { - 'name': name, - 'root': root, - 'type': failure_domain, - 'class': device_class - } - CephService.send_command('mon', 'osd crush rule create-replicated', **rule) + def create(self, name, failure_domain, device_class=None, root=None, profile=None, + pool_type='replication'): + if pool_type == 'erasure': + rule = { + 'name': name, + 'profile': profile, + 'type': failure_domain, + 'class': device_class + } + CephService.send_command('mon', 'osd crush rule create-erasure', **rule) + else: + rule = { + 'name': name, + 'root': root, + 'type': failure_domain, + 'class': device_class + } + CephService.send_command('mon', 'osd crush rule create-replicated', **rule) def delete(self, name): CephService.send_command('mon', 'osd crush rule rm', name=name) diff --git a/src/pybind/mgr/dashboard/openapi.yaml b/src/pybind/mgr/dashboard/openapi.yaml index beb4216015e..5f472024074 100644 --- a/src/pybind/mgr/dashboard/openapi.yaml +++ b/src/pybind/mgr/dashboard/openapi.yaml @@ -4206,11 +4206,15 @@ paths: type: string name: type: string + pool_type: + default: replication + type: string + profile: + type: string root: type: string required: - name - - root - failure_domain type: object responses: -- 2.39.5