networktocode / netutils

Python library that is a collection of functions and objects for common network automation tasks.
https://netutils.readthedocs.io/
Other
218 stars 49 forks source link

Config Parsing Helper #124

Open itdependsnetworks opened 2 years ago

itdependsnetworks commented 2 years ago

Environment

Proposed Functionality

Provided convinence methods to parse through a standard Ios-like (and potentially others) configurations. The idea being similar to CiscoConfParse in scope, but ideally to provide a few key features.

The ability to navigate nested configuration for a known path:

root_obj.get_path(["router bgp 45000", "address-family ipv4 unicast"])
# Returns 
  neighbor 192.168.1.2 activate
  network 172.17.1.0 mas

The ability to get configurations with parent context:

root_obj.get_path_with_parents(["router bgp 45000", "address-family ipv4 unicast"])
# Returns 
router bgp 45000
 address-family ipv4 unicast
  neighbor 192.168.1.2 activate
  network 172.17.1.0 mas

The ability to get configurations that match:

root_obj.get_multpile_parents(["interface GigabitEthernet.*"])
# Returns 
[ """interface GigabitEthernet0/1/0
 mac-address 00e0.1476.7600
 no ip address
!""", 
"""interface GigabitEthernet0/1/1
 mac-address 00e0.1476.7601
 no ip address
!"""]

The ability to get configurations that contains:

root_obj.get_contained(["interface GigabitEthernet.*"], "channel-group 1")
# Returns 
[ """interface GigabitEthernet0/1/0
 mac-address 00e0.1476.7600
 no ip address
 channel-group 1
!""", 
"""interface GigabitEthernet0/1/1
 mac-address 00e0.1476.7601
 no ip address
 channel-group 1
!"""]

And similar

Use Case

As an operator, I want the ability to find configurations based on various different characteristics. Such that I can quickly make logical choices, populate a SoT, find otherwise difficult to find configurations (offline), and quickly interrogate configurations across a large amount of data, just to name a few.

jeffkala commented 2 years ago

Would the idea be to rework how the parsers work, or for these to be its own logic?

itdependsnetworks commented 2 years ago

I think it should just be adding convenience methods.

mundruid commented 2 years ago

Functions to be added: def find_blocks(): def find_children(): def find_children_w_parents(): def find_interface_objects(): def find_lineage(): def find_lines(): def find_object_branches(): def find_objects(): def find_objects_dna(): def find_objects_w_all_children(): def find_objects_w_child(): def find_objects_w_missing_children(): def find_objects_w_parents(): def find_objects_wo_child(): def find_parents_w_child(): def find_parents_wo_child():

itdependsnetworks commented 1 year ago

For further clarity, ciscoconfparse uses GPL and intends to keep that license, this is an intention to get similar behaviour without the constructs that come with GPL license.