Coverage for manila/api/v2/scheduler_stats.py: 96%
50 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# Copyright (c) 2015 Clinton Knight. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14from webob import exc
16from manila.api.openstack import wsgi
17from manila.api.views import scheduler_stats as scheduler_stats_views
18from manila import exception
19from manila.i18n import _
20from manila.scheduler import rpcapi
21from manila.share import share_types
24class SchedulerStatsController(wsgi.Controller):
25 """The Scheduler Stats API controller for the OpenStack API."""
27 resource_name = 'scheduler_stats:pools'
29 def __init__(self):
30 self.scheduler_api = rpcapi.SchedulerAPI()
31 self._view_builder_class = scheduler_stats_views.ViewBuilder
32 super(SchedulerStatsController, self).__init__()
34 @wsgi.Controller.api_version('1.0', '2.22')
35 @wsgi.Controller.authorize('index')
36 def pools_index(self, req):
37 """Returns a list of storage pools known to the scheduler."""
38 return self._pools(req, action='index')
40 @wsgi.Controller.api_version('2.23') # noqa
41 @wsgi.Controller.authorize('index')
42 def pools_index(self, req): # pylint: disable=function-redefined # noqa F811
43 return self._pools(req, action='index', enable_share_type=True)
45 @wsgi.Controller.api_version('1.0', '2.22')
46 @wsgi.Controller.authorize('detail')
47 def pools_detail(self, req):
48 """Returns a detailed list of storage pools known to the scheduler."""
49 return self._pools(req, action='detail')
51 @wsgi.Controller.api_version('2.23') # noqa
52 @wsgi.Controller.authorize('detail')
53 def pools_detail(self, req): # pylint: disable=function-redefined # noqa F811
54 return self._pools(req, action='detail', enable_share_type=True)
56 def _pools(self, req, action='index', enable_share_type=False):
57 context = req.environ['manila.context']
58 search_opts = {}
59 search_opts.update(req.GET)
61 if enable_share_type:
62 req_share_type = search_opts.pop('share_type', None)
63 if req_share_type: 63 ↛ 74line 63 didn't jump to line 74 because the condition on line 63 was always true
64 try:
65 share_type = share_types.get_share_type_by_name_or_id(
66 context, req_share_type)
68 search_opts['capabilities'] = share_type.get('extra_specs',
69 {})
70 except exception.ShareTypeNotFound:
71 msg = _("Share type %s not found.") % req_share_type
72 raise exc.HTTPBadRequest(explanation=msg)
74 try:
75 pools = self.scheduler_api.get_pools(context,
76 filters=search_opts,
77 cached=True)
78 except exception.NotAuthorized:
79 raise exc.HTTPForbidden()
80 detail = (action == 'detail')
81 return self._view_builder.pools(pools, detail=detail)
84def create_resource():
85 return wsgi.Resource(SchedulerStatsController())