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.
This commit is contained in:
Joshua Boniface 2019-07-05 16:28:18 -04:00
parent dc16f51b2a
commit 18520d6c77
4 changed files with 49 additions and 42 deletions

View File

@ -348,13 +348,14 @@ 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:
if is_fuzzy:
# Implicitly assume fuzzy limits
if not re.match('\^.*', limit):
limit = '.*' + limit
@ -674,13 +675,14 @@ 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:
if is_fuzzy:
# Implicitly assume fuzzy limits
if not re.match('\^.*', limit):
limit = '.*' + limit
@ -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,6 +955,7 @@ def get_list_volume(zk_conn, pool, limit):
pool_name, volume_name = volume.split('/')
if limit:
try:
if is_fuzzy:
# Implicitly assume fuzzy limits
if not re.match('\^.*', limit):
limit = '.*' + limit
@ -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:
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:

View File

@ -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,6 +499,7 @@ def get_list(zk_conn, limit):
description = zkhandler.readdata(zk_conn, '/networks/{}'.format(net))
if limit:
try:
if is_fuzzy:
# Implcitly assume fuzzy limits
if not re.match('\^.*', limit):
limit = '.*' + limit
@ -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):

View File

@ -231,13 +231,14 @@ 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:
if is_fuzzy:
# Implcitly assume fuzzy limits
if not re.match('\^.*', limit):
limit = '.*' + limit

View File

@ -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):