Revision f2ea1314 kamaki/cli/commands/image.py

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

  
154 154
def _validate_image_location(location):
155 155
    """
156
    :param location: (str) pithos://<user-id>/<container>/<img-file-path>
156
    :param location: (str) pithos://<user-id>/<container>/<image-path>
157 157

  
158
    :returns: (<user-id>, <container>, <img-file-path>)
158
    :returns: (<user-id>, <container>, <image-path>)
159 159

  
160 160
    :raises AssertionError: if location is invalid
161 161
    """
......
305 305
        no_metafile_upload=FlagArgument(
306 306
            'Do not store metadata in remote meta file',
307 307
            ('--no-metafile-upload')),
308

  
308
        container=ValueArgument(
309
            'Pithos+ container containing the image file',
310
            ('-C', '--container')),
311
        uuid=ValueArgument('Custom user uuid', '--uuid')
309 312
    )
310 313

  
311 314
    def _get_user_id(self):
......
379 382
                importance=2, details=[
380 383
                    'An image location is needed. Image location format:',
381 384
                    '  pithos://<user-id>/<container>/<path>',
382
                    ' an image file at the above location must exist.'
385
                    ' where an image file at the above location must exist.'
383 386
                    ] + howto_image_file)
384 387
        try:
385 388
            return _validate_image_location(location)
......
391 394
                    '  pithos://<user-id>/<container>/<img-file-path>'
392 395
                    ] + howto_image_file)
393 396

  
397
    def _mine_location(self, container_path):
398
        uuid = self['uuid'] or self._get_user_id()
399
        if self['container']:
400
            return uuid, self['container'], container_path
401
        container, sep, path = container_path.partition(':')
402
        if not (bool(container) and bool(path)):
403
            raiseCLIError(
404
                'Incorrect container-path format', importance=1, details=[
405
                'Use : to seperate container form path',
406
                '  <container>:<image-path>',
407
                'OR',
408
                'Use -C to specifiy a container',
409
                '  -C <container> <image-path>'] + howto_image_file)
410

  
411
        return uuid, container, path
412

  
394 413
    @errors.generic.all
395 414
    @errors.plankton.connection
396
    def _run(self, name, location):
397
        (params, properties, location) = self._load_params_from_file(location)
398
        uuid, container, img_path = self._validate_location(location)
415
    def _run(self, name, uuid, container, img_path):
416
        location = 'pithos://%s/%s/%s' % (uuid, container, img_path)
417
        (params, properties, new_loc) = self._load_params_from_file(location)
418
        if location != new_loc:
419
            uuid, container, img_path = self._validate_location(new_loc)
399 420
        self._load_params_from_args(params, properties)
400 421
        pclient = self._get_pithos_client(container)
401 422

  
......
440 461
                print('Metadata file uploaded as %s:%s (version %s)' % (
441 462
                    container, meta_path, meta_headers['x-object-version']))
442 463

  
443
    def main(self, name, location):
464
    def main(self, name, container___image_path):
444 465
        super(self.__class__, self)._run()
445
        self._run(name, location)
466
        self._run(name, *self._mine_location(container___image_path))
446 467

  
447 468

  
448 469
@command(image_cmds)

Also available in: Unified diff