Skip to content

Commit 8faabb3

Browse files
NiallBuntingSteve Martinelli
authored andcommitted
Glance image set Resolve Fracturing
Currently `image set` uses the new api, where other parts of osc the old api is used. This deprecates the v2 api in favour of the v1 to maintain the same commands across osc. However the functionality now remains there as people could now be using this functionality. This also adds the --unprotected argument, as in the previous version if --protected was not supplied it would just make the argument --unprotected without the users explicit consent. The patch also fixes the documentation for image set as it was outdated. Change-Id: I990d20332c80165102badef7ac94ddbeb7824950 Closes-Bug: 1498092
1 parent 2616fdb commit 8faabb3

3 files changed

Lines changed: 119 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
@@ -193,7 +193,7 @@ Save an image locally
193193
image set
194194
---------
195195
196-
*Only supported for Image v1*
196+
*Image v1, v2*
197197
198198
Set image properties
199199
@@ -252,6 +252,8 @@ Set image properties
252252
253253
Size of image data (in bytes)
254254
255+
*Image version 1 only.*
256+
255257
.. option:: --protected
256258
257259
Prevent image from being deleted
@@ -272,38 +274,94 @@ Set image properties
272274
273275
Upload image to this store
274276
277+
*Image version 1 only.*
278+
275279
.. option:: --location <image-url>
276280
277281
Download image from an existing URL
278282
283+
*Image version 1 only.*
284+
279285
.. option:: --copy-from <image-url>
280286
281287
Copy image from the data store (similar to --location)
282288
289+
*Image version 1 only.*
290+
283291
.. option:: --file <file>
284292
285293
Upload image from local file
286294
295+
*Image version 1 only.*
296+
287297
.. option:: --volume <volume>
288298
289299
Update image with a volume
290300
301+
*Image version 1 only.*
302+
291303
.. option:: --force
292304
293305
Force image update if volume is in use (only meaningful with --volume)
294306
307+
*Image version 1 only.*
308+
295309
.. option:: --checksum <checksum>
296310
297311
Image hash used for verification
298312
313+
*Image version 1 only.*
314+
299315
.. option:: --stdin
300316
301317
Allow to read image data from standard input
302318
319+
*Image version 1 only.*
320+
303321
.. option:: --property <key=value>
304322
305323
Set a property on this image (repeat for multiple values)
306324
325+
*Image version 1 only.*
326+
327+
.. option:: --architecture <architecture>
328+
329+
Operating system Architecture
330+
331+
.. versionadded:: 2
332+
333+
.. option:: --ramdisk-id <ramdisk-id>
334+
335+
ID of image stored in Glance that should be used as
336+
the ramdisk when booting an AMI-style image
337+
338+
.. versionadded:: 2
339+
340+
.. option:: --os-distro <os-distro>
341+
342+
Common name of operating system distribution
343+
344+
.. versionadded:: 2
345+
346+
.. option:: --os-version <os-version>
347+
348+
Operating system version as specified by the distributor
349+
350+
.. versionadded:: 2
351+
352+
.. option:: --kernel-id <kernel-id>
353+
354+
ID of image in Glance that should be used as the
355+
kernel when booting an AMI-style image
356+
357+
.. versionadded:: 2
358+
359+
.. option:: --instance-uuid <instance_uuid>
360+
361+
ID of instance used to create this image
362+
363+
.. versionadded:: 2
364+
307365
.. describe:: <image>
308366
309367
Image to modify (name or ID)

openstackclient/image/v2/image.py

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from glanceclient.common import utils as gc_utils
2727
from openstackclient.api import utils as api_utils
28+
from openstackclient.common import exceptions
2829
from openstackclient.common import parseractions
2930
from openstackclient.common import utils
3031
from openstackclient.identity import common
@@ -336,9 +337,22 @@ class SetImage(show.ShowOne):
336337
"""Set image properties"""
337338

338339
log = logging.getLogger(__name__ + ".SetImage")
340+
deadopts = ('size', 'store', 'location', 'copy-from', 'checksum')
339341

340342
def get_parser(self, prog_name):
341343
parser = super(SetImage, self).get_parser(prog_name)
344+
# TODO(bunting): There are additional arguments that v1 supported
345+
# --size - does not exist in v2
346+
# --store - does not exist in v2
347+
# --location - maybe location add?
348+
# --copy-from - does not exist in v2
349+
# --file - should be able to upload file
350+
# --volume - needs adding
351+
# --force - needs adding
352+
# --checksum - maybe could be done client side
353+
# --stdin - could be implemented
354+
# --property - needs adding
355+
# --tags - needs adding
342356
parser.add_argument(
343357
"image",
344358
metavar="<image>",
@@ -354,12 +368,28 @@ def get_parser(self, prog_name):
354368
metavar="<architecture>",
355369
help="Operating system Architecture"
356370
)
357-
parser.add_argument(
371+
protected_group = parser.add_mutually_exclusive_group()
372+
protected_group.add_argument(
358373
"--protected",
359-
dest="protected",
360374
action="store_true",
361375
help="Prevent image from being deleted"
362376
)
377+
protected_group.add_argument(
378+
"--unprotected",
379+
action="store_true",
380+
help="Allow image to be deleted (default)"
381+
)
382+
public_group = parser.add_mutually_exclusive_group()
383+
public_group.add_argument(
384+
"--public",
385+
action="store_true",
386+
help="Image is accessible to the public",
387+
)
388+
public_group.add_argument(
389+
"--private",
390+
action="store_true",
391+
help="Image is inaccessible to the public (default)",
392+
)
363393
parser.add_argument(
364394
"--instance-uuid",
365395
metavar="<instance_uuid>",
@@ -372,12 +402,11 @@ def get_parser(self, prog_name):
372402
help="Minimum disk size needed to boot image, in gigabytes"
373403
)
374404
visibility_choices = ["public", "private"]
375-
parser.add_argument(
405+
public_group.add_argument(
376406
"--visibility",
377407
metavar="<visibility>",
378408
choices=visibility_choices,
379-
help="Scope of image accessibility. Valid values: %s"
380-
% visibility_choices
409+
help=argparse.SUPPRESS
381410
)
382411
help_msg = ("ID of image in Glance that should be used as the kernel"
383412
" when booting an AMI-style image")
@@ -432,12 +461,25 @@ def get_parser(self, prog_name):
432461
choices=container_choices,
433462
help=help_msg
434463
)
464+
for deadopt in self.deadopts:
465+
parser.add_argument(
466+
"--%s" % deadopt,
467+
metavar="<%s>" % deadopt,
468+
dest=deadopt.replace('-', '_'),
469+
help=argparse.SUPPRESS
470+
)
435471
return parser
436472

437473
def take_action(self, parsed_args):
438474
self.log.debug("take_action(%s)", parsed_args)
439475
image_client = self.app.client_manager.image
440476

477+
for deadopt in self.deadopts:
478+
if getattr(parsed_args, deadopt.replace('-', '_'), None):
479+
raise exceptions.CommandError(
480+
"ERROR: --%s was given, which is an Image v1 option"
481+
" that is no longer supported in Image v2" % deadopt)
482+
441483
kwargs = {}
442484
copy_attrs = ('architecture', 'container_format', 'disk_format',
443485
'file', 'kernel_id', 'locations', 'name',
@@ -451,10 +493,21 @@ def take_action(self, parsed_args):
451493
# Only include a value in kwargs for attributes that are
452494
# actually present on the command line
453495
kwargs[attr] = val
496+
497+
# Handle exclusive booleans with care
498+
# Avoid including attributes in kwargs if an option is not
499+
# present on the command line. These exclusive booleans are not
500+
# a single value for the pair of options because the default must be
501+
# to do nothing when no options are present as opposed to always
502+
# setting a default.
454503
if parsed_args.protected:
455504
kwargs['protected'] = True
456-
else:
505+
if parsed_args.unprotected:
457506
kwargs['protected'] = False
507+
if parsed_args.public:
508+
kwargs['visibility'] = 'public'
509+
if parsed_args.private:
510+
kwargs['visibility'] = 'private'
458511

459512
if not kwargs:
460513
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
@@ -527,8 +527,7 @@ def test_image_set_options(self):
527527
'name': 'new-name',
528528
'owner': 'new-owner',
529529
'min_disk': 2,
530-
'min_ram': 4,
531-
'protected': False
530+
'min_ram': 4
532531
}
533532
# ImageManager.update(image, **kwargs)
534533
self.images_mock.update.assert_called_with(

0 commit comments

Comments
 (0)