@@ -490,19 +490,6 @@ def take_action(self, parsed_args):
490490 column_headers = copy .deepcopy (columns )
491491 column_headers [4 ] = 'Attached to'
492492
493- # Cache the server list
494- server_cache = {}
495- try :
496- compute_client = self .app .client_manager .compute
497- for s in compute_client .servers .list ():
498- server_cache [s .id ] = s
499- except Exception :
500- # Just forget it if there's any trouble
501- pass
502- AttachmentsColumnWithCache = functools .partial (
503- AttachmentsColumn , server_cache = server_cache
504- )
505-
506493 project_id = None
507494 if parsed_args .project :
508495 project_id = identity_common .find_project (
@@ -533,6 +520,28 @@ def take_action(self, parsed_args):
533520 marker = parsed_args .marker ,
534521 limit = parsed_args .limit ,
535522 )
523+
524+ do_server_list = False
525+
526+ for vol in data :
527+ if vol .status == 'in-use' :
528+ do_server_list = True
529+ break
530+
531+ # Cache the server list
532+ server_cache = {}
533+ if do_server_list :
534+ try :
535+ compute_client = self .app .client_manager .compute
536+ for s in compute_client .servers .list ():
537+ server_cache [s .id ] = s
538+ except Exception :
539+ # Just forget it if there's any trouble
540+ pass
541+ AttachmentsColumnWithCache = functools .partial (
542+ AttachmentsColumn , server_cache = server_cache
543+ )
544+
536545 column_headers = utils .backward_compat_col_lister (
537546 column_headers , parsed_args .columns , {'Display Name' : 'Name' }
538547 )
0 commit comments