Revision d77e33d4

b/kamaki/cli/commands/image.py
32 32
# or implied, of GRNET S.A.command
33 33

  
34 34
from json import load, dumps
35
from os.path import abspath
35
from os import path
36 36
from logging import getLogger
37 37

  
38 38
from kamaki.cli import command
......
43 43
from kamaki.clients.astakos import AstakosClient
44 44
from kamaki.clients import ClientError
45 45
from kamaki.cli.argument import FlagArgument, ValueArgument, KeyValueArgument
46
from kamaki.cli.argument import IntArgument
46
from kamaki.cli.argument import IntArgument, ProgressBarArgument
47 47
from kamaki.cli.commands.cyclades import _init_cyclades
48 48
from kamaki.cli.errors import raiseCLIError, CLIBaseUrlError
49 49
from kamaki.cli.commands import _command_init, errors, addLogSettings
......
142 142

  
143 143
    :raises AssertionError: Valid json but invalid image properties dict
144 144
    """
145
    with open(abspath(filepath)) as f:
145
    with open(path.abspath(filepath)) as f:
146 146
        meta_dict = load(f)
147 147
        try:
148 148
            return _validate_image_meta(meta_dict)
......
283 283
class image_register(_init_image, _optional_json):
284 284
    """(Re)Register an image"""
285 285

  
286
    container_info_cache = {}
287

  
286 288
    arguments = dict(
287 289
        checksum=ValueArgument('set image checksum', '--checksum'),
288 290
        container_format=ValueArgument(
......
308 310
        container=ValueArgument(
309 311
            'Pithos+ container containing the image file',
310 312
            ('-C', '--container')),
311
        uuid=ValueArgument('Custom user uuid', '--uuid')
313
        uuid=ValueArgument('Custom user uuid', '--uuid'),
314
        local_image_path=ValueArgument(
315
            'Local image file path to upload and register '
316
            '(still need target file in the form container:remote-path )',
317
            '--upload-image-file'),
318
        progress_bar=ProgressBarArgument(
319
            'Do not use progress bar', '--no-progress-bar', default=False)
312 320
    )
313 321

  
314 322
    def _get_user_id(self):
......
339 347

  
340 348
    def _store_remote_metafile(self, pclient, remote_path, metadata):
341 349
        return pclient.upload_from_string(
342
            remote_path, _validate_image_meta(metadata, return_str=True))
350
            remote_path, _validate_image_meta(metadata, return_str=True),
351
            container_info_cache=self.container_info_cache)
343 352

  
344 353
    def _load_params_from_file(self, location):
345 354
        params, properties = dict(), dict()
......
413 422
    @errors.generic.all
414 423
    @errors.plankton.connection
415 424
    def _run(self, name, uuid, container, img_path):
425
        if self['local_image_path']:
426
            with open(self['local_image_path']) as f:
427
                pithos = self._get_pithos_client(container)
428
                (pbar, upload_cb) = self._safe_progress_bar('Uploading')
429
                if pbar:
430
                    hash_bar = pbar.clone()
431
                    hash_cb = hash_bar.get_generator('Calculating hashes')
432
                pithos.upload_object(
433
                    img_path, f,
434
                    hash_cb=hash_cb, upload_cb=upload_cb,
435
                    container_info_cache=self.container_info_cache)
436
                pbar.finish()
437

  
416 438
        location = 'pithos://%s/%s/%s' % (uuid, container, img_path)
417 439
        (params, properties, new_loc) = self._load_params_from_file(location)
418 440
        if location != new_loc:
......
449 471
        if pclient:
450 472
            try:
451 473
                meta_headers = pclient.upload_from_string(
452
                    meta_path, dumps(r, indent=2))
474
                    meta_path, dumps(r, indent=2),
475
                    container_info_cache=self.container_info_cache)
453 476
            except TypeError:
454 477
                print('Failed to dump metafile %s:%s' % (container, meta_path))
455 478
                return

Also available in: Unified diff