Revision 432fc8c3 tools/cloud

b/tools/cloud
406 406
        path = '/api/%s/servers/%d/meta/%s' % (self.api, int(server_id), key)
407 407
        reply = self.http_delete(path)
408 408

  
409
@command_name('lsimgmeta')
410
class ListImageMeta(Command):
411
    description = 'list image meta'
412
    syntax = '<image id> [key]'
413

  
414
    def execute(self, image_id, key=None):
415
        path = '/api/%s/images/%d/meta' % (self.api, int(image_id))
416
        if key:
417
            path += '/' + key
418
        reply = self.http_get(path)
419
        if key:
420
            print_dict(reply['meta'])
421
        else:
422
            print_dict(reply['metadata']['values'])
423

  
424
@command_name('setimgmeta')
425
class UpdateImageMeta(Command):
426
    description = 'update image meta'
427
    syntax = '<image id> <key> <val>'
428

  
429
    def execute(self, image_id, key, val):
430
        path = '/api/%s/images/%d/meta' % (self.api, int(image_id))
431
        metadata = {key: val}
432
        body = json.dumps({'metadata': metadata})
433
        reply = self.http_post(path, body, expected_status=201)
434
        print_dict(reply['metadata'])
435

  
436
@command_name('addimgmeta')
437
class CreateImageMeta(Command):
438
    description = 'add image meta'
439
    syntax = '<image id> <key> <val>'
440

  
441
    def execute(self, image_id, key, val):
442
        path = '/api/%s/images/%d/meta/%s' % (self.api, int(image_id), key)
443
        meta = {key: val}
444
        body = json.dumps({'meta': meta})
445
        reply = self.http_put(path, body, expected_status=201)
446
        print_dict(reply['meta'])
447

  
448
@command_name('delimgmeta')
449
class DeleteImageMeta(Command):
450
    description = 'delete image meta'
451
    syntax = '<image id> <key>'
452

  
453
    def execute(self, image_id, key):
454
        path = '/api/%s/images/%d/meta/%s' % (self.api, int(image_id), key)
455
        reply = self.http_delete(path)
456

  
409 457

  
410 458
def main():
411 459
    try:

Also available in: Unified diff