Coverage for manila/api/schemas/share_snapshots.py: 100%

14 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. 

12import copy 

13from oslo_config import cfg 

14 

15from manila.api.validation import parameter_types 

16from manila.api.validation import response_types 

17 

18CONF = cfg.CONF 

19 

20# Base list snapshots query (v2.0+) 

21index_request_query = { 

22 'type': 'object', 

23 'properties': { 

24 # Pagination 

25 'limit': parameter_types.single_param( 

26 parameter_types.non_negative_integer 

27 ), 

28 'offset': parameter_types.single_param( 

29 parameter_types.non_negative_integer 

30 ), 

31 

32 # Sorting 

33 'sort_key': parameter_types.single_param({ 

34 'type': 'string', 

35 'minLength': 1, 

36 'maxLength': 255, 

37 }), 

38 'sort_dir': parameter_types.single_param({ 

39 'type': 'string', 

40 'default': 'desc', 

41 'description': 'Sort direction', 

42 }), 

43 

44 # Project Scoping 

45 'project_id': parameter_types.single_param({ 

46 'type': 'string', 

47 'minLength': 1, 

48 'maxLength': 255, 

49 }), 

50 # Admin only 

51 'all_tenants': parameter_types.single_param({ 

52 **parameter_types.boolean, 

53 'description': ( 

54 "Set 1 to list resources for all projects;" 

55 "set 0 to list resources only for the current project" 

56 ) 

57 }), 

58 

59 # Basic filters 

60 'name': parameter_types.single_param({ 

61 'type': 'string', 

62 'minLength': 1, 

63 'maxLength': 255, 

64 }), 

65 'description': parameter_types.single_param({ 

66 'type': 'string', 

67 'minLength': 1, 

68 'maxLength': 255, 

69 }), 

70 'status': parameter_types.single_param({ 

71 'type': 'string', 

72 'minLength': 1, 

73 'maxLength': 255, 

74 }), 

75 'share_id': parameter_types.single_param({ 

76 'type': 'string', 

77 'minLength': 1, 

78 'maxLength': 255, 

79 }), 

80 'size': parameter_types.single_param( 

81 parameter_types.non_negative_integer, 

82 ), 

83 }, 

84 'required': [], 

85 'additionalProperties': True, 

86} 

87 

88# >= v2.36: like filters for name~/description~ 

89index_request_query_v236 = copy.copy(index_request_query) 

90index_request_query_v236['properties'].update({ 

91 'name~': parameter_types.single_param({ 

92 'type': 'string', 

93 'minLength': 1, 

94 'maxLength': 255, 

95 }), 

96 'description~': parameter_types.single_param({ 

97 'type': 'string', 

98 'minLength': 1, 

99 'maxLength': 255 

100 }), 

101}) 

102 

103# >= v2.73: metadata filter 

104index_request_query_v273 = copy.copy(index_request_query_v236) 

105index_request_query_v273['properties'].update({ 

106 'metadata': parameter_types.single_param({ 

107 'type': 'string', 

108 'minLength': 1, 

109 'maxLength': 4096, 

110 }), 

111}) 

112 

113# >= v2.79: with_count flag added on top 

114index_request_query_v279 = copy.copy(index_request_query_v273) 

115index_request_query_v279['properties'].update({ 

116 'with_count': parameter_types.single_param({ 

117 **parameter_types.boolean, 

118 'default': False, 

119 'description': "Show count in share snapshot list API response" 

120 }), 

121}) 

122 

123_snapshot_response = { 

124 'type': 'object', 

125 'properties': { 

126 'id': {'type': ['string', 'integer'], 

127 'description': "The UUID of the snapshot."}, 

128 'links': response_types.links, 

129 'name': {'type': ['string', 'null'], 

130 'description': "The user-defined name of the snapshot."}, 

131 }, 

132 'required': ['id', 'links', 'name'], 

133 'additionalProperties': False, 

134} 

135 

136index_response_body = { 

137 'type': 'object', 

138 'properties': { 

139 'snapshots': { 

140 'type': 'array', 

141 'items': _snapshot_response, 

142 }, 

143 'share_snapshots_links': response_types.collection_links, 

144 # >= v2.79 when with_count=True 

145 'count': {'type': 'integer', 'minimum': 0}, 

146 }, 

147 'required': ['snapshots'], 

148 'additionalProperties': False, 

149}