From 185615e6e8c69315f2de28f46c0e163d926d7a78 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 1 Dec 2020 03:20:00 -0500 Subject: [PATCH] Don't strip single-element lists This was a dumb decision that complicated handling of single-item entries. --- api-daemon/pvcapid/helper.py | 44 ----------------------------------- client-cli/cli_lib/ceph.py | 12 ---------- client-cli/cli_lib/network.py | 7 ------ client-cli/cli_lib/node.py | 4 ---- client-cli/cli_lib/vm.py | 4 ---- 5 files changed, 71 deletions(-) diff --git a/api-daemon/pvcapid/helper.py b/api-daemon/pvcapid/helper.py index a8444d0c..9d496381 100755 --- a/api-daemon/pvcapid/helper.py +++ b/api-daemon/pvcapid/helper.py @@ -205,10 +205,6 @@ def node_list(limit=None, daemon_state=None, coordinator_state=None, domain_stat 'message': retdata } - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - return retdata, retcode @@ -394,10 +390,6 @@ def vm_state(vm): retflag, retdata = pvc_vm.get_list(zk_conn, None, None, vm, is_fuzzy=False) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 @@ -427,10 +419,6 @@ def vm_node(vm): retflag, retdata = pvc_vm.get_list(zk_conn, None, None, vm, is_fuzzy=False) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 @@ -490,10 +478,6 @@ def vm_list(node=None, state=None, limit=None, is_fuzzy=True): retflag, retdata = pvc_vm.get_list(zk_conn, node, state, limit, is_fuzzy) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 @@ -545,10 +529,6 @@ def get_vm_meta(vm): retflag, retdata = pvc_vm.get_list(zk_conn, None, None, vm, is_fuzzy=False) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 @@ -820,10 +800,6 @@ def vm_flush_locks(vm): retflag, retdata = pvc_vm.get_list(zk_conn, None, None, vm, is_fuzzy=False) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retdata['state'] not in ['stop', 'disable']: return {"message": "VM must be stopped to flush locks"}, 400 @@ -853,10 +829,6 @@ def net_list(limit=None, is_fuzzy=True): retflag, retdata = pvc_network.get_list(zk_conn, limit, is_fuzzy) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 @@ -1029,10 +1001,6 @@ def net_acl_list(network, limit=None, direction=None, is_fuzzy=True): 'message': retdata } - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - return retdata, retcode @@ -1281,10 +1249,6 @@ def ceph_pool_list(limit=None, is_fuzzy=True): retflag, retdata = pvc_ceph.get_list_pool(zk_conn, limit, is_fuzzy) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 @@ -1348,10 +1312,6 @@ def ceph_volume_list(pool=None, limit=None, is_fuzzy=True): retflag, retdata = pvc_ceph.get_list_volume(zk_conn, pool, limit, is_fuzzy) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 @@ -1623,10 +1583,6 @@ def ceph_volume_snapshot_list(pool=None, volume=None, limit=None, is_fuzzy=True) retflag, retdata = pvc_ceph.get_list_snapshot(zk_conn, pool, volume, limit, is_fuzzy) pvc_common.stopZKConnection(zk_conn) - # If this is a single element, strip it out of the list - if isinstance(retdata, list) and len(retdata) == 1: - retdata = retdata[0] - if retflag: if retdata: retcode = 200 diff --git a/client-cli/cli_lib/ceph.py b/client-cli/cli_lib/ceph.py index 33358617..34acc3b1 100644 --- a/client-cli/cli_lib/ceph.py +++ b/client-cli/cli_lib/ceph.py @@ -300,9 +300,6 @@ def format_list_osd(osd_list): # Handle empty list if not osd_list: osd_list = list() - # Handle single-item list - if not isinstance(osd_list, list): - osd_list = [osd_list] osd_list_output = [] @@ -628,9 +625,6 @@ def format_list_pool(pool_list): # Handle empty list if not pool_list: pool_list = list() - # Handle single-entry list - if not isinstance(pool_list, list): - pool_list = [pool_list] pool_list_output = [] @@ -989,9 +983,6 @@ def format_list_volume(volume_list): # Handle empty list if not volume_list: volume_list = list() - # Handle single-entry list - if not isinstance(volume_list, list): - volume_list = [volume_list] volume_list_output = [] @@ -1209,9 +1200,6 @@ def format_list_snapshot(snapshot_list): # Handle empty list if not snapshot_list: snapshot_list = list() - # Handle single-entry list - 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 9ce886f8..efa159ff 100644 --- a/client-cli/cli_lib/network.py +++ b/client-cli/cli_lib/network.py @@ -440,10 +440,6 @@ def format_list(config, network_list): if not network_list: return "No network found" - # Handle single-element lists - if not isinstance(network_list, list): - network_list = [network_list] - network_list_output = [] # Determine optimal column widths @@ -617,9 +613,6 @@ def format_list_acl(acl_list): # Handle when we get an empty entry if not acl_list: acl_list = list() - # Handle when we get a single entry - if isinstance(acl_list, dict): - acl_list = [acl_list] acl_list_output = [] diff --git a/client-cli/cli_lib/node.py b/client-cli/cli_lib/node.py index 56ffc4cc..37804caf 100644 --- a/client-cli/cli_lib/node.py +++ b/client-cli/cli_lib/node.py @@ -186,10 +186,6 @@ def format_info(node_information, long_output): def format_list(node_list, raw): - # Handle single-element lists - if not isinstance(node_list, list): - node_list = [node_list] - if raw: ainformation = list() for node in sorted(item['name'] for item in node_list): diff --git a/client-cli/cli_lib/vm.py b/client-cli/cli_lib/vm.py index f46eb6a8..e00a521e 100644 --- a/client-cli/cli_lib/vm.py +++ b/client-cli/cli_lib/vm.py @@ -1211,10 +1211,6 @@ def format_info(config, domain_information, long_output): def format_list(config, vm_list, raw): - # Handle single-element lists - if not isinstance(vm_list, list): - vm_list = [vm_list] - # Function to strip the "br" off of nets and return a nicer list def getNiceNetID(domain_information): # Network list