Skip to content

Commit 201b1ce

Browse files
Dean Troyerlin-hua-cheng
authored andcommitted
Clean up Image v2 image set command
Make the Image v2 image set command meet at the intersection of the v1 image set command and the v2 image create command: * Add visibility to the deadopts list and remove the option * Put the options in the same order as v1 image set * Make the help text match * Add --properties * Move the additional options that do not appear in either v1 image set or v2 image create after --property as they are really pre-defined properties * Add tests for v2 image set to match v1 and then some * Put the SetImage class in v2/image.py in alphabetical order Change-Id: I102b914e8ad09a014f6fdd846c5766b6c2eaadb8
1 parent c71c78d commit 201b1ce

3 files changed

Lines changed: 284 additions & 144 deletions

File tree

doc/source/command-objects/image.rst

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ Set image properties
238238
[--checksum <checksum>]
239239
[--stdin]
240240
[--property <key=value> [...] ]
241+
[--architecture <architecture>]
242+
[--instance-id <instance-id>]
243+
[--kernel-id <kernel-id>]
244+
[--os-distro <os-distro>]
245+
[--os-version <os-version>]
246+
[--ramdisk-id <ramdisk-id>]
241247
<image>
242248
243249
.. option:: --name <name>
@@ -258,14 +264,11 @@ Set image properties
258264
259265
.. option:: --container-format <container-format>
260266
261-
Container format of image.
262-
Acceptable formats: ['ami', 'ari', 'aki', 'bare', 'ovf']
267+
Image container format (default: bare)
263268
264269
.. option:: --disk-format <disk-format>
265270
266-
Disk format of image.
267-
Acceptable formats: ['ami', 'ari', 'aki', 'vhd', 'vmdk', 'raw', 'qcow2',
268-
'vdi', 'iso']
271+
Image disk format (default: raw)
269272
270273
.. option:: --size <size>
271274
@@ -339,45 +342,41 @@ Set image properties
339342
340343
.. option:: --property <key=value>
341344
342-
Set a property on this image (repeat for multiple values)
343-
344-
*Image version 1 only.*
345+
Set a property on this image (repeat option to set multiple properties)
345346
346347
.. option:: --architecture <architecture>
347348
348-
Operating system Architecture
349+
Operating system architecture
349350
350351
.. versionadded:: 2
351352
352-
.. option:: --ramdisk-id <ramdisk-id>
353+
.. option:: --instance-id <instance-id>
353354
354-
ID of image stored in Glance that should be used as
355-
the ramdisk when booting an AMI-style image
355+
ID of server instance used to create this image
356356
357357
.. versionadded:: 2
358358
359-
.. option:: --os-distro <os-distro>
359+
.. option:: --kernel-id <kernel-id>
360360
361-
Common name of operating system distribution
361+
ID of kernel image used to boot this disk image
362362
363363
.. versionadded:: 2
364364
365-
.. option:: --os-version <os-version>
365+
.. option:: --os-distro <os-distro>
366366
367-
Operating system version as specified by the distributor
367+
Operating system distribution name
368368
369369
.. versionadded:: 2
370370
371-
.. option:: --kernel-id <kernel-id>
371+
.. option:: --os-version <os-version>
372372
373-
ID of image in Glance that should be used as the
374-
kernel when booting an AMI-style image
373+
Operating system distribution version
375374
376375
.. versionadded:: 2
377376
378-
.. option:: --instance-uuid <instance_uuid>
377+
.. option:: --ramdisk-id <ramdisk-id>
379378
380-
ID of instance used to create this image
379+
ID of ramdisk image used to boot this disk image
381380
382381
.. versionadded:: 2
383382

openstackclient/image/v2/image.py

Lines changed: 90 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def get_parser(self, prog_name):
210210
"--%s" % deadopt,
211211
metavar="<%s>" % deadopt,
212212
dest=deadopt.replace('-', '_'),
213-
help=argparse.SUPPRESS
213+
help=argparse.SUPPRESS,
214214
)
215215
return parser
216216

@@ -522,38 +522,11 @@ def take_action(self, parsed_args):
522522
gc_utils.save_image(data, parsed_args.file)
523523

524524

525-
class ShowImage(show.ShowOne):
526-
"""Display image details"""
527-
528-
log = logging.getLogger(__name__ + ".ShowImage")
529-
530-
def get_parser(self, prog_name):
531-
parser = super(ShowImage, self).get_parser(prog_name)
532-
parser.add_argument(
533-
"image",
534-
metavar="<image>",
535-
help="Image to display (name or ID)",
536-
)
537-
return parser
538-
539-
def take_action(self, parsed_args):
540-
self.log.debug("take_action(%s)", parsed_args)
541-
542-
image_client = self.app.client_manager.image
543-
image = utils.find_resource(
544-
image_client.images,
545-
parsed_args.image,
546-
)
547-
548-
info = _format_image(image)
549-
return zip(*sorted(six.iteritems(info)))
550-
551-
552525
class SetImage(show.ShowOne):
553526
"""Set image properties"""
554527

555528
log = logging.getLogger(__name__ + ".SetImage")
556-
deadopts = ('size', 'store', 'location', 'copy-from', 'checksum')
529+
deadopts = ('visibility',)
557530

558531
def get_parser(self, prog_name):
559532
parser = super(SetImage, self).get_parser(prog_name)
@@ -567,7 +540,6 @@ def get_parser(self, prog_name):
567540
# --force - needs adding
568541
# --checksum - maybe could be done client side
569542
# --stdin - could be implemented
570-
# --property - needs adding
571543
# --tags - needs adding
572544
parser.add_argument(
573545
"image",
@@ -580,20 +552,44 @@ def get_parser(self, prog_name):
580552
help="New image name"
581553
)
582554
parser.add_argument(
583-
"--architecture",
584-
metavar="<architecture>",
585-
help="Operating system Architecture"
555+
"--owner",
556+
metavar="<project>",
557+
help="New image owner project (name or ID)",
558+
)
559+
parser.add_argument(
560+
"--min-disk",
561+
type=int,
562+
metavar="<disk-gb>",
563+
help="Minimum disk size needed to boot image, in gigabytes"
564+
)
565+
parser.add_argument(
566+
"--min-ram",
567+
type=int,
568+
metavar="<ram-mb>",
569+
help="Minimum RAM size needed to boot image, in megabytes",
570+
)
571+
parser.add_argument(
572+
"--container-format",
573+
metavar="<container-format>",
574+
help="Image container format "
575+
"(default: %s)" % DEFAULT_CONTAINER_FORMAT,
576+
)
577+
parser.add_argument(
578+
"--disk-format",
579+
metavar="<disk-format>",
580+
help="Image disk format "
581+
"(default: %s)" % DEFAULT_DISK_FORMAT,
586582
)
587583
protected_group = parser.add_mutually_exclusive_group()
588584
protected_group.add_argument(
589585
"--protected",
590586
action="store_true",
591-
help="Prevent image from being deleted"
587+
help="Prevent image from being deleted",
592588
)
593589
protected_group.add_argument(
594590
"--unprotected",
595591
action="store_true",
596-
help="Allow image to be deleted (default)"
592+
help="Allow image to be deleted (default)",
597593
)
598594
public_group = parser.add_mutually_exclusive_group()
599595
public_group.add_argument(
@@ -607,82 +603,55 @@ def get_parser(self, prog_name):
607603
help="Image is inaccessible to the public (default)",
608604
)
609605
parser.add_argument(
610-
"--instance-uuid",
611-
metavar="<instance_uuid>",
612-
help="ID of instance used to create this image"
606+
"--property",
607+
dest="properties",
608+
metavar="<key=value>",
609+
action=parseractions.KeyValueAction,
610+
help="Set a property on this image "
611+
"(repeat option to set multiple properties)",
613612
)
614613
parser.add_argument(
615-
"--min-disk",
616-
type=int,
617-
metavar="<disk-gb>",
618-
help="Minimum disk size needed to boot image, in gigabytes"
619-
)
620-
visibility_choices = ["public", "private"]
621-
public_group.add_argument(
622-
"--visibility",
623-
metavar="<visibility>",
624-
choices=visibility_choices,
625-
help=argparse.SUPPRESS
614+
"--architecture",
615+
metavar="<architecture>",
616+
help="Operating system architecture",
626617
)
627-
help_msg = ("ID of image in Glance that should be used as the kernel"
628-
" when booting an AMI-style image")
629618
parser.add_argument(
630-
"--kernel-id",
631-
metavar="<kernel-id>",
632-
help=help_msg
619+
"--instance-id",
620+
metavar="<instance-id>",
621+
help="ID of server instance used to create this image",
633622
)
634623
parser.add_argument(
635-
"--os-version",
636-
metavar="<os-version>",
637-
help="Operating system version as specified by the distributor"
624+
"--instance-uuid",
625+
metavar="<instance-id>",
626+
dest="instance_id",
627+
help=argparse.SUPPRESS,
638628
)
639-
disk_choices = ["None", "ami", "ari", "aki", "vhd", "vmdk", "raw",
640-
"qcow2", "vdi", "iso"]
641-
help_msg = ("Format of the disk. Valid values: %s" % disk_choices)
642629
parser.add_argument(
643-
"--disk-format",
644-
metavar="<disk-format>",
645-
choices=disk_choices,
646-
help=help_msg
630+
"--kernel-id",
631+
metavar="<kernel-id>",
632+
help="ID of kernel image used to boot this disk image",
647633
)
648634
parser.add_argument(
649635
"--os-distro",
650636
metavar="<os-distro>",
651-
help="Common name of operating system distribution"
637+
help="Operating system distribution name",
652638
)
653639
parser.add_argument(
654-
"--owner",
655-
metavar="<owner>",
656-
help="New Owner of the image"
640+
"--os-version",
641+
metavar="<os-version>",
642+
help="Operating system distribution version",
657643
)
658-
msg = ("ID of image stored in Glance that should be used as the "
659-
"ramdisk when booting an AMI-style image")
660644
parser.add_argument(
661645
"--ramdisk-id",
662646
metavar="<ramdisk-id>",
663-
help=msg
664-
)
665-
parser.add_argument(
666-
"--min-ram",
667-
type=int,
668-
metavar="<ram-mb>",
669-
help="Amount of RAM (in MB) required to boot image"
670-
)
671-
container_choices = ["None", "ami", "ari", "aki", "bare", "ovf", "ova"]
672-
help_msg = ("Format of the container. Valid values: %s"
673-
% container_choices)
674-
parser.add_argument(
675-
"--container-format",
676-
metavar="<container-format>",
677-
choices=container_choices,
678-
help=help_msg
647+
help="ID of ramdisk image used to boot this disk image",
679648
)
680649
for deadopt in self.deadopts:
681650
parser.add_argument(
682651
"--%s" % deadopt,
683652
metavar="<%s>" % deadopt,
684653
dest=deadopt.replace('-', '_'),
685-
help=argparse.SUPPRESS
654+
help=argparse.SUPPRESS,
686655
)
687656
return parser
688657

@@ -698,10 +667,9 @@ def take_action(self, parsed_args):
698667

699668
kwargs = {}
700669
copy_attrs = ('architecture', 'container_format', 'disk_format',
701-
'file', 'kernel_id', 'locations', 'name',
670+
'file', 'instance_id', 'kernel_id', 'locations',
702671
'min_disk', 'min_ram', 'name', 'os_distro', 'os_version',
703-
'owner', 'prefix', 'progress', 'ramdisk_id',
704-
'visibility')
672+
'owner', 'prefix', 'progress', 'ramdisk_id')
705673
for attr in copy_attrs:
706674
if attr in parsed_args:
707675
val = getattr(parsed_args, attr, None)
@@ -710,6 +678,11 @@ def take_action(self, parsed_args):
710678
# actually present on the command line
711679
kwargs[attr] = val
712680

681+
# Properties should get flattened into the general kwargs
682+
if getattr(parsed_args, 'properties', None):
683+
for k, v in six.iteritems(parsed_args.properties):
684+
kwargs[k] = str(v)
685+
713686
# Handle exclusive booleans with care
714687
# Avoid including attributes in kwargs if an option is not
715688
# present on the command line. These exclusive booleans are not
@@ -736,3 +709,30 @@ def take_action(self, parsed_args):
736709
info = {}
737710
info.update(image)
738711
return zip(*sorted(six.iteritems(info)))
712+
713+
714+
class ShowImage(show.ShowOne):
715+
"""Display image details"""
716+
717+
log = logging.getLogger(__name__ + ".ShowImage")
718+
719+
def get_parser(self, prog_name):
720+
parser = super(ShowImage, self).get_parser(prog_name)
721+
parser.add_argument(
722+
"image",
723+
metavar="<image>",
724+
help="Image to display (name or ID)",
725+
)
726+
return parser
727+
728+
def take_action(self, parsed_args):
729+
self.log.debug("take_action(%s)", parsed_args)
730+
731+
image_client = self.app.client_manager.image
732+
image = utils.find_resource(
733+
image_client.images,
734+
parsed_args.image,
735+
)
736+
737+
info = _format_image(image)
738+
return zip(*sorted(six.iteritems(info)))

0 commit comments

Comments
 (0)