@@ -1087,11 +1087,22 @@ def get_parser(self, prog_name):
10871087 default = False ,
10881088 help = _ ('List additional fields in output' ),
10891089 )
1090- parser .add_argument (
1090+ name_lookup_group = parser .add_mutually_exclusive_group ()
1091+ name_lookup_group .add_argument (
10911092 '-n' , '--no-name-lookup' ,
10921093 action = 'store_true' ,
10931094 default = False ,
1094- help = _ ('Skip flavor and image name lookup.' ),
1095+ help = _ ('Skip flavor and image name lookup.'
1096+ 'Mutually exclusive with "--name-lookup-one-by-one"'
1097+ ' option.' ),
1098+ )
1099+ name_lookup_group .add_argument (
1100+ '--name-lookup-one-by-one' ,
1101+ action = 'store_true' ,
1102+ default = False ,
1103+ help = _ ('When looking up flavor and image names, look them up'
1104+ 'one by one as needed instead of all together (default). '
1105+ 'Mutually exclusive with "--no-name-lookup|-n" option.' ),
10951106 )
10961107 parser .add_argument (
10971108 '--marker' ,
@@ -1266,28 +1277,43 @@ def take_action(self, parsed_args):
12661277 limit = parsed_args .limit )
12671278
12681279 images = {}
1269- # Create a dict that maps image_id to image object.
1270- # Needed so that we can display the "Image Name" column.
1271- # "Image Name" is not crucial, so we swallow any exceptions.
1272- if data and not parsed_args .no_name_lookup :
1273- try :
1274- images_list = self .app .client_manager .image .images .list ()
1275- for i in images_list :
1276- images [i .id ] = i
1277- except Exception :
1278- pass
1279-
12801280 flavors = {}
1281- # Create a dict that maps flavor_id to flavor object.
1282- # Needed so that we can display the "Flavor Name" column.
1283- # "Flavor Name" is not crucial, so we swallow any exceptions.
12841281 if data and not parsed_args .no_name_lookup :
1285- try :
1286- flavors_list = compute_client .flavors .list (is_public = None )
1287- for i in flavors_list :
1288- flavors [i .id ] = i
1289- except Exception :
1290- pass
1282+ # Create a dict that maps image_id to image object.
1283+ # Needed so that we can display the "Image Name" column.
1284+ # "Image Name" is not crucial, so we swallow any exceptions.
1285+ if parsed_args .name_lookup_one_by_one or image_id :
1286+ for i_id in set (filter (lambda x : x is not None ,
1287+ (s .image .get ('id' ) for s in data ))):
1288+ try :
1289+ images [i_id ] = image_client .images .get (i_id )
1290+ except Exception :
1291+ pass
1292+ else :
1293+ try :
1294+ images_list = image_client .images .list ()
1295+ for i in images_list :
1296+ images [i .id ] = i
1297+ except Exception :
1298+ pass
1299+
1300+ # Create a dict that maps flavor_id to flavor object.
1301+ # Needed so that we can display the "Flavor Name" column.
1302+ # "Flavor Name" is not crucial, so we swallow any exceptions.
1303+ if parsed_args .name_lookup_one_by_one or flavor_id :
1304+ for f_id in set (filter (lambda x : x is not None ,
1305+ (s .flavor .get ('id' ) for s in data ))):
1306+ try :
1307+ flavors [f_id ] = compute_client .flavors .get (f_id )
1308+ except Exception :
1309+ pass
1310+ else :
1311+ try :
1312+ flavors_list = compute_client .flavors .list (is_public = None )
1313+ for i in flavors_list :
1314+ flavors [i .id ] = i
1315+ except Exception :
1316+ pass
12911317
12921318 # Populate image_name, image_id, flavor_name and flavor_id attributes
12931319 # of server objects so that we can display those columns.
0 commit comments