From 44753c06090227c4cd158d89a482e71e49478308 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Sun, 5 Jan 2020 02:55:28 -0500 Subject: [PATCH] Always handle single-instance results --- client-cli/cli_lib/ceph.py | 8 ++++---- client-cli/cli_lib/network.py | 4 ++++ client-cli/cli_lib/node.py | 4 ++++ client-cli/cli_lib/vm.py | 4 ++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/client-cli/cli_lib/ceph.py b/client-cli/cli_lib/ceph.py index 7b800b2e..86974cf1 100644 --- a/client-cli/cli_lib/ceph.py +++ b/client-cli/cli_lib/ceph.py @@ -356,7 +356,7 @@ def format_list_osd(osd_list): if not osd_list: osd_list = list() # Handle single-item list - if isinstance(osd_list, dict): + if not isinstance(osd_list, list): osd_list = [ osd_list ] osd_list_output = [] @@ -709,7 +709,7 @@ def format_list_pool(pool_list): if not pool_list: pool_list = list() # Handle single-entry list - if isinstance(pool_list, dict): + if not isinstance(pool_list, list): pool_list = [ pool_list ] pool_list_output = [] @@ -1079,7 +1079,7 @@ def format_list_volume(volume_list): if not volume_list: volume_list = list() # Handle single-entry list - if isinstance(volume_list, dict): + if not isinstance(volume_list, list): volume_list = [ volume_list ] volume_list_output = [] @@ -1338,7 +1338,7 @@ def format_list_snapshot(snapshot_list): if not snapshot_list: snapshot_list = list() # Handle single-entry list - if isinstance(snapshot_list, dict): + if not isinstance(snapshot_list, list): snapshot_list = [ snapshot_list ] snapshot_list_output = [] diff --git a/client-cli/cli_lib/network.py b/client-cli/cli_lib/network.py index 8167f58d..1a5dc3c0 100644 --- a/client-cli/cli_lib/network.py +++ b/client-cli/cli_lib/network.py @@ -538,6 +538,10 @@ def format_list(config, network_list): click.echo("No network found") return + # Handle single-element lists + if not isinstance(network_list, list): + network_list = [ network_list ] + network_list_output = [] # Determine optimal column widths diff --git a/client-cli/cli_lib/node.py b/client-cli/cli_lib/node.py index 7bf1990f..1e890cbc 100644 --- a/client-cli/cli_lib/node.py +++ b/client-cli/cli_lib/node.py @@ -214,6 +214,10 @@ def format_info(node_information, long_output): click.echo('') def format_list(node_list): + # Handle single-element lists + if not isinstance(node_list, list): + node_list = [ node_list ] + node_list_output = [] # Determine optimal column widths diff --git a/client-cli/cli_lib/vm.py b/client-cli/cli_lib/vm.py index ee5df7b1..e4b46b57 100644 --- a/client-cli/cli_lib/vm.py +++ b/client-cli/cli_lib/vm.py @@ -448,6 +448,10 @@ def follow_console_log(config, vm, lines=10): # Output display functions # def format_info(config, domain_information, long_output): + # Handle single-element lists + if not isinstance(domain_information, list): + domain_information = [ domain_information ] + # Format a nice output; do this line-by-line then concat the elements at the end ainformation = [] ainformation.append('{}Virtual machine information:{}'.format(ansiprint.bold(), ansiprint.end()))