Revision 00b1248e kamaki/cli/commands/image.py

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

  
285 285

  
286 286
@command(image_cmds)
287
class image_meta(_init_image):
288
    """Manage image metadata and custom properties"""
289

  
290

  
291
@command(image_cmds)
292 287
class image_info(_init_image, _optional_json):
293
    """Get image metadata
294
    Image metadata include:
295
    - image file information (location, size, etc.)
296
    - image information (id, name, etc.)
297
    - image os properties (os, fs, etc.)
298
    """
288
    """Get image metadata"""
299 289

  
300 290
    @errors.generic.all
301 291
    @errors.plankton.connection
......
312 302

  
313 303

  
314 304
@command(image_cmds)
315
class image_meta_set(_init_image, _optional_output_cmd):
305
class image_modify(_init_image, _optional_json):
316 306
    """Add / update metadata and properties for an image
317 307
    The original image preserves the values that are not affected
318 308
    """
319 309

  
320 310
    arguments = dict(
321
        name=ValueArgument('Set a new name', ('--name')),
322
        disk_format=ValueArgument('Set a new disk format', ('--disk-format')),
311
        image_name=ValueArgument('Change name', '--name'),
312
        disk_format=ValueArgument('Change disk format', '--disk-format'),
323 313
        container_format=ValueArgument(
324
            'Set a new container format', ('--container-format')),
325
        status=ValueArgument('Set a new status', ('--status')),
326
        publish=FlagArgument('publish the image', ('--publish')),
327
        unpublish=FlagArgument('unpublish the image', ('--unpublish')),
328
        properties=KeyValueArgument(
314
            'Change container format', '--container-format'),
315
        status=ValueArgument('Change status', '--status'),
316
        publish=FlagArgument('Publish the image', '--publish'),
317
        unpublish=FlagArgument('Unpublish the image', '--unpublish'),
318
        property_to_set=KeyValueArgument(
329 319
            'set property in key=value form (can be repeated)',
330
            ('-p', '--property'))
320
            ('-p', '--property-set')),
321
        property_to_del=RepeatableArgument(
322
            'Delete property by key (can be repeated)', '--property-del')
331 323
    )
332

  
333
    def _check_empty(self):
334
        for term in (
335
                'name', 'disk_format', 'container_format', 'status', 'publish',
336
                'unpublish', 'properties'):
337
            if self[term]:
338
                if self['publish'] and self['unpublish']:
339
                    raiseCLIError(
340
                        '--publish and --unpublish are mutually exclusive')
341
                return
342
        raiseCLIError(
343
            'Nothing to update, please use arguments (-h for a list)')
324
    required = [
325
        'image_name', 'disk_format', 'container_format', 'status', 'publish',
326
        'unpublish', 'property_to_set']
344 327

  
345 328
    @errors.generic.all
346 329
    @errors.plankton.connection
347 330
    @errors.plankton.id
348 331
    def _run(self, image_id):
349
        self._check_empty()
350 332
        meta = self.client.get_meta(image_id)
351
        for k, v in self['properties'].items():
333
        for k, v in self['property_to_set'].items():
352 334
            meta['properties'][k.upper()] = v
335
        for k in self['property_to_del']:
336
            meta['properties'][k.upper()] = None
353 337
        self._optional_output(self.client.update_image(
354 338
            image_id,
355
            name=self['name'],
339
            name=self['image_name'],
356 340
            disk_format=self['disk_format'],
357 341
            container_format=self['container_format'],
358 342
            status=self['status'],
......
365 349

  
366 350

  
367 351
@command(image_cmds)
368
class image_meta_delete(_init_image, _optional_output_cmd):
369
    """Remove/empty image metadata and/or custom properties"""
370

  
371
    arguments = dict(
372
        disk_format=FlagArgument('Empty disk format', ('--disk-format')),
373
        container_format=FlagArgument(
374
            'Empty container format', ('--container-format')),
375
        status=FlagArgument('Empty status', ('--status')),
376
        properties=RepeatableArgument(
377
            'Property keys to remove', ('-p', '--property'))
378
    )
379

  
380
    def _check_empty(self):
381
        for t in ('disk_format', 'container_format', 'status', 'properties'):
382
            if self[t]:
383
                return
384
        raiseCLIError(
385
            'Nothing to update, please use arguments (-h for a list)')
386

  
387
    @errors.generic.all
388
    @errors.plankton.connection
389
    @errors.plankton.id
390
    def _run(self, image_id):
391
        self._check_empty()
392
        meta = self.client.get_meta(image_id)
393
        for k in self['properties']:
394
            meta['properties'].pop(k.upper(), None)
395
        self._optional_output(self.client.update_image(
396
            image_id,
397
            disk_format='' if self['disk_format'] else None,
398
            container_format='' if self['container_format'] else None,
399
            status='' if self['status'] else None,
400
            **meta['properties']))
401

  
402
    def main(self, image_id):
403
        super(self.__class__, self)._run()
404
        self._run(image_id=image_id)
405

  
406

  
407
@command(image_cmds)
408 352
class image_register(_init_image, _optional_json):
409 353
    """(Re)Register an image file to an Image service
410 354
    The image file must be stored at a pithos repository

Also available in: Unified diff