Coverage for manila/api/views/share_snapshot_export_locations.py: 91%
24 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) 2016 Hitachi Data Systems
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):
20 _collection_name = "share_snapshot_export_locations"
22 def _get_view(self, request, export_location, detail=False):
23 context = request.environ['manila.context']
25 result = {
26 'share_snapshot_export_location': {
27 'id': export_location['id'],
28 'path': export_location['path'],
29 'links': self._get_links(request, export_location['id']),
30 }
31 }
33 ss_el = result['share_snapshot_export_location']
34 if context.is_admin: 34 ↛ 39line 34 didn't jump to line 39 because the condition on line 34 was always true
35 ss_el['share_snapshot_instance_id'] = (
36 export_location['share_snapshot_instance_id'])
37 ss_el['is_admin_only'] = export_location['is_admin_only']
39 if detail:
40 ss_el['created_at'] = export_location['created_at']
41 ss_el['updated_at'] = export_location['updated_at']
43 return result
45 def list_export_locations(self, request, export_locations):
47 context = request.environ['manila.context']
49 result = {self._collection_name: []}
50 for export_location in export_locations:
51 if context.is_admin or not export_location['is_admin_only']: 51 ↛ 56line 51 didn't jump to line 56 because the condition on line 51 was always true
52 result[self._collection_name].append(self._get_view(
53 request,
54 export_location)['share_snapshot_export_location'])
55 else:
56 continue
58 return result
60 def detail_export_location(self, request, export_location):
61 return self._get_view(request, export_location, detail=True)