From 18520d6c7721a5a22408c3166f2597da877e6750 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 5 Jul 2019 16:28:18 -0400 Subject: [PATCH] Support disabling fuzzy limit matching Used for the APIs when they filter by name but we don't want a fuzzy limit since we specified an exact name. --- client-common/ceph.py | 53 ++++++++++++++++++++++------------------ client-common/network.py | 21 ++++++++-------- client-common/node.py | 13 +++++----- client-common/vm.py | 4 +-- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/client-common/ceph.py b/client-common/ceph.py index 6a3cdf84..77a0e206 100644 --- a/client-common/ceph.py +++ b/client-common/ceph.py @@ -348,18 +348,19 @@ def unset_osd(zk_conn, option): return success, message -def get_list_osd(zk_conn, limit): +def get_list_osd(zk_conn, limit, is_fuzzy=True): osd_list = [] full_osd_list = zkhandler.listchildren(zk_conn, '/ceph/osds') for osd in full_osd_list: if limit: try: - # Implicitly assume fuzzy limits - if not re.match('\^.*', limit): - limit = '.*' + limit - if not re.match('.*\$', limit): - limit = limit + '.*' + if is_fuzzy: + # Implicitly assume fuzzy limits + if not re.match('\^.*', limit): + limit = '.*' + limit + if not re.match('.*\$', limit): + limit = limit + '.*' if re.match(limit, osd): osd_list.append(getOSDInformation(zk_conn, osd)) @@ -674,18 +675,19 @@ def remove_pool(zk_conn, name): return success, message -def get_list_pool(zk_conn, limit): +def get_list_pool(zk_conn, limit, is_fuzzy=True): pool_list = [] full_pool_list = zkhandler.listchildren(zk_conn, '/ceph/pools') for pool in full_pool_list: if limit: try: - # Implicitly assume fuzzy limits - if not re.match('\^.*', limit): - limit = '.*' + limit - if not re.match('.*\$', limit): - limit = limit + '.*' + if is_fuzzy: + # Implicitly assume fuzzy limits + if not re.match('\^.*', limit): + limit = '.*' + limit + if not re.match('.*\$', limit): + limit = limit + '.*' if re.match(limit, pool): pool_list.append(getPoolInformation[zk_conn, pool]) @@ -942,7 +944,7 @@ def remove_volume(zk_conn, pool, name): return success, message -def get_list_volume(zk_conn, pool, limit): +def get_list_volume(zk_conn, pool, limit, is_fuzzy=True): volume_list = [] if pool and not verifyPool(zk_conn, name): return False, 'ERROR: No pool with name "{}" is present in the cluster.'.format(name) @@ -953,11 +955,12 @@ def get_list_volume(zk_conn, pool, limit): pool_name, volume_name = volume.split('/') if limit: try: - # Implicitly assume fuzzy limits - if not re.match('\^.*', limit): - limit = '.*' + limit - if not re.match('.*\$', limit): - limit = limit + '.*' + if is_fuzzy: + # Implicitly assume fuzzy limits + if not re.match('\^.*', limit): + limit = '.*' + limit + if not re.match('.*\$', limit): + limit = limit + '.*' if re.match(limit, volume): volume_list.append(getVolumeInformation(zk_conn, pool_name, volume_name)) @@ -1158,7 +1161,7 @@ def remove_snapshot(zk_conn, pool, volume, name): return success, message -def get_list_snapshot(zk_conn, pool, volume, limit): +def get_list_snapshot(zk_conn, pool, volume, limit, is_fuzzy=True): snapshot_list = [] if pool and not verifyPool(zk_conn, pool): return False, 'ERROR: No pool with name "{}" is present in the cluster.'.format(pool) @@ -1173,11 +1176,13 @@ def get_list_snapshot(zk_conn, pool, volume, limit): pool_name, volume_name = volume.split('/') if limit: try: - # Implicitly assume fuzzy limits - if not re.match('\^.*', limit): - limit = '.*' + limit - if not re.match('.*\$', limit): - limit = limit + '.*' + if is_fuzzy: + # Implicitly assume fuzzy limits + if not re.match('\^.*', limit): + limit = '.*' + limit + if not re.match('.*\$', limit): + limit = limit + '.*' + if re.match(limit, snapshot): snapshot_list.append(getVolumeInformation(zk_conn, pool_name, volume_name, snapshot_name)) except Exception as e: diff --git a/client-common/network.py b/client-common/network.py index 8b82458d..7e42fd63 100644 --- a/client-common/network.py +++ b/client-common/network.py @@ -491,7 +491,7 @@ def get_info(zk_conn, network): return True, network_information -def get_list(zk_conn, limit): +def get_list(zk_conn, limit, is_fuzzy=True): net_list = [] full_net_list = zkhandler.listchildren(zk_conn, '/networks') @@ -499,11 +499,12 @@ def get_list(zk_conn, limit): description = zkhandler.readdata(zk_conn, '/networks/{}'.format(net)) if limit: try: - # Implcitly assume fuzzy limits - if not re.match('\^.*', limit): - limit = '.*' + limit - if not re.match('.*\$', limit): - limit = limit + '.*' + if is_fuzzy: + # Implcitly assume fuzzy limits + if not re.match('\^.*', limit): + limit = '.*' + limit + if not re.match('.*\$', limit): + limit = limit + '.*' if re.match(limit, net): net_list.append(getNetworkInformation(zk_conn, net)) @@ -517,7 +518,7 @@ def get_list(zk_conn, limit): #output_string = formatNetworkList(zk_conn, net_list) return True, net_list -def get_list_dhcp(zk_conn, network, limit, only_static=False): +def get_list_dhcp(zk_conn, network, limit, only_static=False, is_fuzzy=True): # Validate and obtain alternate passed value net_vni = getNetworkVNI(zk_conn, network) if not net_vni: @@ -532,7 +533,7 @@ def get_list_dhcp(zk_conn, network, limit, only_static=False): full_dhcp_list = getNetworkDHCPLeases(zk_conn, net_vni) reservations = False - if limit: + if limit and is_fuzzy: try: # Implcitly assume fuzzy limits if not re.match('\^.*', limit): @@ -559,7 +560,7 @@ def get_list_dhcp(zk_conn, network, limit, only_static=False): #output_string = formatDHCPLeaseList(zk_conn, net_vni, dhcp_list, reservations=reservations) return True, dhcp_list -def get_list_acl(zk_conn, network, limit, direction): +def get_list_acl(zk_conn, network, limit, direction, is_fuzzy=True): # Validate and obtain alternate passed value net_vni = getNetworkVNI(zk_conn, network) if not net_vni: @@ -576,7 +577,7 @@ def get_list_acl(zk_conn, network, limit, direction): acl_list = [] full_acl_list = getNetworkACLs(zk_conn, net_vni, direction) - if limit: + if limit and is_fuzzy: try: # Implcitly assume fuzzy limits if not re.match('\^.*', limit): diff --git a/client-common/node.py b/client-common/node.py index bf3e5615..a3b18ccb 100644 --- a/client-common/node.py +++ b/client-common/node.py @@ -231,18 +231,19 @@ def get_info(zk_conn, node): return True, node_information -def get_list(zk_conn, limit): +def get_list(zk_conn, limit, is_fuzzy=True): node_list = [] full_node_list = zkhandler.listchildren(zk_conn, '/nodes') for node in full_node_list: if limit: try: - # Implcitly assume fuzzy limits - if not re.match('\^.*', limit): - limit = '.*' + limit - if not re.match('.*\$', limit): - limit = limit + '.*' + if is_fuzzy: + # Implcitly assume fuzzy limits + if not re.match('\^.*', limit): + limit = '.*' + limit + if not re.match('.*\$', limit): + limit = limit + '.*' if re.match(limit, node): node_list.append(getNodeInformation(zk_conn, node)) diff --git a/client-common/vm.py b/client-common/vm.py index 745462b1..ecb4cff9 100644 --- a/client-common/vm.py +++ b/client-common/vm.py @@ -560,7 +560,7 @@ def get_info(zk_conn, domain): return True, domain_information -def get_list(zk_conn, node, state, limit): +def get_list(zk_conn, node, state, limit, is_fuzzy=True): if node: # Verify node is valid if not common.verifyNode(zk_conn, node): @@ -575,7 +575,7 @@ def get_list(zk_conn, node, state, limit): vm_list = [] # Set our limit to a sensible regex - if limit: + if limit and is_fuzzy: try: # Implcitly assume fuzzy limits if not re.match('\^.*', limit):