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

9 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-04-17 15:08 +0000

1# Copyright 2019 INSPUR 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 

15from nova.api.validation import parameter_types 

16 

17# TODO(stephenfin): Restrict the value to 'null' in a future API version 

18shelve = { 

19 'type': 'object', 

20 'properties': { 

21 'shelve': {}, 

22 }, 

23 'required': ['shelve'], 

24 'additionalProperties': False, 

25} 

26 

27# TODO(stephenfin): Restrict the value to 'null' in a future API version 

28shelve_offload = { 

29 'type': 'object', 

30 'properties': { 

31 'shelveOffload': {}, 

32 }, 

33 'required': ['shelveOffload'], 

34 'additionalProperties': False, 

35} 

36 

37unshelve = { 

38 'type': 'object', 

39 'properties': { 

40 'unshelve': {}, 

41 }, 

42 'required': ['unshelve'], 

43 'additionalProperties': False, 

44} 

45 

46# NOTE(brinzhang): For older microversion there will be no change as 

47# schema is applied only for version < 2.91 with unshelve a server API. 

48# Anything working in old version keep working as it is. 

49unshelve_v277 = { 

50 'type': 'object', 

51 'properties': { 

52 'unshelve': { 

53 'type': ['object', 'null'], 

54 'properties': { 

55 'availability_zone': parameter_types.name 

56 }, 

57 # NOTE: The allowed request body is {'unshelve': null} or 

58 # {'unshelve': {'availability_zone': <string>}}, not allowed 

59 # {'unshelve': {}} as the request body for unshelve. 

60 'required': ['availability_zone'], 

61 'additionalProperties': False, 

62 }, 

63 }, 

64 'required': ['unshelve'], 

65 'additionalProperties': False, 

66} 

67 

68# NOTE(rribaud): 

69# schema is applied only for version >= 2.91 with unshelve a server API. 

70# Add host parameter to specify to unshelve to this specific host. 

71# 

72# Schema has been redefined for better clarity instead of extend 2.77. 

73# 

74# API can be called with the following body: 

75# 

76# - {"unshelve": null} (Keep compatibility with previous microversions) 

77# 

78# or 

79# 

80# - {"unshelve": {"availability_zone": <string>}} 

81# - {"unshelve": {"availability_zone": null}} (Unpin availability zone) 

82# - {"unshelve": {"host": <fqdn>}} 

83# - {"unshelve": {"availability_zone": <string>, "host": <fqdn>}} 

84# - {"unshelve": {"availability_zone": null, "host": <fqdn>}} 

85# 

86# 

87# Everything else is not allowed, examples: 

88# 

89# - {"unshelve": {}} 

90# - {"unshelve": {"host": <fqdn>, "host": <fqdn>}} 

91# - {"unshelve": {"foo": <string>}} 

92 

93unshelve_v291 = { 

94 "type": "object", 

95 "properties": { 

96 "unshelve": { 

97 "oneOf": [ 

98 { 

99 "type": ["object"], 

100 "properties": { 

101 "availability_zone": { 

102 "oneOf": [ 

103 {"type": ["null"]}, 

104 {"type": "string"}] 

105 }, 

106 "host": { 

107 "type": "string" 

108 } 

109 }, 

110 "additionalProperties": False 

111 }, 

112 {"type": ["null"]} 

113 ] 

114 } 

115 }, 

116 "required": ["unshelve"], 

117 "additionalProperties": False 

118} 

119 

120shelve_response = { 

121 'type': 'null', 

122} 

123 

124shelve_offload_response = { 

125 'type': 'null', 

126} 

127 

128unshelve_response = { 

129 'type': 'null', 

130}