Coverage for manila/api/v2/share_snapshot_instance_export_locations.py: 90%
38 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 ShareSnapshotInstanceExportLocationController(wsgi.Controller):
28 def __init__(self):
29 self._view_builder_class = (
30 share_snapshot_export_locations.ViewBuilder)
31 self.resource_name = 'share_snapshot_instance_export_location'
32 super(ShareSnapshotInstanceExportLocationController, self).__init__()
34 @wsgi.Controller.api_version('2.32')
35 @wsgi.Controller.authorize
36 def index(self, req, snapshot_instance_id):
37 context = req.environ['manila.context']
38 instance = self._verify_snapshot_instance(
39 context, snapshot_instance_id)
40 export_locations = (
41 db_api.share_snapshot_instance_export_locations_get_all(
42 context, instance['id']))
44 return self._view_builder.list_export_locations(req, export_locations)
46 @wsgi.Controller.api_version('2.32')
47 @wsgi.Controller.authorize
48 def show(self, req, snapshot_instance_id, export_location_id):
49 context = req.environ['manila.context']
50 self._verify_snapshot_instance(context, snapshot_instance_id)
51 export_location = db_api.share_snapshot_instance_export_location_get(
52 context, export_location_id)
53 return self._view_builder.detail_export_location(req, export_location)
55 def _verify_snapshot_instance(self, context, snapshot_instance_id):
56 try:
57 snapshot_instance = db_api.share_snapshot_instance_get(
58 context, snapshot_instance_id)
59 share = db_api.share_get(
60 context, snapshot_instance.share_instance['share_id'])
61 if not share['is_public']: 61 ↛ 66line 61 didn't jump to line 66 because the condition on line 61 was always true
62 policy.check_policy(context, 'share', 'get', share)
63 except exception.NotFound:
64 msg = _("Snapshot instance '%s' not found.") % snapshot_instance_id
65 raise exc.HTTPNotFound(explanation=msg)
66 return snapshot_instance
69def create_resource():
70 return wsgi.Resource(ShareSnapshotInstanceExportLocationController())