From 2ff8540c8117e77f7d690606b484c43dda09e95b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Stephan=20M=C3=BCller?= Date: Mon, 2 Mar 2020 11:08:23 +0100 Subject: [PATCH] mgr/dashboard: Change pool info API endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Moves the "_info" endpoint of pool into an equivalent UI-API call with the name "info". Added three more attributes to the info dict which enables the dashboard to only call info to get all the needed data, currently three calls will be used to do that. Removed pool_name parameter as the outcome was not used. Updated the tests and related angular files accordingly. Fixes: https://tracker.ceph.com/issues/44371 Signed-off-by: Stephan Müller --- qa/tasks/mgr/dashboard/test_pool.py | 4 ++- src/pybind/mgr/dashboard/controllers/pool.py | 36 ++++++++++++------- .../src/app/shared/api/pool.service.spec.ts | 2 +- .../src/app/shared/api/pool.service.ts | 4 +-- .../src/app/shared/models/pool-form-info.ts | 3 ++ 5 files changed, 33 insertions(+), 16 deletions(-) diff --git a/qa/tasks/mgr/dashboard/test_pool.py b/qa/tasks/mgr/dashboard/test_pool.py index 8d403d89a1d51..969318d2a94b3 100644 --- a/qa/tasks/mgr/dashboard/test_pool.py +++ b/qa/tasks/mgr/dashboard/test_pool.py @@ -400,7 +400,7 @@ class PoolTest(DashboardTestCase): }) def test_pool_info(self): - self._get("/api/pool/_info") + self._get("/ui-api/pool/info") self.assertSchemaBody(JObj({ 'pool_names': JList(six.string_types), 'compression_algorithms': JList(six.string_types), @@ -412,4 +412,6 @@ class PoolTest(DashboardTestCase): 'crush_rules_erasure': JList(JObj({}, allow_unknown=True)), 'pg_autoscale_default_mode': six.string_types, 'pg_autoscale_modes': JList(six.string_types), + 'erasure_code_profiles': JList(JObj({}, allow_unknown=True)), + 'used_rules': JObj({}, allow_unknown=True), })) diff --git a/src/pybind/mgr/dashboard/controllers/pool.py b/src/pybind/mgr/dashboard/controllers/pool.py index ac3ab1189b7f9..275c59c44a920 100644 --- a/src/pybind/mgr/dashboard/controllers/pool.py +++ b/src/pybind/mgr/dashboard/controllers/pool.py @@ -4,7 +4,7 @@ from __future__ import absolute_import import time import cherrypy -from . import ApiController, RESTController, Endpoint, ReadPermission, Task +from . import ApiController, RESTController, Endpoint, ReadPermission, Task, UiApiController from .. import mgr from ..security import Scope from ..services.ceph_service import CephService @@ -205,15 +205,19 @@ class Pool(RESTController): def configuration(self, pool_name): return RbdConfiguration(pool_name).list() + +@UiApiController('/pool', Scope.POOL) +class PoolUi(Pool): @Endpoint() @ReadPermission - def _info(self, pool_name=''): - # type: (str) -> dict + def info(self): """Used by the create-pool dialog""" + osd_map_crush = mgr.get('osd_map_crush') + options = mgr.get('config_options')['options'] def rules(pool_type): return [r - for r in mgr.get('osd_map_crush')['rules'] + for r in osd_map_crush['rules'] if r['type'] == pool_type] def all_bluestore(): @@ -222,12 +226,23 @@ class Pool(RESTController): def get_config_option_enum(conf_name): return [[v for v in o['enum_values'] if len(v) > 0] - for o in mgr.get('config_options')['options'] + for o in options if o['name'] == conf_name][0] + used_rules = {} + pool_names = [] + for p in self._pool_list(): + name = p['pool_name'] + rule = p['crush_rule'] + pool_names.append(name) + if rule in used_rules: + used_rules[rule].append(name) + else: + used_rules[rule] = [name] + mgr_config = mgr.get('config') - result = { - "pool_names": [p['pool_name'] for p in self._pool_list()], + return { + "pool_names": pool_names, "crush_rules_replicated": rules(1), "crush_rules_erasure": rules(3), "is_all_bluestore": all_bluestore(), @@ -237,9 +252,6 @@ class Pool(RESTController): "compression_modes": get_config_option_enum('bluestore_compression_mode'), "pg_autoscale_default_mode": mgr_config['osd_pool_default_pg_autoscale_mode'], "pg_autoscale_modes": get_config_option_enum('osd_pool_default_pg_autoscale_mode'), + "erasure_code_profiles": CephService.get_erasure_code_profiles(), + "used_rules": used_rules } - - if pool_name: - result['pool_options'] = RbdConfiguration(pool_name).list() - - return result diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.spec.ts index 20ff612d65d39..6450bc6ade29c 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.spec.ts @@ -37,7 +37,7 @@ describe('PoolService', () => { it('should call getInfo', () => { service.getInfo().subscribe(); - const req = httpTesting.expectOne(`${apiPath}/_info`); + const req = httpTesting.expectOne(`ui-${apiPath}/info`); expect(req.request.method).toBe('GET'); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.ts index 4d85ec483374f..d4382a631e5d2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/api/pool.service.ts @@ -59,8 +59,8 @@ export class PoolService { ); } - getInfo(pool_name?: string) { - return this.http.get(`${this.apiPath}/_info` + (pool_name ? `?pool_name=${pool_name}` : '')); + getInfo() { + return this.http.get(`ui-${this.apiPath}/info`); } list(attrs: string[] = []) { diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/pool-form-info.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/pool-form-info.ts index 4f5b653df38d2..16fa24ca9c7d2 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/models/pool-form-info.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/models/pool-form-info.ts @@ -1,4 +1,5 @@ import { CrushRule } from './crush-rule'; +import { ErasureCodeProfile } from './erasure-code-profile'; export class PoolFormInfo { pool_names: string[]; @@ -11,4 +12,6 @@ export class PoolFormInfo { crush_rules_erasure: CrushRule[]; pg_autoscale_default_mode: string; pg_autoscale_modes: string[]; + erasure_code_profiles: ErasureCodeProfile[]; + used_rules: { [rule_name: string]: string[] }; } -- 2.39.5