Revision aa197ee4 api/actions.py
b/api/actions.py | ||
---|---|---|
25 | 25 |
'''Decorator for functions implementing server actions. |
26 | 26 |
`name` is the key in the dict passed by the client. |
27 | 27 |
''' |
28 |
|
|
28 |
|
|
29 | 29 |
def decorator(func): |
30 | 30 |
server_actions[name] = func |
31 | 31 |
return func |
... | ... | |
53 | 53 |
# itemNotFound (404), |
54 | 54 |
# buildInProgress (409), |
55 | 55 |
# overLimit (413) |
56 |
|
|
56 |
|
|
57 | 57 |
try: |
58 | 58 |
password = args['adminPass'] |
59 | 59 |
except KeyError: |
... | ... | |
72 | 72 |
# itemNotFound (404), |
73 | 73 |
# buildInProgress (409), |
74 | 74 |
# overLimit (413) |
75 |
|
|
75 |
|
|
76 | 76 |
reboot_type = args.get('type', '') |
77 | 77 |
if reboot_type not in ('SOFT', 'HARD'): |
78 | 78 |
raise BadRequest('Malformed Request.') |
... | ... | |
84 | 84 |
# Normal Response Code: 202 |
85 | 85 |
# Error Response Codes: serviceUnavailable (503), |
86 | 86 |
# itemNotFound (404) |
87 |
|
|
87 |
|
|
88 | 88 |
if args: |
89 | 89 |
raise BadRequest('Malformed Request.') |
90 | 90 |
startup_instance(vm) |
... | ... | |
95 | 95 |
# Normal Response Code: 202 |
96 | 96 |
# Error Response Codes: serviceUnavailable (503), |
97 | 97 |
# itemNotFound (404) |
98 |
|
|
98 |
|
|
99 | 99 |
if args: |
100 | 100 |
raise BadRequest('Malformed Request.') |
101 | 101 |
shutdown_instance(vm) |
... | ... | |
129 | 129 |
# serverCapacityUnavailable (503), |
130 | 130 |
# overLimit (413), |
131 | 131 |
# resizeNotAllowed (403) |
132 |
|
|
132 |
|
|
133 | 133 |
raise ServiceUnavailable('Resize not supported.') |
134 | 134 |
|
135 | 135 |
@server_action('confirmResize') |
... | ... | |
145 | 145 |
# serverCapacityUnavailable (503), |
146 | 146 |
# overLimit (413), |
147 | 147 |
# resizeNotAllowed (403) |
148 |
|
|
148 |
|
|
149 | 149 |
raise ServiceUnavailable('Resize not supported.') |
150 | 150 |
|
151 | 151 |
@server_action('revertResize') |
... | ... | |
184 | 184 |
# itemNotFound (404), |
185 | 185 |
# buildInProgress (409), |
186 | 186 |
# overLimit (413) |
187 |
|
|
187 |
|
|
188 | 188 |
console_type = args.get('type', '') |
189 | 189 |
if console_type != 'vnc': |
190 | 190 |
raise BadRequest('Type can only be "vnc".') |
... | ... | |
192 | 192 |
# Use RAPI to get VNC console information for this instance |
193 | 193 |
if get_rsapi_state(vm) != 'ACTIVE': |
194 | 194 |
raise BadRequest('Server not in ACTIVE state.') |
195 |
|
|
195 |
|
|
196 | 196 |
if settings.TEST: |
197 | 197 |
console_data = {'kind': 'vnc', 'host': 'ganeti_node', 'port': 1000} |
198 | 198 |
else: |
199 | 199 |
console_data = get_instance_console(vm) |
200 |
|
|
200 |
|
|
201 | 201 |
if console_data['kind'] != 'vnc': |
202 | 202 |
raise ServiceUnavailable('Could not create a console of requested type.') |
203 |
|
|
203 |
|
|
204 | 204 |
# Let vncauthproxy decide on the source port. |
205 | 205 |
# The alternative: static allocation, e.g. |
206 | 206 |
# sport = console_data['port'] - 1000 |
... | ... | |
208 | 208 |
daddr = console_data['host'] |
209 | 209 |
dport = console_data['port'] |
210 | 210 |
password = random_password() |
211 |
|
|
211 |
|
|
212 | 212 |
try: |
213 | 213 |
if settings.TEST: |
214 | 214 |
fwd = {'source_port': 1234, 'status': 'OK'} |
... | ... | |
219 | 219 |
|
220 | 220 |
if fwd['status'] != "OK": |
221 | 221 |
raise ServiceUnavailable('Could not allocate VNC console.') |
222 |
|
|
222 |
|
|
223 | 223 |
console = { |
224 | 224 |
'type': 'vnc', |
225 | 225 |
'host': getfqdn(), |
226 | 226 |
'port': fwd['source_port'], |
227 | 227 |
'password': password} |
228 |
|
|
228 |
|
|
229 | 229 |
if request.serialization == 'xml': |
230 | 230 |
mimetype = 'application/xml' |
231 | 231 |
data = render_to_string('console.xml', {'console': console}) |
232 | 232 |
else: |
233 | 233 |
mimetype = 'application/json' |
234 | 234 |
data = json.dumps({'console': console}) |
235 |
|
|
235 |
|
|
236 | 236 |
return HttpResponse(data, mimetype=mimetype, status=200) |
237 | 237 |
|
238 | 238 |
|
... | ... | |
246 | 246 |
# badMediaType(415), |
247 | 247 |
# itemNotFound (404), |
248 | 248 |
# overLimit (413) |
249 |
|
|
249 |
|
|
250 | 250 |
server_id = args.get('serverRef', None) |
251 | 251 |
if not server_id: |
252 | 252 |
raise BadRequest('Malformed Request.') |
... | ... | |
265 | 265 |
# badMediaType(415), |
266 | 266 |
# itemNotFound (404), |
267 | 267 |
# overLimit (413) |
268 |
|
|
268 |
|
|
269 | 269 |
server_id = args.get('serverRef', None) |
270 | 270 |
if not server_id: |
271 | 271 |
raise BadRequest('Malformed Request.') |
Also available in: Unified diff