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:
parent
dc16f51b2a
commit
18520d6c77
|
@ -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:
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue