3939CONTAINER_CHOICES = ["ami" , "ari" , "aki" , "bare" , "docker" , "ova" , "ovf" ]
4040DEFAULT_CONTAINER_FORMAT = 'bare'
4141DEFAULT_DISK_FORMAT = 'raw'
42- DISK_CHOICES = ["ami" , "ari" , "aki" , "vhd" , "vmdk" , "raw" , "qcow2" , "vhdx" ,
43- "vdi" , "iso" , "ploop" ]
42+ DISK_CHOICES = [
43+ "ami" ,
44+ "ari" ,
45+ "aki" ,
46+ "vhd" ,
47+ "vmdk" ,
48+ "raw" ,
49+ "qcow2" ,
50+ "vhdx" ,
51+ "vdi" ,
52+ "iso" ,
53+ "ploop" ,
54+ ]
4455
4556
4657LOG = logging .getLogger (__name__ )
4758
4859
4960def _get_columns (item ):
50- column_map = {
51- 'is_protected' : 'protected' ,
52- 'owner_id' : 'owner'
53- }
61+ column_map = {'is_protected' : 'protected' , 'owner_id' : 'owner' }
5462 hidden_columns = [
55- 'location' , 'checksum' , 'copy_from' , 'created_at' , 'status' ,
63+ 'location' ,
64+ 'checksum' ,
65+ 'copy_from' ,
66+ 'created_at' ,
67+ 'status' ,
5668 'updated_at' ,
5769 ]
5870 return utils .get_osc_show_columns_for_sdk_resource (
59- item .to_dict (), column_map , hidden_columns ,
71+ item .to_dict (),
72+ column_map ,
73+ hidden_columns ,
6074 )
6175
6276
63- _formatters = {
64- }
77+ _formatters = {}
6578
6679
6780class HumanReadableSizeColumn (cliff_columns .FormattableColumn ):
@@ -117,25 +130,36 @@ def get_parser(self, prog_name):
117130 default = DEFAULT_CONTAINER_FORMAT ,
118131 metavar = "<container-format>" ,
119132 choices = CONTAINER_CHOICES ,
120- help = (_ ("Image container format. "
133+ help = (
134+ _ (
135+ "Image container format. "
121136 "The supported options are: %(option_list)s. "
122- "The default format is: %(default_opt)s" ) %
123- {'option_list' : ', ' .join (CONTAINER_CHOICES ),
124- 'default_opt' : DEFAULT_CONTAINER_FORMAT })
137+ "The default format is: %(default_opt)s"
138+ )
139+ % {
140+ 'option_list' : ', ' .join (CONTAINER_CHOICES ),
141+ 'default_opt' : DEFAULT_CONTAINER_FORMAT ,
142+ }
143+ ),
125144 )
126145 parser .add_argument (
127146 "--disk-format" ,
128147 default = DEFAULT_DISK_FORMAT ,
129148 metavar = "<disk-format>" ,
130149 choices = DISK_CHOICES ,
131- help = _ ("Image disk format. The supported options are: %s. "
132- "The default format is: raw" ) % ', ' .join (DISK_CHOICES )
150+ help = _ (
151+ "Image disk format. The supported options are: %s. "
152+ "The default format is: raw"
153+ )
154+ % ', ' .join (DISK_CHOICES ),
133155 )
134156 parser .add_argument (
135157 "--size" ,
136158 metavar = "<size>" ,
137- help = _ ("Image size, in bytes (only used with --location and"
138- " --copy-from)" ),
159+ help = _ (
160+ "Image size, in bytes (only used with --location and"
161+ " --copy-from)"
162+ ),
139163 )
140164 parser .add_argument (
141165 "--min-disk" ,
@@ -175,8 +199,10 @@ def get_parser(self, prog_name):
175199 dest = 'force' ,
176200 action = 'store_true' ,
177201 default = False ,
178- help = _ ("Force image creation if volume is in use "
179- "(only meaningful with --volume)" ),
202+ help = _ (
203+ "Force image creation if volume is in use "
204+ "(only meaningful with --volume)"
205+ ),
180206 )
181207 parser .add_argument (
182208 "--checksum" ,
@@ -210,8 +236,10 @@ def get_parser(self, prog_name):
210236 dest = "properties" ,
211237 metavar = "<key=value>" ,
212238 action = parseractions .KeyValueAction ,
213- help = _ ("Set a property on this image "
214- "(repeat option to set multiple properties)" ),
239+ help = _ (
240+ "Set a property on this image "
241+ "(repeat option to set multiple properties)"
242+ ),
215243 )
216244 parser .add_argument (
217245 "--project" ,
@@ -226,10 +254,23 @@ def take_action(self, parsed_args):
226254 # Build an attribute dict from the parsed args, only include
227255 # attributes that were actually set on the command line
228256 kwargs = {}
229- copy_attrs = ('name' , 'id' , 'store' , 'container_format' ,
230- 'disk_format' , 'owner' , 'size' , 'min_disk' , 'min_ram' ,
231- 'location' , 'copy_from' , 'volume' , 'force' ,
232- 'checksum' , 'properties' )
257+ copy_attrs = (
258+ 'name' ,
259+ 'id' ,
260+ 'store' ,
261+ 'container_format' ,
262+ 'disk_format' ,
263+ 'owner' ,
264+ 'size' ,
265+ 'min_disk' ,
266+ 'min_ram' ,
267+ 'location' ,
268+ 'copy_from' ,
269+ 'volume' ,
270+ 'force' ,
271+ 'checksum' ,
272+ 'properties' ,
273+ )
233274 for attr in copy_attrs :
234275 if attr in parsed_args :
235276 val = getattr (parsed_args , attr , None )
@@ -295,20 +336,25 @@ def take_action(self, parsed_args):
295336 image = image_client .create_image (** kwargs )
296337 finally :
297338 # Clean up open files - make sure data isn't a string
298- if ('data' in kwargs and hasattr (kwargs ['data' ], 'close' ) and
299- kwargs ['data' ] != sys .stdin ):
339+ if (
340+ 'data' in kwargs
341+ and hasattr (kwargs ['data' ], 'close' )
342+ and kwargs ['data' ] != sys .stdin
343+ ):
300344 kwargs ['data' ].close ()
301345
302346 if image :
303347 display_columns , columns = _get_columns (image )
304348 _formatters ['properties' ] = format_columns .DictColumn
305- data = utils .get_item_properties (image , columns ,
306- formatters = _formatters )
349+ data = utils .get_item_properties (
350+ image , columns , formatters = _formatters
351+ )
307352 return (display_columns , data )
308353 elif info :
309354 info .update (image ._info )
310355 info ['properties' ] = format_columns .DictColumn (
311- info .get ('properties' , {}))
356+ info .get ('properties' , {})
357+ )
312358 return zip (* sorted (info .items ()))
313359
314360
@@ -384,9 +430,11 @@ def get_parser(self, prog_name):
384430 '--sort' ,
385431 metavar = "<key>[:<direction>]" ,
386432 default = 'name:asc' ,
387- help = _ ("Sort output by selected keys and directions(asc or desc) "
388- "(default: name:asc), multiple keys and directions can be "
389- "specified separated by comma" ),
433+ help = _ (
434+ "Sort output by selected keys and directions(asc or desc) "
435+ "(default: name:asc), multiple keys and directions can be "
436+ "specified separated by comma"
437+ ),
390438 )
391439 return parser
392440
@@ -447,14 +495,17 @@ def take_action(self, parsed_args):
447495
448496 return (
449497 column_headers ,
450- (utils .get_item_properties (
451- s ,
452- columns ,
453- formatters = {
454- 'is_public' : VisibilityColumn ,
455- 'properties' : format_columns .DictColumn ,
456- },
457- ) for s in data )
498+ (
499+ utils .get_item_properties (
500+ s ,
501+ columns ,
502+ formatters = {
503+ 'is_public' : VisibilityColumn ,
504+ 'properties' : format_columns .DictColumn ,
505+ },
506+ )
507+ for s in data
508+ ),
458509 )
459510
460511
@@ -517,21 +568,21 @@ def get_parser(self, prog_name):
517568 "--container-format" ,
518569 metavar = "<container-format>" ,
519570 choices = CONTAINER_CHOICES ,
520- help = _ ("Image container format. The supported options are: %s" ) %
521- ', ' .join (CONTAINER_CHOICES )
571+ help = _ ("Image container format. The supported options are: %s" )
572+ % ', ' .join (CONTAINER_CHOICES ),
522573 )
523574 parser .add_argument (
524575 "--disk-format" ,
525576 metavar = "<disk-format>" ,
526577 choices = DISK_CHOICES ,
527- help = _ ("Image disk format. The supported options are: %s." ) %
528- ', ' .join (DISK_CHOICES )
578+ help = _ ("Image disk format. The supported options are: %s." )
579+ % ', ' .join (DISK_CHOICES ),
529580 )
530581 parser .add_argument (
531582 "--size" ,
532583 metavar = "<size>" ,
533584 type = int ,
534- help = _ ("Size of image data (in bytes)" )
585+ help = _ ("Size of image data (in bytes)" ),
535586 )
536587 protected_group = parser .add_mutually_exclusive_group ()
537588 protected_group .add_argument (
@@ -560,8 +611,10 @@ def get_parser(self, prog_name):
560611 dest = "properties" ,
561612 metavar = "<key=value>" ,
562613 action = parseractions .KeyValueAction ,
563- help = _ ("Set a property on this image "
564- "(repeat option to set multiple properties)" ),
614+ help = _ (
615+ "Set a property on this image "
616+ "(repeat option to set multiple properties)"
617+ ),
565618 )
566619 parser .add_argument (
567620 "--store" ,
@@ -593,8 +646,10 @@ def get_parser(self, prog_name):
593646 dest = 'force' ,
594647 action = 'store_true' ,
595648 default = False ,
596- help = _ ("Force image change if volume is in use "
597- "(only meaningful with --volume)" ),
649+ help = _ (
650+ "Force image change if volume is in use "
651+ "(only meaningful with --volume)"
652+ ),
598653 )
599654 parser .add_argument (
600655 "--stdin" ,
@@ -619,9 +674,21 @@ def take_action(self, parsed_args):
619674 image_client = self .app .client_manager .image
620675
621676 kwargs = {}
622- copy_attrs = ('name' , 'owner' , 'min_disk' , 'min_ram' , 'properties' ,
623- 'container_format' , 'disk_format' , 'size' , 'store' ,
624- 'location' , 'copy_from' , 'volume' , 'checksum' )
677+ copy_attrs = (
678+ 'name' ,
679+ 'owner' ,
680+ 'min_disk' ,
681+ 'min_ram' ,
682+ 'properties' ,
683+ 'container_format' ,
684+ 'disk_format' ,
685+ 'size' ,
686+ 'store' ,
687+ 'location' ,
688+ 'copy_from' ,
689+ 'volume' ,
690+ 'checksum' ,
691+ )
625692 for attr in copy_attrs :
626693 if attr in parsed_args :
627694 val = getattr (parsed_args , attr , None )
@@ -665,12 +732,16 @@ def take_action(self, parsed_args):
665732 source_volume .id ,
666733 parsed_args .force ,
667734 parsed_args .image ,
668- (parsed_args .container_format
669- if parsed_args .container_format
670- else image .container_format ),
671- (parsed_args .disk_format
672- if parsed_args .disk_format
673- else image .disk_format ),
735+ (
736+ parsed_args .container_format
737+ if parsed_args .container_format
738+ else image .container_format
739+ ),
740+ (
741+ parsed_args .disk_format
742+ if parsed_args .disk_format
743+ else image .disk_format
744+ ),
674745 )
675746 elif parsed_args .file :
676747 # Send an open file handle to glanceclient so it will
@@ -687,8 +758,12 @@ def take_action(self, parsed_args):
687758 else :
688759 kwargs ["data" ] = sys .stdin
689760 else :
690- LOG .warning (_ ('Use --stdin to enable read image '
691- 'data from standard input' ))
761+ LOG .warning (
762+ _ (
763+ 'Use --stdin to enable read image '
764+ 'data from standard input'
765+ )
766+ )
692767
693768 if image .properties and parsed_args .properties :
694769 image .properties .update (kwargs ['properties' ])
@@ -697,8 +772,11 @@ def take_action(self, parsed_args):
697772 image = image_client .update_image (image .id , ** kwargs )
698773 finally :
699774 # Clean up open files - make sure data isn't a string
700- if ('data' in kwargs and hasattr (kwargs ['data' ], 'close' ) and
701- kwargs ['data' ] != sys .stdin ):
775+ if (
776+ 'data' in kwargs
777+ and hasattr (kwargs ['data' ], 'close' )
778+ and kwargs ['data' ] != sys .stdin
779+ ):
702780 kwargs ['data' ].close ()
703781
704782
@@ -728,6 +806,7 @@ def take_action(self, parsed_args):
728806 _formatters ['size' ] = HumanReadableSizeColumn
729807 display_columns , columns = _get_columns (image )
730808 _formatters ['properties' ] = format_columns .DictColumn
731- data = utils .get_item_properties (image , columns ,
732- formatters = _formatters )
809+ data = utils .get_item_properties (
810+ image , columns , formatters = _formatters
811+ )
733812 return (display_columns , data )
0 commit comments