Skip to content

Commit c657047

Browse files
committed
volume list: Don't call nova if no volume is attached
Currently 'openstack volume list' calls nova to resolve server UUIDs to server names. This is not required if: 1. no volume is attached to an instance 2. no volume exists in deployment This patch fixes this by checking volume statuses and, if any volume has status 'in-use', we will call nova to resolve server names. Note that we don't check for 'reserved', 'attaching', 'detaching' states since those are transition states and doesn't guarantee that the volume is actually attached to the instance. Change-Id: Ic4d89db69244d3fba44d4b69c79b3e7632ee3d53
1 parent 2642b07 commit c657047

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

openstackclient/volume/v2/volume.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)