Coverage for manila/api/v2/share_instance_export_locations.py: 94%

47 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2026-02-18 22:19 +0000

1# Copyright 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. 

15 

16from webob import exc 

17 

18from manila.api.openstack import wsgi 

19from manila.api.schemas import share_instance_export_locations as schema 

20from manila.api import validation 

21from manila.api.views import export_locations as export_locations_views 

22from manila.db import api as db_api 

23from manila import exception 

24from manila.i18n import _ 

25from manila import policy 

26 

27 

28class ShareInstanceExportLocationController(wsgi.Controller): 

29 """The Share Instance Export Locations API controller.""" 

30 

31 def __init__(self): 

32 self._view_builder_class = export_locations_views.ViewBuilder 

33 self.resource_name = 'share_instance_export_location' 

34 super(ShareInstanceExportLocationController, self).__init__() 

35 

36 def _verify_share_instance(self, context, share_instance_id): 

37 try: 

38 share_instance = db_api.share_instance_get(context, 

39 share_instance_id, 

40 with_share_data=True) 

41 if not share_instance['is_public']: 41 ↛ exitline 41 didn't return from function '_verify_share_instance' because the condition on line 41 was always true

42 policy.check_policy(context, 'share_instance', 'show', 

43 share_instance) 

44 except exception.NotFound: 

45 msg = _("Share instance '%s' not found.") % share_instance_id 

46 raise exc.HTTPNotFound(explanation=msg) 

47 

48 @wsgi.Controller.api_version('2.9') 

49 @wsgi.Controller.authorize 

50 @validation.response_body_schema(schema.index_response_body, '2.9', '2.13') 

51 @validation.response_body_schema( 

52 schema.index_response_body_v214, '2.14', '2.86') 

53 @validation.response_body_schema(schema.index_response_body_v287, '2.87') 

54 def index(self, req, share_instance_id): 

55 """Return a list of export locations for the share instance.""" 

56 context = req.environ['manila.context'] 

57 self._verify_share_instance(context, share_instance_id) 

58 export_locations = db_api.export_location_get_all_by_share_instance_id( 

59 context, share_instance_id) 

60 return self._view_builder.summary_list(req, export_locations) 

61 

62 @wsgi.Controller.api_version('2.9') 

63 @wsgi.Controller.authorize 

64 @validation.response_body_schema(schema.show_response_body, '2.9', '2.13') 

65 @validation.response_body_schema( 

66 schema.show_response_body_v214, '2.14', '2.86') 

67 @validation.response_body_schema(schema.show_response_body_v287, '2.87') 

68 def show(self, req, share_instance_id, export_location_uuid): 

69 """Return data about the requested export location.""" 

70 context = req.environ['manila.context'] 

71 self._verify_share_instance(context, share_instance_id) 

72 try: 

73 export_location = db_api.export_location_get_by_uuid( 

74 context, export_location_uuid) 

75 return self._view_builder.detail(req, export_location) 

76 except exception.ExportLocationNotFound as e: 

77 raise exc.HTTPNotFound(explanation=e.msg) 

78 

79 

80def create_resource(): 

81 return wsgi.Resource(ShareInstanceExportLocationController())