Coverage for manila/api/views/services.py: 96%
26 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 Mirantis inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16from manila.api import common
19class ViewBuilder(common.ViewBuilder):
21 _collection_name = "services"
22 _detail_version_modifiers = [
23 "add_disabled_reason_field",
24 "add_ensuring_field",
25 ]
27 def summary(self, request, service):
28 """Summary view of a single service."""
29 keys = 'host', 'binary', 'status',
30 service_dict = {key: service.get(key) for key in keys}
31 self.update_versioned_resource_dict(request, service_dict, service)
32 return service_dict
34 def detail(self, request, service):
35 """Detailed view of a single service."""
36 keys = ('id', 'binary', 'host', 'zone', 'status',
37 'state', 'updated_at')
38 service_dict = {key: service.get(key) for key in keys}
39 self.update_versioned_resource_dict(request, service_dict, service)
40 return service_dict
42 def detail_list(self, request, services):
43 """Detailed view of a list of services."""
44 services_list = [self.detail(request, s) for s in services]
45 services_dict = dict(services=services_list)
46 return services_dict
48 @common.ViewBuilder.versioned_method("2.83")
49 def add_disabled_reason_field(self, context, service_dict, service):
50 service_dict.pop('disabled', None)
51 service_dict['status'] = service.get('status')
52 service_dict['disabled_reason'] = service.get('disabled_reason')
54 @common.ViewBuilder.versioned_method("2.86")
55 def add_ensuring_field(self, context, service_dict, service):
56 service_dict['ensuring'] = service.get('ensuring')