Revision 38db356b kamaki/cli/commands/image.py

b/kamaki/cli/commands/image.py
402 402

  
403 403
@command(image_cmds)
404 404
class image_register(_init_image, _optional_json):
405
    """(Re)Register an image"""
405
    """(Re)Register an image file to an Image service
406
    The image file must be stored at a pithos repository
407
    Some metadata can be set by user (e.g. disk-format) while others are set
408
    only automatically (e.g. image id). There are also some custom user
409
    metadata, called properties.
410
    A register command creates a remote meta file at
411
       <container>:<image path>.meta
412
    Users may download and edit this file and use it to re-register one or more
413
    images.
414
    In case of a meta file, runtime arguments for metadata or properties
415
    override meta file settings.
416
    """
406 417

  
407 418
    container_info_cache = {}
408 419

  
409 420
    arguments = dict(
410
        checksum=ValueArgument('set image checksum', '--checksum'),
421
        checksum=ValueArgument('Set image checksum', '--checksum'),
411 422
        container_format=ValueArgument(
412
            'set container format',
423
            'Set container format',
413 424
            '--container-format'),
414
        disk_format=ValueArgument('set disk format', '--disk-format'),
415
        #owner=ValueArgument('set image owner (admin only)', '--owner'),
425
        disk_format=ValueArgument('Set disk format', '--disk-format'),
426
        owner_name=ValueArgument('Set user uuid by user name', '--owner-name'),
416 427
        properties=KeyValueArgument(
417
            'add property in key=value form (can be repeated)',
428
            'Add property (user-specified metadata) in key=value form'
429
            '(can be repeated)',
418 430
            ('-p', '--property')),
419
        is_public=FlagArgument('mark image as public', '--public'),
420
        size=IntArgument('set image size', '--size'),
431
        is_public=FlagArgument('Mark image as public', '--public'),
432
        size=IntArgument('Set image size in bytes', '--size'),
421 433
        metafile=ValueArgument(
422 434
            'Load metadata from a json-formated file <img-file>.meta :'
423 435
            '{"key1": "val1", "key2": "val2", ..., "properties: {...}"}',
424 436
            ('--metafile')),
425 437
        metafile_force=FlagArgument(
426
            'Store remote metadata object, even if it already exists',
427
            ('-f', '--force')),
438
            'Overide remote metadata file', ('-f', '--force')),
428 439
        no_metafile_upload=FlagArgument(
429 440
            'Do not store metadata in remote meta file',
430 441
            ('--no-metafile-upload')),
......
511 522
                'No image file location provided',
512 523
                importance=2, details=[
513 524
                    'An image location is needed. Image location format:',
514
                    '  pithos://<user-id>/<container>/<path>',
525
                    '  <container>:<path>',
515 526
                    ' where an image file at the above location must exist.'
516 527
                    ] + howto_image_file)
517 528
        try:
......
521 532
                ae, 'Invalid image location format',
522 533
                importance=1, details=[
523 534
                    'Valid image location format:',
524
                    '  pithos://<user-id>/<container>/<img-file-path>'
535
                    '  <container>:<img-file-path>'
525 536
                    ] + howto_image_file)
526 537

  
538
    @staticmethod
539
    def _old_location_format(location):
540
        prefix = 'pithos://'
541
        try:
542
            if location.startswith(prefix):
543
                uuid, sep, rest = location[len(prefix):].partition('/')
544
                container, sep, path = rest.partition('/')
545
                return (uuid, container, path)
546
        except Exception as e:
547
            raiseCLIError(e, 'Invalid location format', details=[
548
                'Correct location format:', '  <container>:<image path>'])
549
        return ()
550

  
527 551
    def _mine_location(self, container_path):
528
        uuid = self['uuid'] or self._get_user_id()
552
        old_response = self._old_location_format(container_path)
553
        if old_response:
554
            return old_response
555
        uuid = self['uuid'] or (self._username2uuid(self['owner_name']) if (
556
                    self['owner_name']) else self._get_user_id())
557
        if not uuid:
558
            if self['owner_name']:
559
                raiseCLIError('No user with username %s' % self['owner_name'])
560
            raiseCLIError('Failed to get user uuid', details=[
561
                'For details on current user:',
562
                '  /user whoami',
563
                'To authenticate a new user through a user token:',
564
                '  /user authenticate <token>'])
529 565
        if self['container']:
530 566
            return uuid, self['container'], container_path
531 567
        container, sep, path = container_path.partition(':')

Also available in: Unified diff