Don't strip single-element lists
This was a dumb decision that complicated handling of single-item entries.
This commit is contained in:
parent
3a5955b41c
commit
185615e6e8
|
@ -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
|
||||
|
|
|
@ -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 = []
|
||||
|
||||
|
|
|
@ -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 = []
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue