@@ -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" )
0 commit comments