@@ -693,6 +693,17 @@ def get_parser(self, prog_name):
693693 metavar = "<ramdisk-id>" ,
694694 help = "ID of ramdisk image used to boot this disk image" ,
695695 )
696+ deactivate_group = parser .add_mutually_exclusive_group ()
697+ deactivate_group .add_argument (
698+ "--deactivate" ,
699+ action = "store_true" ,
700+ help = "Deactivate the image" ,
701+ )
702+ deactivate_group .add_argument (
703+ "--activate" ,
704+ action = "store_true" ,
705+ help = "Activate the image" ,
706+ )
696707 for deadopt in self .deadopts :
697708 parser .add_argument (
698709 "--%s" % deadopt ,
@@ -745,18 +756,35 @@ def take_action(self, parsed_args):
745756 if parsed_args .private :
746757 kwargs ['visibility' ] = 'private'
747758
748- if not kwargs :
759+ # Checks if anything that requires getting the image
760+ if not (kwargs or parsed_args .deactivate or parsed_args .activate ):
749761 self .log .warning ("No arguments specified" )
750762 return {}, {}
751763
752764 image = utils .find_resource (
753765 image_client .images , parsed_args .image )
754766
767+ if parsed_args .deactivate :
768+ image_client .images .deactivate (image .id )
769+ activation_status = "deactivated"
770+ if parsed_args .activate :
771+ image_client .images .reactivate (image .id )
772+ activation_status = "activated"
773+
774+ # Check if need to do the actual update
775+ if not kwargs :
776+ return {}, {}
777+
755778 if parsed_args .tags :
756779 # Tags should be extended, but duplicates removed
757780 kwargs ['tags' ] = list (set (image .tags ).union (set (parsed_args .tags )))
758781
759- image = image_client .images .update (image .id , ** kwargs )
782+ try :
783+ image = image_client .images .update (image .id , ** kwargs )
784+ except Exception as e :
785+ if activation_status is not None :
786+ print ("Image %s was %s." % (image .id , activation_status ))
787+ raise e
760788
761789
762790class ShowImage (show .ShowOne ):
0 commit comments