Skip to content

Commit c71c78d

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Glance image set Resolve Fracturing"
2 parents b8faa8a + 8faabb3 commit c71c78d

3 files changed

Lines changed: 118 additions & 9 deletions

File tree

doc/source/command-objects/image.rst

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Save an image locally
212212
image set
213213
---------
214214
215-
*Only supported for Image v1*
215+
*Image v1, v2*
216216
217217
Set image properties
218218
@@ -271,6 +271,8 @@ Set image properties
271271
272272
Size of image data (in bytes)
273273
274+
*Image version 1 only.*
275+
274276
.. option:: --protected
275277
276278
Prevent image from being deleted
@@ -291,38 +293,94 @@ Set image properties
291293
292294
Upload image to this store
293295
296+
*Image version 1 only.*
297+
294298
.. option:: --location <image-url>
295299
296300
Download image from an existing URL
297301
302+
*Image version 1 only.*
303+
298304
.. option:: --copy-from <image-url>
299305
300306
Copy image from the data store (similar to --location)
301307
308+
*Image version 1 only.*
309+
302310
.. option:: --file <file>
303311
304312
Upload image from local file
305313
314+
*Image version 1 only.*
315+
306316
.. option:: --volume <volume>
307317
308318
Update image with a volume
309319
320+
*Image version 1 only.*
321+
310322
.. option:: --force
311323
312324
Force image update if volume is in use (only meaningful with --volume)
313325
326+
*Image version 1 only.*
327+
314328
.. option:: --checksum <checksum>
315329
316330
Image hash used for verification
317331
332+
*Image version 1 only.*
333+
318334
.. option:: --stdin
319335
320336
Allow to read image data from standard input
321337
338+
*Image version 1 only.*
339+
322340
.. option:: --property <key=value>
323341
324342
Set a property on this image (repeat for multiple values)
325343
344+
*Image version 1 only.*
345+
346+
.. option:: --architecture <architecture>
347+
348+
Operating system Architecture
349+
350+
.. versionadded:: 2
351+
352+
.. option:: --ramdisk-id <ramdisk-id>
353+
354+
ID of image stored in Glance that should be used as
355+
the ramdisk when booting an AMI-style image
356+
357+
.. versionadded:: 2
358+
359+
.. option:: --os-distro <os-distro>
360+
361+
Common name of operating system distribution
362+
363+
.. versionadded:: 2
364+
365+
.. option:: --os-version <os-version>
366+
367+
Operating system version as specified by the distributor
368+
369+
.. versionadded:: 2
370+
371+
.. option:: --kernel-id <kernel-id>
372+
373+
ID of image in Glance that should be used as the
374+
kernel when booting an AMI-style image
375+
376+
.. versionadded:: 2
377+
378+
.. option:: --instance-uuid <instance_uuid>
379+
380+
ID of instance used to create this image
381+
382+
.. versionadded:: 2
383+
326384
.. describe:: <image>
327385
328386
Image to modify (name or ID)

openstackclient/image/v2/image.py

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,22 @@ class SetImage(show.ShowOne):
553553
"""Set image properties"""
554554

555555
log = logging.getLogger(__name__ + ".SetImage")
556+
deadopts = ('size', 'store', 'location', 'copy-from', 'checksum')
556557

557558
def get_parser(self, prog_name):
558559
parser = super(SetImage, self).get_parser(prog_name)
560+
# TODO(bunting): There are additional arguments that v1 supported
561+
# --size - does not exist in v2
562+
# --store - does not exist in v2
563+
# --location - maybe location add?
564+
# --copy-from - does not exist in v2
565+
# --file - should be able to upload file
566+
# --volume - needs adding
567+
# --force - needs adding
568+
# --checksum - maybe could be done client side
569+
# --stdin - could be implemented
570+
# --property - needs adding
571+
# --tags - needs adding
559572
parser.add_argument(
560573
"image",
561574
metavar="<image>",
@@ -571,12 +584,28 @@ def get_parser(self, prog_name):
571584
metavar="<architecture>",
572585
help="Operating system Architecture"
573586
)
574-
parser.add_argument(
587+
protected_group = parser.add_mutually_exclusive_group()
588+
protected_group.add_argument(
575589
"--protected",
576-
dest="protected",
577590
action="store_true",
578591
help="Prevent image from being deleted"
579592
)
593+
protected_group.add_argument(
594+
"--unprotected",
595+
action="store_true",
596+
help="Allow image to be deleted (default)"
597+
)
598+
public_group = parser.add_mutually_exclusive_group()
599+
public_group.add_argument(
600+
"--public",
601+
action="store_true",
602+
help="Image is accessible to the public",
603+
)
604+
public_group.add_argument(
605+
"--private",
606+
action="store_true",
607+
help="Image is inaccessible to the public (default)",
608+
)
580609
parser.add_argument(
581610
"--instance-uuid",
582611
metavar="<instance_uuid>",
@@ -589,12 +618,11 @@ def get_parser(self, prog_name):
589618
help="Minimum disk size needed to boot image, in gigabytes"
590619
)
591620
visibility_choices = ["public", "private"]
592-
parser.add_argument(
621+
public_group.add_argument(
593622
"--visibility",
594623
metavar="<visibility>",
595624
choices=visibility_choices,
596-
help="Scope of image accessibility. Valid values: %s"
597-
% visibility_choices
625+
help=argparse.SUPPRESS
598626
)
599627
help_msg = ("ID of image in Glance that should be used as the kernel"
600628
" when booting an AMI-style image")
@@ -649,12 +677,25 @@ def get_parser(self, prog_name):
649677
choices=container_choices,
650678
help=help_msg
651679
)
680+
for deadopt in self.deadopts:
681+
parser.add_argument(
682+
"--%s" % deadopt,
683+
metavar="<%s>" % deadopt,
684+
dest=deadopt.replace('-', '_'),
685+
help=argparse.SUPPRESS
686+
)
652687
return parser
653688

654689
def take_action(self, parsed_args):
655690
self.log.debug("take_action(%s)", parsed_args)
656691
image_client = self.app.client_manager.image
657692

693+
for deadopt in self.deadopts:
694+
if getattr(parsed_args, deadopt.replace('-', '_'), None):
695+
raise exceptions.CommandError(
696+
"ERROR: --%s was given, which is an Image v1 option"
697+
" that is no longer supported in Image v2" % deadopt)
698+
658699
kwargs = {}
659700
copy_attrs = ('architecture', 'container_format', 'disk_format',
660701
'file', 'kernel_id', 'locations', 'name',
@@ -668,10 +709,21 @@ def take_action(self, parsed_args):
668709
# Only include a value in kwargs for attributes that are
669710
# actually present on the command line
670711
kwargs[attr] = val
712+
713+
# Handle exclusive booleans with care
714+
# Avoid including attributes in kwargs if an option is not
715+
# present on the command line. These exclusive booleans are not
716+
# a single value for the pair of options because the default must be
717+
# to do nothing when no options are present as opposed to always
718+
# setting a default.
671719
if parsed_args.protected:
672720
kwargs['protected'] = True
673-
else:
721+
if parsed_args.unprotected:
674722
kwargs['protected'] = False
723+
if parsed_args.public:
724+
kwargs['visibility'] = 'public'
725+
if parsed_args.private:
726+
kwargs['visibility'] = 'private'
675727

676728
if not kwargs:
677729
self.log.warning("No arguments specified")

openstackclient/tests/image/v2/test_image.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,7 @@ def test_image_set_options(self):
713713
'name': 'new-name',
714714
'owner': 'new-owner',
715715
'min_disk': 2,
716-
'min_ram': 4,
717-
'protected': False
716+
'min_ram': 4
718717
}
719718
# ImageManager.update(image, **kwargs)
720719
self.images_mock.update.assert_called_with(

0 commit comments

Comments
 (0)