Revision d8e50a39 tools/cloud
b/tools/cloud | ||
---|---|---|
9 | 9 |
import json |
10 | 10 |
|
11 | 11 |
DEFAULT_HOST = '127.0.0.1:8000' |
12 |
DEFAULT_API = 'v1.1redux'
|
|
12 |
DEFAULT_API = 'v1.1' |
|
13 | 13 |
|
14 | 14 |
|
15 | 15 |
commands = {} |
... | ... | |
86 | 86 |
if len(reply) == 1: |
87 | 87 |
key = reply.keys()[0] |
88 | 88 |
val = reply[key] |
89 |
print '%s %s' % (key, val.get('message', '')) |
|
89 |
print '%s: %s' % (key, val.get('message', ''))
|
|
90 | 90 |
if self.verbose: |
91 | 91 |
print val.get('details', '') |
92 | 92 |
exit(1) |
... | ... | |
268 | 268 |
print '%3d %s %s' % (id, name, details) |
269 | 269 |
|
270 | 270 |
|
271 |
@command_name('infoflv')
|
|
271 |
@command_name('flvinfo')
|
|
272 | 272 |
class GetFlavorDetails(Command): |
273 | 273 |
description = 'get flavor details' |
274 | 274 |
syntax = '<flavor id>' |
... | ... | |
334 | 334 |
reply = self.http_post(path, body) |
335 | 335 |
print_dict(reply['image']) |
336 | 336 |
|
337 |
|
|
338 | 337 |
@command_name('deleteimg') |
339 | 338 |
class DeleteImage(Command): |
340 | 339 |
description = 'delete image' |
... | ... | |
344 | 343 |
path = '/api/%s/images/%d' % (self.api, int(image_id)) |
345 | 344 |
self.http_delete(path) |
346 | 345 |
|
346 |
@command_name('lsmeta') |
|
347 |
class ListServerMeta(Command): |
|
348 |
description = 'list server meta' |
|
349 |
syntax = '<server id> [key]' |
|
350 |
|
|
351 |
def execute(self, server_id, key=None): |
|
352 |
path = '/api/%s/servers/%d/meta' % (self.api, int(server_id)) |
|
353 |
if key: |
|
354 |
path += '/' + key |
|
355 |
reply = self.http_get(path) |
|
356 |
if key: |
|
357 |
print_dict(reply['meta']) |
|
358 |
else: |
|
359 |
print_dict(reply['metadata']['values']) |
|
360 |
|
|
361 |
@command_name('setmeta') |
|
362 |
class UpdateServerMeta(Command): |
|
363 |
description = 'update server meta' |
|
364 |
syntax = '<server id> <key> <val>' |
|
365 |
|
|
366 |
def execute(self, server_id, key, val): |
|
367 |
path = '/api/%s/servers/%d/meta' % (self.api, int(server_id)) |
|
368 |
metadata = {key: val} |
|
369 |
body = json.dumps({'metadata': metadata}) |
|
370 |
reply = self.http_post(path, body, expected_status=201) |
|
371 |
print_dict(reply['metadata']) |
|
372 |
|
|
373 |
@command_name('addmeta') |
|
374 |
class CreateServerMeta(Command): |
|
375 |
description = 'add server meta' |
|
376 |
syntax = '<server id> <key> <val>' |
|
377 |
|
|
378 |
def execute(self, server_id, key, val): |
|
379 |
path = '/api/%s/servers/%d/meta/%s' % (self.api, int(server_id), key) |
|
380 |
meta = {key: val} |
|
381 |
body = json.dumps({'meta': meta}) |
|
382 |
reply = self.http_put(path, body, expected_status=201) |
|
383 |
print_dict(reply['meta']) |
|
384 |
|
|
385 |
@command_name('delmeta') |
|
386 |
class DeleteServerMeta(Command): |
|
387 |
description = 'delete server meta' |
|
388 |
syntax = '<server id> <key>' |
|
389 |
|
|
390 |
def execute(self, server_id, key): |
|
391 |
path = '/api/%s/servers/%d/meta/%s' % (self.api, int(server_id), key) |
|
392 |
reply = self.http_delete(path) |
|
393 |
|
|
347 | 394 |
|
348 | 395 |
def main(): |
349 | 396 |
try: |
Also available in: Unified diff