Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/836.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed `find_children_w_parents` to only return the matched child line and its actual descendants, instead of every sibling line under the same top-level parent.
24 changes: 11 additions & 13 deletions netutils/config/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,20 +416,18 @@ def find_children_w_parents(
>>> print(bgp_conf)
[' address-family ipv4 unicast', ' neighbor 192.168.1.2 activate', ' network 172.17.1.0 mask']
"""
config = []
potential_parents = [
elem.parents[0]
for elem in self.build_config_relationship()
relationships = self.build_config_relationship()
matched_lines = {
elem.config_line
for elem in relationships
if self._match_type_check(elem.config_line, child_pattern, match_type)
]
for cfg_line in self.build_config_relationship():
parents = cfg_line.parents[0] if cfg_line.parents else None
if parents in potential_parents and self._match_type_check(
parents, # type: ignore[arg-type]
parent_pattern,
match_type,
):
config.append(cfg_line.config_line)
and elem.parents
and self._match_type_check(elem.parents[0], parent_pattern, match_type)
}
config = []
for elem in relationships:
if elem.config_line in matched_lines or any(parent in matched_lines for parent in elem.parents):
config.append(elem.config_line)
return config


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"parent_pattern": "context local",
"child_pattern": " logging",
"match_type": "regex"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
logging something
logging something else
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
context local
something not logging
logging something
logging something else
something else not logging
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
contact-email-addr sch-smart-licensing@cisco.com
profile "CiscoTAC-1"
active
destination transport-method http