Coverage for manila/api/v2/share_snapshot_export_locations.py: 90%
37 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 webob import exc
18from manila.api.openstack import wsgi
19from manila.api.views import share_snapshot_export_locations
20from manila.db import api as db_api
21from manila import exception
22from manila.i18n import _
23from manila import policy
26class ShareSnapshotExportLocationController(wsgi.Controller):
28 def __init__(self):
29 self._view_builder_class = (
30 share_snapshot_export_locations.ViewBuilder)
31 self.resource_name = 'share_snapshot_export_location'
32 super(ShareSnapshotExportLocationController, self).__init__()
34 @wsgi.Controller.api_version('2.32')
35 @wsgi.Controller.authorize
36 def index(self, req, snapshot_id):
37 context = req.environ['manila.context']
38 snapshot = self._verify_snapshot(context, snapshot_id)
39 return self._view_builder.list_export_locations(
40 req, snapshot['export_locations'])
42 @wsgi.Controller.api_version('2.32')
43 @wsgi.Controller.authorize
44 def show(self, req, snapshot_id, export_location_id):
45 context = req.environ['manila.context']
46 self._verify_snapshot(context, snapshot_id)
47 export_location = db_api.share_snapshot_instance_export_location_get(
48 context, export_location_id)
50 return self._view_builder.detail_export_location(req, export_location)
52 def _verify_snapshot(self, context, snapshot_id):
53 try:
54 snapshot = db_api.share_snapshot_get(context, snapshot_id)
55 share = db_api.share_get(context, snapshot['share_id'])
56 if not share['is_public']: 56 ↛ 61line 56 didn't jump to line 61 because the condition on line 56 was always true
57 policy.check_policy(context, 'share', 'get', share)
58 except exception.NotFound:
59 msg = _("Snapshot '%s' not found.") % snapshot_id
60 raise exc.HTTPNotFound(explanation=msg)
61 return snapshot
64def create_resource():
65 return wsgi.Resource(ShareSnapshotExportLocationController())