diff --git a/daemon-common/ceph.py b/daemon-common/ceph.py index b85d38e2..770cfe8a 100644 --- a/daemon-common/ceph.py +++ b/daemon-common/ceph.py @@ -375,7 +375,7 @@ def get_list_osd(zkhandler, limit, is_fuzzy=True): for osd in full_osd_list: if limit: try: - if re.match(limit, osd): + if re.fullmatch(limit, osd): osd_list.append(getOSDInformation(zkhandler, osd)) except Exception as e: return False, "Regex Error: {}".format(e) @@ -496,16 +496,19 @@ def remove_pool(zkhandler, name): def get_list_pool(zkhandler, limit, is_fuzzy=True): full_pool_list = zkhandler.children("base.pool") - if limit: - if not is_fuzzy: - limit = "^" + limit + "$" + if is_fuzzy and limit: + # Implicitly assume fuzzy limits + if not re.match(r"\^.*", limit): + limit = ".*" + limit + if not re.match(r".*\$", limit): + limit = limit + ".*" get_pool_info = dict() for pool in full_pool_list: is_limit_match = False if limit: try: - if re.match(limit, pool): + if re.fullmatch(limit, pool): is_limit_match = True except Exception as e: return False, "Regex Error: {}".format(e) @@ -848,15 +851,12 @@ def get_list_volume(zkhandler, pool, limit, is_fuzzy=True): full_volume_list = getCephVolumes(zkhandler, pool) - if limit: - if not is_fuzzy: - limit = "^" + limit + "$" - else: - # Implicitly assume fuzzy limits - if not re.match(r"\^.*", limit): - limit = ".*" + limit - if not re.match(r".*\$", limit): - limit = limit + ".*" + if is_fuzzy and limit: + # Implicitly assume fuzzy limits + if not re.match(r"\^.*", limit): + limit = ".*" + limit + if not re.match(r".*\$", limit): + limit = limit + ".*" get_volume_info = dict() for volume in full_volume_list: @@ -867,7 +867,7 @@ def get_list_volume(zkhandler, pool, limit, is_fuzzy=True): if limit: # Try to match the limit against the volume name try: - if re.match(limit, volume_name): + if re.fullmatch(limit, volume_name): is_limit_match = True except Exception as e: return False, "Regex Error: {}".format(e) @@ -1073,7 +1073,7 @@ def get_list_snapshot(zkhandler, pool, volume, limit, is_fuzzy=True): pool_name, volume_name = volume.split("/") if limit: try: - if re.match(limit, snapshot_name): + if re.fullmatch(limit, snapshot_name): snapshot_list.append( { "pool": pool_name, diff --git a/daemon-common/network.py b/daemon-common/network.py index d78284bd..781a77fc 100644 --- a/daemon-common/network.py +++ b/daemon-common/network.py @@ -665,16 +665,20 @@ def get_list(zkhandler, limit, is_fuzzy=True): net_list = [] full_net_list = zkhandler.children("base.network") + if is_fuzzy and limit: + # Implicitly assume fuzzy limits + if not re.match(r"\^.*", limit): + limit = ".*" + limit + if not re.match(r".*\$", limit): + limit = limit + ".*" + for net in full_net_list: description = zkhandler.read(("network", net)) if limit: try: - if not is_fuzzy: - limit = "^" + limit + "$" - - if re.match(limit, net): + if re.fullmatch(limit, net): net_list.append(getNetworkInformation(zkhandler, net)) - if re.match(limit, description): + if re.fullmatch(limit, description): net_list.append(getNetworkInformation(zkhandler, net)) except Exception as e: return False, "Regex Error: {}".format(e) @@ -700,25 +704,19 @@ def get_list_dhcp(zkhandler, network, limit, only_static=False, is_fuzzy=True): full_dhcp_list = getNetworkDHCPReservations(zkhandler, net_vni) full_dhcp_list += getNetworkDHCPLeases(zkhandler, net_vni) - if limit: - try: - if not is_fuzzy: - limit = "^" + limit + "$" - - # Implcitly assume fuzzy limits - if not re.match(r"\^.*", limit): - limit = ".*" + limit - if not re.match(r".*\$", limit): - limit = limit + ".*" - except Exception as e: - return False, "Regex Error: {}".format(e) + if is_fuzzy and limit: + # Implicitly assume fuzzy limits + if not re.match(r"\^.*", limit): + limit = ".*" + limit + if not re.match(r".*\$", limit): + limit = limit + ".*" for lease in full_dhcp_list: valid_lease = False if limit: - if re.match(limit, lease): + if re.fullmatch(limit, lease): valid_lease = True - if re.match(limit, lease): + if re.fullmatch(limit, lease): valid_lease = True else: valid_lease = True @@ -748,23 +746,17 @@ def get_list_acl(zkhandler, network, limit, direction, is_fuzzy=True): acl_list = [] full_acl_list = getNetworkACLs(zkhandler, net_vni, direction) - if limit: - try: - if not is_fuzzy: - limit = "^" + limit + "$" - - # Implcitly assume fuzzy limits - if not re.match(r"\^.*", limit): - limit = ".*" + limit - if not re.match(r".*\$", limit): - limit = limit + ".*" - except Exception as e: - return False, "Regex Error: {}".format(e) + if is_fuzzy and limit: + # Implicitly assume fuzzy limits + if not re.match(r"\^.*", limit): + limit = ".*" + limit + if not re.match(r".*\$", limit): + limit = limit + ".*" for acl in full_acl_list: valid_acl = False if limit: - if re.match(limit, acl["description"]): + if re.fullmatch(limit, acl["description"]): valid_acl = True else: valid_acl = True diff --git a/daemon-common/node.py b/daemon-common/node.py index b52a9613..bd1d5a99 100644 --- a/daemon-common/node.py +++ b/daemon-common/node.py @@ -237,13 +237,17 @@ def get_list( node_list = [] full_node_list = zkhandler.children("base.node") + if is_fuzzy and limit: + # Implicitly assume fuzzy limits + if not re.match(r"\^.*", limit): + limit = ".*" + limit + if not re.match(r".*\$", limit): + limit = limit + ".*" + for node in full_node_list: if limit: try: - if not is_fuzzy: - limit = "^" + limit + "$" - - if re.match(limit, node): + if re.fullmatch(limit, node): node_list.append(getNodeInformation(zkhandler, node)) except Exception as e: return False, "Regex Error: {}".format(e) diff --git a/daemon-common/vm.py b/daemon-common/vm.py index a95f1efc..3b4ee633 100644 --- a/daemon-common/vm.py +++ b/daemon-common/vm.py @@ -1227,9 +1227,9 @@ def get_list(zkhandler, node, state, tag, limit, is_fuzzy=True, negate=False): if limit: # Try to match the limit against the UUID (if applicable) and name try: - if is_limit_uuid and re.match(limit, vm): + if is_limit_uuid and re.fullmatch(limit, vm): is_limit_match = True - if re.match(limit, name): + if re.fullmatch(limit, name): is_limit_match = True except Exception as e: return False, "Regex Error: {}".format(e)