Coverage for manila/api/v2/share_replica_export_locations.py: 100%
48 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# 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.
15from webob import exc
17from manila.api.openstack import wsgi
18from manila.api.views import export_locations as export_locations_views
19from manila.db import api as db_api
20from manila import exception
21from manila.i18n import _
23PRE_GRADUATION_VERSION = '2.55'
24GRADUATION_VERSION = '2.56'
27class ShareReplicaExportLocationController(wsgi.Controller):
28 """The Share Instance Export Locations API controller."""
30 def __init__(self):
31 self._view_builder_class = export_locations_views.ViewBuilder
32 self.resource_name = 'share_replica_export_location'
33 super(ShareReplicaExportLocationController, self).__init__()
35 def _verify_share_replica(self, context, share_replica_id):
36 try:
37 db_api.share_replica_get(context, share_replica_id)
38 except exception.NotFound:
39 msg = _("Share replica '%s' not found.") % share_replica_id
40 raise exc.HTTPNotFound(explanation=msg)
42 @wsgi.Controller.api_version(
43 '2.47', PRE_GRADUATION_VERSION, experimental=True)
44 def index(self, req, share_replica_id):
45 return self._index(req, share_replica_id)
47 # pylint: disable=function-redefined
48 @wsgi.Controller.api_version(GRADUATION_VERSION) # noqa
49 def index(self, req, share_replica_id): # noqa F811
50 return self._index(req, share_replica_id)
52 # pylint: enable=function-redefined
53 @wsgi.Controller.authorize('index')
54 def _index(self, req, share_replica_id):
55 """Return a list of export locations for the share instance."""
56 context = req.environ['manila.context']
57 self._verify_share_replica(context, share_replica_id)
58 export_locations = db_api.export_location_get_all_by_share_instance_id(
59 context, share_replica_id,
60 include_admin_only=context.is_admin)
61 return self._view_builder.summary_list(req, export_locations,
62 replica=True)
64 @wsgi.Controller.api_version(
65 '2.47', PRE_GRADUATION_VERSION, experimental=True)
66 def show(self, req, share_replica_id, export_location_uuid):
67 return self._show(req, share_replica_id, export_location_uuid)
69 # pylint: disable=function-redefined
70 @wsgi.Controller.api_version(GRADUATION_VERSION) # noqa
71 def show(self, req, share_replica_id, export_location_uuid): # noqa F811
72 return self._show(req, share_replica_id, export_location_uuid)
74 # pylint: enable=function-redefined
75 @wsgi.Controller.authorize('show')
76 def _show(self, req, share_replica_id, export_location_uuid):
77 """Return data about the requested export location."""
78 context = req.environ['manila.context']
79 self._verify_share_replica(context, share_replica_id)
80 try:
81 export_location = db_api.export_location_get_by_uuid(
82 context, export_location_uuid)
83 return self._view_builder.detail(req, export_location,
84 replica=True)
85 except exception.ExportLocationNotFound as e:
86 raise exc.HTTPNotFound(explanation=e.msg)
89def create_resource():
90 return wsgi.Resource(ShareReplicaExportLocationController())