volume: Migrate 'volume list' to compute SDK

Change-Id: Iae662aa6b391ba6ae5f569184c7d19fb3654be35
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-05-07 15:46:35 +01:00
parent 9f30ee9af2
commit 55cbb84e60
3 changed files with 10 additions and 8 deletions

View File

@ -378,7 +378,6 @@ class ListVolume(command.Lister):
def take_action(self, parsed_args): def take_action(self, parsed_args):
volume_client = self.app.client_manager.volume volume_client = self.app.client_manager.volume
compute_client = self.app.client_manager.compute
if parsed_args.long: if parsed_args.long:
columns = ( columns = (
@ -420,7 +419,8 @@ class ListVolume(command.Lister):
# Cache the server list # Cache the server list
server_cache = {} server_cache = {}
try: try:
for s in compute_client.servers.list(): compute_client = self.app.client_manager.sdk_connection.compute
for s in compute_client.servers():
server_cache[s.id] = s server_cache[s.id] = s
except Exception: except Exception:
# Just forget it if there's any trouble # Just forget it if there's any trouble

View File

@ -20,6 +20,7 @@ import functools
import logging import logging
from cliff import columns as cliff_columns from cliff import columns as cliff_columns
from openstack import exceptions as sdk_exceptions
from osc_lib.cli import format_columns from osc_lib.cli import format_columns
from osc_lib.cli import parseractions from osc_lib.cli import parseractions
from osc_lib.command import command from osc_lib.command import command
@ -507,10 +508,10 @@ class ListVolume(command.Lister):
server_cache = {} server_cache = {}
if do_server_list: if do_server_list:
try: try:
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.sdk_connection.compute
for s in compute_client.servers.list(): for s in compute_client.servers():
server_cache[s.id] = s server_cache[s.id] = s
except Exception: except sdk_exceptions.SDKException:
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass # nosec: B110
AttachmentsColumnWithCache = functools.partial( AttachmentsColumnWithCache = functools.partial(

View File

@ -20,6 +20,7 @@ import functools
import logging import logging
from cliff import columns as cliff_columns from cliff import columns as cliff_columns
from openstack import exceptions as sdk_exceptions
from openstack import utils as sdk_utils from openstack import utils as sdk_utils
from osc_lib.cli import format_columns from osc_lib.cli import format_columns
from osc_lib.cli import parseractions from osc_lib.cli import parseractions
@ -522,10 +523,10 @@ class ListVolume(command.Lister):
server_cache = {} server_cache = {}
if do_server_list: if do_server_list:
try: try:
compute_client = self.app.client_manager.compute compute_client = self.app.client_manager.sdk_connection.compute
for s in compute_client.servers.list(): for s in compute_client.servers():
server_cache[s.id] = s server_cache[s.id] = s
except Exception: except sdk_exceptions.SDKException:
# Just forget it if there's any trouble # Just forget it if there's any trouble
pass # nosec: B110 pass # nosec: B110
AttachmentsColumnWithCache = functools.partial( AttachmentsColumnWithCache = functools.partial(