Coverage for manila/api/views/share_instance.py: 96%

46 statements  

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

1# Licensed under the Apache License, Version 2.0 (the "License"); you may 

2# not use this file except in compliance with the License. You may obtain 

3# a copy of the License at 

4# 

5# http://www.apache.org/licenses/LICENSE-2.0 

6# 

7# Unless required by applicable law or agreed to in writing, software 

8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 

9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 

10# License for the specific language governing permissions and limitations 

11# under the License. 

12 

13from manila.api import common 

14from manila.common import constants 

15 

16 

17class ViewBuilder(common.ViewBuilder): 

18 """Model a server API response as a python dictionary.""" 

19 

20 _collection_name = 'share_instances' 

21 _collection_links = 'share_instances_links' 

22 

23 _detail_version_modifiers = [ 

24 "remove_export_locations", 

25 "add_access_rules_status_field", 

26 "add_replication_fields", 

27 "add_share_type_field", 

28 "add_cast_rules_to_readonly_field", 

29 "add_progress_field", 

30 "translate_creating_from_snapshot_status", 

31 "add_updated_at_field", 

32 ] 

33 

34 def detail_list(self, request, instances): 

35 """Detailed view of a list of share instances.""" 

36 return self._list_view(self.detail, request, instances) 

37 

38 def detail(self, request, share_instance): 

39 """Detailed view of a single share instance.""" 

40 export_locations = [e['path'] for e in share_instance.export_locations] 

41 

42 instance_dict = { 

43 'id': share_instance.get('id'), 

44 'share_id': share_instance.get('share_id'), 

45 'availability_zone': share_instance.get('availability_zone'), 

46 'created_at': share_instance.get('created_at'), 

47 'host': share_instance.get('host'), 

48 'status': share_instance.get('status'), 

49 'share_network_id': share_instance.get('share_network_id'), 

50 'share_server_id': share_instance.get('share_server_id'), 

51 'export_location': share_instance.get('export_location'), 

52 'export_locations': export_locations, 

53 } 

54 

55 self.update_versioned_resource_dict( 

56 request, instance_dict, share_instance) 

57 return {'share_instance': instance_dict} 

58 

59 def _list_view(self, func, request, instances): 

60 """Provide a view for a list of share instances.""" 

61 instances_list = [func(request, instance)['share_instance'] 

62 for instance in instances] 

63 instances_links = self._get_collection_links(request, 

64 instances, 

65 self._collection_name) 

66 instances_dict = {self._collection_name: instances_list} 

67 

68 if instances_links: 

69 instances_dict[self._collection_links] = instances_links 

70 

71 return instances_dict 

72 

73 @common.ViewBuilder.versioned_method("2.9") 

74 def remove_export_locations(self, context, share_instance_dict, 

75 share_instance): 

76 share_instance_dict.pop('export_location') 

77 share_instance_dict.pop('export_locations') 

78 

79 @common.ViewBuilder.versioned_method("2.10") 

80 def add_access_rules_status_field(self, context, instance_dict, 

81 share_instance): 

82 instance_dict['access_rules_status'] = ( 

83 share_instance.get('access_rules_status') 

84 ) 

85 

86 @common.ViewBuilder.versioned_method("2.11") 

87 def add_replication_fields(self, context, instance_dict, share_instance): 

88 instance_dict['replica_state'] = share_instance.get('replica_state') 

89 

90 @common.ViewBuilder.versioned_method("2.22") 

91 def add_share_type_field(self, context, instance_dict, share_instance): 

92 instance_dict['share_type_id'] = share_instance.get('share_type_id') 

93 

94 @common.ViewBuilder.versioned_method("2.30") 

95 def add_cast_rules_to_readonly_field(self, context, instance_dict, 

96 share_instance): 

97 instance_dict['cast_rules_to_readonly'] = share_instance.get( 

98 'cast_rules_to_readonly', False) 

99 

100 @common.ViewBuilder.versioned_method("1.0", "2.53") 

101 def translate_creating_from_snapshot_status(self, context, instance_dict, 

102 share_instance): 

103 if (share_instance.get('status') == 103 ↛ 105line 103 didn't jump to line 105 because the condition on line 103 was never true

104 constants.STATUS_CREATING_FROM_SNAPSHOT): 

105 instance_dict['status'] = constants.STATUS_CREATING 

106 

107 @common.ViewBuilder.versioned_method("2.54") 

108 def add_progress_field(self, context, instance_dict, share_instance): 

109 instance_dict['progress'] = share_instance.get('progress') 

110 

111 @common.ViewBuilder.versioned_method("2.71") 

112 def add_updated_at_field(self, context, instance_dict, share_instance): 

113 instance_dict['updated_at'] = share_instance.get('updated_at')