Coverage for nova/api/openstack/compute/schemas/volumes.py: 100%

18 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-24 11:16 +0000

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

14 

15import copy 

16 

17from nova.api.validation import parameter_types 

18 

19create = { 

20 'type': 'object', 

21 'properties': { 

22 'volume': { 

23 'type': 'object', 

24 'properties': { 

25 'volume_type': {'type': 'string'}, 

26 'metadata': {'type': 'object'}, 

27 'snapshot_id': {'type': 'string'}, 

28 'size': { 

29 'type': ['integer', 'string'], 

30 'pattern': '^[0-9]+$', 

31 'minimum': 1 

32 }, 

33 'availability_zone': {'type': 'string'}, 

34 'display_name': {'type': 'string'}, 

35 'display_description': {'type': 'string'}, 

36 }, 

37 'required': ['size'], 

38 'additionalProperties': False, 

39 }, 

40 }, 

41 'required': ['volume'], 

42 'additionalProperties': False, 

43} 

44 

45 

46snapshot_create = { 

47 'type': 'object', 

48 'properties': { 

49 'snapshot': { 

50 'type': 'object', 

51 'properties': { 

52 'volume_id': {'type': 'string'}, 

53 'force': parameter_types.boolean, 

54 'display_name': {'type': 'string'}, 

55 'display_description': {'type': 'string'}, 

56 }, 

57 'required': ['volume_id'], 

58 'additionalProperties': False, 

59 }, 

60 }, 

61 'required': ['snapshot'], 

62 'additionalProperties': False, 

63} 

64 

65create_volume_attachment = { 

66 'type': 'object', 

67 'properties': { 

68 'volumeAttachment': { 

69 'type': 'object', 

70 'properties': { 

71 'volumeId': parameter_types.volume_id, 

72 'device': { 

73 'type': ['string', 'null'], 

74 # NOTE: The validation pattern from match_device() in 

75 # nova/block_device.py. 

76 'pattern': '(^/dev/x{0,1}[a-z]{0,1}d{0,1})([a-z]+)[0-9]*$' 

77 }, 

78 }, 

79 'required': ['volumeId'], 

80 'additionalProperties': False, 

81 }, 

82 }, 

83 'required': ['volumeAttachment'], 

84 'additionalProperties': False, 

85} 

86create_volume_attachment_v249 = copy.deepcopy(create_volume_attachment) 

87create_volume_attachment_v249['properties']['volumeAttachment'][ 

88 'properties']['tag'] = parameter_types.tag 

89 

90create_volume_attachment_v279 = copy.deepcopy(create_volume_attachment_v249) 

91create_volume_attachment_v279['properties']['volumeAttachment'][ 

92 'properties']['delete_on_termination'] = parameter_types.boolean 

93 

94update_volume_attachment = copy.deepcopy(create_volume_attachment) 

95del update_volume_attachment['properties']['volumeAttachment'][ 

96 'properties']['device'] 

97 

98# NOTE(brinzhang): Allow attachment_id, serverId, device, tag, and 

99# delete_on_termination (i.e., follow the content of the GET response) 

100# to be specified for RESTfulness, even though we will not allow updating 

101# all of them. 

102update_volume_attachment_v285 = { 

103 'type': 'object', 

104 'properties': { 

105 'volumeAttachment': { 

106 'type': 'object', 

107 'properties': { 

108 'volumeId': parameter_types.volume_id, 

109 'device': { 

110 'type': ['string', 'null'], 

111 # NOTE: The validation pattern from match_device() in 

112 # nova/block_device.py. 

113 'pattern': '(^/dev/x{0,1}[a-z]{0,1}d{0,1})([a-z]+)[0-9]*$' 

114 }, 

115 'tag': parameter_types.tag, 

116 'delete_on_termination': parameter_types.boolean, 

117 'serverId': parameter_types.server_id, 

118 'id': parameter_types.attachment_id 

119 }, 

120 'required': ['volumeId'], 

121 'additionalProperties': False, 

122 }, 

123 }, 

124 'required': ['volumeAttachment'], 

125 'additionalProperties': False, 

126} 

127 

128index_query = { 

129 'type': 'object', 

130 'properties': { 

131 'limit': parameter_types.multi_params( 

132 parameter_types.non_negative_integer), 

133 'offset': parameter_types.multi_params( 

134 parameter_types.non_negative_integer) 

135 }, 

136 # NOTE(gmann): This is kept True to keep backward compatibility. 

137 # As of now Schema validation stripped out the additional parameters and 

138 # does not raise 400. In microversion 2.75, we have blocked the additional 

139 # parameters. 

140 'additionalProperties': True 

141} 

142 

143detail_query = index_query 

144 

145index_query_275 = copy.deepcopy(index_query) 

146index_query_275['additionalProperties'] = False 

147 

148# TODO(stephenfin): Remove additionalProperties in a future API version 

149show_query = { 

150 'type': 'object', 

151 'properties': {}, 

152 'additionalProperties': True 

153} 

154 

155# TODO(stephenfin): Remove additionalProperties in a future API version 

156snapshot_show_query = { 

157 'type': 'object', 

158 'properties': {}, 

159 'additionalProperties': True 

160}