Revision e51c7d5b kamaki/clients/compute/rest_api.py
b/kamaki/clients/compute/rest_api.py | ||
---|---|---|
101 | 101 |
self.set_param('status', status, iff=status) |
102 | 102 |
self.set_param('host', host, iff=host) |
103 | 103 |
|
104 |
path = path4url('servers', 'detail' if detail else server_id)
|
|
104 |
path = path4url('servers', 'detail' if detail else (server_id or ''))
|
|
105 | 105 |
return self.get(path, success=success, **kwargs) |
106 | 106 |
|
107 | 107 |
def servers_post( |
... | ... | |
263 | 263 |
path = path4url('servers', server_id, 'action') |
264 | 264 |
return self.post(path, data=json_data, success=success, **kwargs) |
265 | 265 |
|
266 |
""" |
|
267 |
def servers_actions_post |
|
268 |
def servers_ips_get |
|
269 |
|
|
270 |
def servers_get(self, server_id='', command='', success=200, **kwargs): |
|
271 |
""GET base_url/servers[/server_id][/command] request |
|
272 |
|
|
273 |
:param server_id: integer (as int or str) |
|
274 |
|
|
275 |
:param command: 'ips', 'stats', or '' |
|
266 |
def servers_ips_get( |
|
267 |
self, server_id, |
|
268 |
network_id=None, changes_since=None, success=(304, 200), |
|
269 |
**kwargs): |
|
270 |
"""GET base_url/servers/<server_id>/ips[/network_id] |
|
276 | 271 |
|
277 |
:param success: success code or list or tupple of accepted success |
|
278 |
codes. if server response code is not in this list, a ClientError |
|
279 |
raises |
|
272 |
:param changes_since: time/date stamp in UNIX/epoch time. Checks for |
|
273 |
changes since a previous request. |
|
280 | 274 |
|
281 | 275 |
:returns: request response |
282 |
"" |
|
283 |
path = path4url('servers', server_id, command) |
|
276 |
""" |
|
277 |
self.set_param('changes-since', changes_since, iff=changes_since) |
|
278 |
path = path4url('servers', server_id, 'ips', network_id or '') |
|
279 |
return self.get(path, success=success, **kwargs) |
|
284 | 280 |
|
285 |
def servers_post(
|
|
281 |
def images_get(
|
|
286 | 282 |
self, |
287 |
server_id='', |
|
288 |
command='', |
|
289 |
json_data=None, |
|
290 |
success=202, |
|
283 |
image_id='', |
|
284 |
detail=False, |
|
285 |
changes_since=None, |
|
286 |
server_name=None, |
|
287 |
name=None, |
|
288 |
status=None, |
|
289 |
marker=None, |
|
290 |
limit=None, |
|
291 |
type=None, |
|
292 |
success=200, |
|
291 | 293 |
**kwargs): |
292 |
""POST base_url/servers[/server_id]/[command] request |
|
293 |
|
|
294 |
:param server_id: integer (as int or str) |
|
294 |
"""GET base_url[/image_id][/command] |
|
295 | 295 |
|
296 |
:param command: 'ips', 'stats', or ''
|
|
296 |
:param image_id: (str) ignored if detail
|
|
297 | 297 |
|
298 |
:param json_data: a json-formated dict that will be send as data
|
|
298 |
:param detail: (bool)
|
|
299 | 299 |
|
300 |
:param success: success code or list or tupple of accepted success |
|
301 |
codes. if server response code is not in this list, a ClientError |
|
302 |
raises |
|
300 |
--- Parameters --- |
|
301 |
:param changes_since: when the image last changed status |
|
303 | 302 |
|
304 |
:returns: request response |
|
305 |
"" |
|
306 |
data = json_data |
|
307 |
if json_data: |
|
308 |
data = json.dumps(json_data) |
|
309 |
self.set_header('Content-Type', 'application/json') |
|
310 |
self.set_header('Content-Length', len(data)) |
|
303 |
:param server_name: Name of the server in URL format |
|
311 | 304 |
|
312 |
path = path4url('servers', server_id, command) |
|
313 |
return self.post(path, data=data, success=success, **kwargs) |
|
314 |
""" |
|
305 |
:param name: Name of the image |
|
315 | 306 |
|
316 |
def flavors_get(self, flavor_id='', command='', success=200, **kwargs): |
|
317 |
"""GET base_url[/flavor_id][/command] |
|
307 |
:param status: Status of the image (e.g. filter on "ACTIVE") |
|
318 | 308 |
|
319 |
:param flavor_id: integer (str or int)
|
|
309 |
:param marker: UUID of the image at which you want to set a marker
|
|
320 | 310 |
|
321 |
:param command: flavor service command
|
|
311 |
:param limit: Integer value for the limit of values to return
|
|
322 | 312 |
|
323 |
:param success: success code or list or tupple of accepted success |
|
324 |
codes. if server response code is not in this list, a ClientError |
|
325 |
raises |
|
313 |
:param type: Type of image (e.g. BASE, SERVER, or ALL) |
|
326 | 314 |
|
327 | 315 |
:returns: request response |
328 | 316 |
""" |
329 |
path = path4url('flavors', flavor_id, command) |
|
330 |
return self.get(path, success=success, **kwargs) |
|
317 |
if not image_id: |
|
318 |
self.set_param('changes-since', changes_since, iff=changes_since) |
|
319 |
self.set_param('name', name, iff=name) |
|
320 |
self.set_param('status', status, iff=status) |
|
321 |
self.set_param('marker', marker, iff=marker) |
|
322 |
self.set_param('limit', limit, iff=limit) |
|
323 |
self.set_param('type', type, iff=type) |
|
324 |
self.set_param('server', server_name, iff=server_name) |
|
331 | 325 |
|
332 |
def images_get(self, image_id='', command='', success=200, **kwargs):
|
|
333 |
"""GET base_url[/image_id][/command]
|
|
326 |
path = path4url('images', 'detail' if detail else (image_id or ''))
|
|
327 |
return self.get(path, success=success, **kwargs)
|
|
334 | 328 |
|
335 |
:param image_id: string |
|
329 |
def images_delete(self, image_id='', success=204, **kwargs): |
|
330 |
"""DEL ETE base_url/images/<image_id> |
|
336 | 331 |
|
337 |
:param command: image server command |
|
332 |
:returns: request response |
|
333 |
""" |
|
334 |
path = path4url('images', image_id) |
|
335 |
return self.delete(path, success=success, **kwargs) |
|
338 | 336 |
|
339 |
:param success: success code or list or tupple of accepted success |
|
340 |
codes. if server response code is not in this list, a ClientError |
|
341 |
raises |
|
337 |
def images_metadata_get(self, image_id, key=None, success=200, **kwargs): |
|
338 |
"""GET base_url/<image_id>/metadata[/key] |
|
342 | 339 |
|
343 | 340 |
:returns: request response |
344 | 341 |
""" |
345 |
path = path4url('images', image_id, command)
|
|
342 |
path = path4url('images', image_id, 'metadata', key or '')
|
|
346 | 343 |
return self.get(path, success=success, **kwargs) |
347 | 344 |
|
348 |
def images_delete(self, image_id='', command='', success=204, **kwargs): |
|
349 |
"""DELETE base_url[/image_id][/command] |
|
350 |
|
|
351 |
:param image_id: string |
|
352 |
|
|
353 |
:param command: image server command |
|
354 |
|
|
355 |
:param success: success code or list or tuple of accepted success |
|
356 |
codes. if server response code is not in this list, a ClientError |
|
357 |
raises |
|
345 |
def images_metadata_post( |
|
346 |
self, image_id, json_data=None, success=201, **kwargs): |
|
347 |
"""POST base_url/images/<image_id>/metadata |
|
358 | 348 |
|
359 | 349 |
:returns: request response |
360 | 350 |
""" |
361 |
path = path4url('images', image_id, command) |
|
362 |
return self.delete(path, success=success, **kwargs) |
|
363 |
|
|
364 |
def images_post( |
|
365 |
self, |
|
366 |
image_id='', |
|
367 |
command='', |
|
368 |
json_data=None, |
|
369 |
success=201, |
|
370 |
**kwargs): |
|
371 |
"""POST base_url/images[/image_id]/[command] request |
|
372 |
|
|
373 |
:param image_id: string |
|
374 |
|
|
375 |
:param command: image server command |
|
351 |
if json_data is not None: |
|
352 |
json_data = json.dumps(json_data) |
|
353 |
self.set_header('Content-Type', 'application/json') |
|
354 |
self.set_header('Content-Length', len(json_data)) |
|
376 | 355 |
|
377 |
:param json_data: (dict) will be send as data |
|
356 |
path = path4url('images', image_id, 'metadata') |
|
357 |
return self.post(path, data=json_data, success=success, **kwargs) |
|
378 | 358 |
|
379 |
:param success: success code or list or tuple of accepted success
|
|
380 |
codes. if server response code is not in this list, a ClientError
|
|
381 |
raises
|
|
359 |
def images_metadata_put(
|
|
360 |
self, image_id, key=None, json_data=None, success=201, **kwargs):
|
|
361 |
"""PUT base_url/images/<image_id>/metadata
|
|
382 | 362 |
|
383 | 363 |
:returns: request response |
384 | 364 |
""" |
385 |
data = json_data |
|
386 | 365 |
if json_data is not None: |
387 |
data = json.dumps(json_data) |
|
366 |
json_data = json.dumps(json_data)
|
|
388 | 367 |
self.set_header('Content-Type', 'application/json') |
389 |
self.set_header('Content-Length', len(data)) |
|
368 |
self.set_header('Content-Length', len(json_data)) |
|
369 |
|
|
370 |
path = path4url('images', image_id, 'metadata') |
|
371 |
return self.put(path, data=json_data, success=success, **kwargs) |
|
390 | 372 |
|
391 |
path = path4url('images', image_id, command)
|
|
392 |
return self.post(path, data=data, success=success, **kwargs)
|
|
373 |
def images_metadata_delete(self, image_id, key, success=204, **kwargs):
|
|
374 |
"""DEL ETE base_url/images/<image_id>/metadata/key
|
|
393 | 375 |
|
394 |
def images_put( |
|
376 |
:returns: request response |
|
377 |
""" |
|
378 |
path = path4url('images', image_id, 'metadata', key) |
|
379 |
return self.put(path, success=success, **kwargs) |
|
380 |
|
|
381 |
def flavors_get( |
|
395 | 382 |
self, |
396 |
image_id='', |
|
397 |
command='', |
|
398 |
json_data=None, |
|
399 |
success=201, |
|
383 |
flavor_id='', |
|
384 |
detail=False, |
|
385 |
changes_since=None, |
|
386 |
minDisk=None, |
|
387 |
minRam=None, |
|
388 |
marker=None, |
|
389 |
limit=None, |
|
390 |
success=200, |
|
400 | 391 |
**kwargs): |
401 |
"""PUT base_url/images[/image_id]/[command] request
|
|
392 |
"""GET base_url[/flavor_id][/command]
|
|
402 | 393 |
|
403 |
:param image_id: string
|
|
394 |
:param flavor_id: ignored if detail
|
|
404 | 395 |
|
405 |
:param command: image server command
|
|
396 |
:param detail: (bool)
|
|
406 | 397 |
|
407 |
:param json_data: (dict) will be send as data
|
|
398 |
--- Parameters ---
|
|
408 | 399 |
|
409 |
:param success: success code or list or tuple of accepted success |
|
410 |
codes. if server response code is not in this list, a ClientError |
|
411 |
raises |
|
400 |
:param changes_since: when the flavor last changed |
|
401 |
|
|
402 |
:param minDisk: minimum disk space in GB filter |
|
403 |
|
|
404 |
:param minRam: minimum RAM filter |
|
405 |
|
|
406 |
:param marker: UUID of the flavor at which to set a marker |
|
407 |
|
|
408 |
:param limit: limit the number of returned values |
|
412 | 409 |
|
413 | 410 |
:returns: request response |
414 | 411 |
""" |
415 |
data = json_data |
|
416 |
if json_data is not None: |
|
417 |
data = json.dumps(json_data) |
|
418 |
self.set_header('Content-Type', 'application/json') |
|
419 |
self.set_header('Content-Length', len(data)) |
|
412 |
if not flavor_id: |
|
413 |
self.set_param('changes-since', changes_since, iff=changes_since) |
|
414 |
self.set_param('minDisk', minDisk, iff=minDisk) |
|
415 |
self.set_param('minRam', minRam, iff=minRam) |
|
416 |
self.set_param('marker', marker, iff=marker) |
|
417 |
self.set_param('limit', limit, iff=limit) |
|
420 | 418 |
|
421 |
path = path4url('images', image_id, command)
|
|
422 |
return self.put(path, data=data, success=success, **kwargs)
|
|
419 |
path = path4url('flavors', 'detail' if detail else (flavor_id or ''))
|
|
420 |
return self.get(path, success=success, **kwargs)
|
|
423 | 421 |
|
424 | 422 |
def floating_ip_pools_get(self, tenant_id, success=200, **kwargs): |
425 | 423 |
path = path4url(tenant_id, 'os-floating-ip-pools') |
Also available in: Unified diff