Coverage for manila/api/v2/share_instances.py: 99%

86 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 import common 

19from manila.api.openstack import wsgi 

20from manila.api.views import share_instance as instance_view 

21from manila import db 

22from manila import exception 

23from manila import share 

24from manila import utils 

25 

26 

27class ShareInstancesController(wsgi.Controller, wsgi.AdminActionsMixin): 

28 """The share instances API controller for the OpenStack API.""" 

29 

30 resource_name = 'share_instance' 

31 _view_builder_class = instance_view.ViewBuilder 

32 

33 def __init__(self): 

34 self.share_api = share.API() 

35 super(ShareInstancesController, self).__init__() 

36 

37 def _get(self, *args, **kwargs): 

38 return db.share_instance_get(*args, **kwargs) 

39 

40 def _update(self, *args, **kwargs): 

41 db.share_instance_update(*args, **kwargs) 

42 

43 def _delete(self, *args, **kwargs): 

44 return self.share_api.delete_instance(*args, **kwargs) 

45 

46 @wsgi.Controller.api_version('2.3', '2.6') 

47 @wsgi.action('os-reset_status') 

48 def instance_reset_status_legacy(self, req, id, body): 

49 return self._reset_status(req, id, body) 

50 

51 @wsgi.Controller.api_version('2.7') 

52 @wsgi.action('reset_status') 

53 def instance_reset_status(self, req, id, body): 

54 return self._reset_status(req, id, body) 

55 

56 @wsgi.Controller.api_version('2.3', '2.6') 

57 @wsgi.action('os-force_delete') 

58 def instance_force_delete_legacy(self, req, id, body): 

59 return self._force_delete(req, id, body) 

60 

61 @wsgi.Controller.api_version('2.7') 

62 @wsgi.action('force_delete') 

63 def instance_force_delete(self, req, id, body): 

64 return self._force_delete(req, id, body) 

65 

66 @wsgi.Controller.api_version("2.3", "2.34") # noqa 

67 @wsgi.Controller.authorize 

68 def index(self, req): # pylint: disable=function-redefined 

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

70 

71 req.GET.pop('export_location_id', None) 

72 req.GET.pop('export_location_path', None) 

73 instances = db.share_instance_get_all(context) 

74 return self._view_builder.detail_list(req, instances) 

75 

76 @wsgi.Controller.api_version("2.35", "2.68") # noqa 

77 @wsgi.Controller.authorize 

78 def index(self, req): # pylint: disable=function-redefined # noqa F811 

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

80 filters = {} 

81 filters.update(req.GET) 

82 common.remove_invalid_options( 

83 context, filters, ('export_location_id', 'export_location_path')) 

84 

85 instances = db.share_instance_get_all(context, filters) 

86 return self._view_builder.detail_list(req, instances) 

87 

88 @wsgi.Controller.api_version("2.69") # noqa 

89 @wsgi.Controller.authorize 

90 def index(self, req): # pylint: disable=function-redefined # noqa F811 

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

92 filters = {} 

93 filters.update(req.GET) 

94 common.remove_invalid_options( 

95 context, filters, ('export_location_id', 'export_location_path', 

96 'is_soft_deleted')) 

97 if 'is_soft_deleted' in filters: 97 ↛ 102line 97 didn't jump to line 102 because the condition on line 97 was always true

98 is_soft_deleted = utils.get_bool_from_api_params( 

99 'is_soft_deleted', filters) 

100 filters['is_soft_deleted'] = is_soft_deleted 

101 

102 instances = db.share_instance_get_all(context, filters) 

103 return self._view_builder.detail_list(req, instances) 

104 

105 @wsgi.Controller.api_version("2.3") 

106 @wsgi.Controller.authorize 

107 def show(self, req, id): 

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

109 

110 try: 

111 instance = db.share_instance_get(context, id) 

112 except exception.NotFound: 

113 raise exc.HTTPNotFound() 

114 

115 return self._view_builder.detail(req, instance) 

116 

117 @wsgi.Controller.api_version("2.3") 

118 @wsgi.Controller.authorize('index') 

119 def get_share_instances(self, req, share_id): 

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

121 

122 try: 

123 share = self.share_api.get(context, share_id) 

124 except exception.NotFound: 

125 raise exc.HTTPNotFound() 

126 

127 view = instance_view.ViewBuilder() 

128 return view.detail_list(req, share.instances) 

129 

130 

131def create_resource(): 

132 return wsgi.Resource(ShareInstancesController())