@@ -250,3 +250,140 @@ def take_action(self, parsed_args):
250250 info = {}
251251 info .update (image )
252252 return zip (* sorted (six .iteritems (info )))
253+
254+
255+ class SetImage (show .ShowOne ):
256+ """Set image properties"""
257+
258+ log = logging .getLogger (__name__ + ".SetImage" )
259+
260+ def get_parser (self , prog_name ):
261+ parser = super (SetImage , self ).get_parser (prog_name )
262+ parser .add_argument (
263+ "image" ,
264+ metavar = "<image>" ,
265+ help = "Image to modify (name or ID)"
266+ )
267+ parser .add_argument (
268+ "--name" ,
269+ metavar = "<name>" ,
270+ help = "New image name"
271+ )
272+ parser .add_argument (
273+ "--architecture" ,
274+ metavar = "<architecture>" ,
275+ help = "Operating system Architecture"
276+ )
277+ parser .add_argument (
278+ "--protected" ,
279+ dest = "protected" ,
280+ action = "store_true" ,
281+ help = "Prevent image from being deleted"
282+ )
283+ parser .add_argument (
284+ "--instance-uuid" ,
285+ metavar = "<instance_uuid>" ,
286+ help = "ID of instance used to create this image"
287+ )
288+ parser .add_argument (
289+ "--min-disk" ,
290+ type = int ,
291+ metavar = "<disk-gb>" ,
292+ help = "Minimum disk size needed to boot image, in gigabytes"
293+ )
294+ visibility_choices = ["public" , "private" ]
295+ parser .add_argument (
296+ "--visibility" ,
297+ metavar = "<visibility>" ,
298+ choices = visibility_choices ,
299+ help = "Scope of image accessibility. Valid values: %s"
300+ % visibility_choices
301+ )
302+ help_msg = ("ID of image in Glance that should be used as the kernel"
303+ " when booting an AMI-style image" )
304+ parser .add_argument (
305+ "--kernel-id" ,
306+ metavar = "<kernel-id>" ,
307+ help = help_msg
308+ )
309+ parser .add_argument (
310+ "--os-version" ,
311+ metavar = "<os-version>" ,
312+ help = "Operating system version as specified by the distributor"
313+ )
314+ disk_choices = ["None" , "ami" , "ari" , "aki" , "vhd" , "vmdk" , "raw" ,
315+ "qcow2" , "vdi" , "iso" ]
316+ help_msg = ("Format of the disk. Valid values: %s" % disk_choices )
317+ parser .add_argument (
318+ "--disk-format" ,
319+ metavar = "<disk-format>" ,
320+ choices = disk_choices ,
321+ help = help_msg
322+ )
323+ parser .add_argument (
324+ "--os-distro" ,
325+ metavar = "<os-distro>" ,
326+ help = "Common name of operating system distribution"
327+ )
328+ parser .add_argument (
329+ "--owner" ,
330+ metavar = "<owner>" ,
331+ help = "New Owner of the image"
332+ )
333+ msg = ("ID of image stored in Glance that should be used as the "
334+ "ramdisk when booting an AMI-style image" )
335+ parser .add_argument (
336+ "--ramdisk-id" ,
337+ metavar = "<ramdisk-id>" ,
338+ help = msg
339+ )
340+ parser .add_argument (
341+ "--min-ram" ,
342+ type = int ,
343+ metavar = "<ram-mb>" ,
344+ help = "Amount of RAM (in MB) required to boot image"
345+ )
346+ container_choices = ["None" , "ami" , "ari" , "aki" , "bare" , "ovf" , "ova" ]
347+ help_msg = ("Format of the container. Valid values: %s"
348+ % container_choices )
349+ parser .add_argument (
350+ "--container-format" ,
351+ metavar = "<container-format>" ,
352+ choices = container_choices ,
353+ help = help_msg
354+ )
355+ return parser
356+
357+ def take_action (self , parsed_args ):
358+ self .log .debug ("take_action(%s)" , parsed_args )
359+ image_client = self .app .client_manager .image
360+
361+ kwargs = {}
362+ copy_attrs = ('architecture' , 'container_format' , 'disk_format' ,
363+ 'file' , 'kernel_id' , 'locations' , 'name' ,
364+ 'min_disk' , 'min_ram' , 'name' , 'os_distro' , 'os_version' ,
365+ 'owner' , 'prefix' , 'progress' , 'ramdisk_id' ,
366+ 'visibility' )
367+ for attr in copy_attrs :
368+ if attr in parsed_args :
369+ val = getattr (parsed_args , attr , None )
370+ if val :
371+ # Only include a value in kwargs for attributes that are
372+ # actually present on the command line
373+ kwargs [attr ] = val
374+ if parsed_args .protected :
375+ kwargs ['protected' ] = True
376+ else :
377+ kwargs ['protected' ] = False
378+
379+ if not kwargs :
380+ self .log .warning ("No arguments specified" )
381+ return {}, {}
382+
383+ image = utils .find_resource (
384+ image_client .images , parsed_args .image )
385+
386+ image = image_client .images .update (image .id , ** kwargs )
387+ info = {}
388+ info .update (image )
389+ return zip (* sorted (six .iteritems (info )))
0 commit comments