Skip to content

Commit

Permalink
Remove legacy APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mpenning committed Nov 29, 2023
1 parent b505d6d commit a499c6e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 453 deletions.
290 changes: 0 additions & 290 deletions ciscoconfparse/ciscoconfparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2112,94 +2112,6 @@ def find_objects_w_missing_children(

return retval

# This method is on CiscoConfParse()
@ logger.catch(reraise=True)
def find_parents_w_child(self, parentspec, childspec, ignore_ws=False):
"""Parse through all children matching childspec, and return a list of
parents that matched the parentspec. Only the parent lines will be
returned.
Parameters
----------
parentspec : str
Text regular expression for the line to be matched; this must match the parent's line
childspec : str
Text regular expression for the line to be matched; this must match the child's line
ignore_ws : bool
boolean that controls whether whitespace is ignored
Returns
-------
list
A list of matching parent configuration lines
Examples
--------
This example finds all ports that are members of access vlan 300
in following config...
.. code::
!
interface FastEthernet0/1
switchport access vlan 532
spanning-tree vlan 532 cost 3
!
interface FastEthernet0/2
switchport access vlan 300
spanning-tree portfast
!
interface FastEthernet0/2
duplex full
speed 100
switchport access vlan 300
spanning-tree portfast
!
The following interfaces should be returned:
.. code::
interface FastEthernet0/2
interface FastEthernet0/3
We do this by quering `find_parents_w_child()`; we set our
parent as `^interface` and set the child as
`switchport access vlan 300`.
.. code-block:: python
:emphasize-lines: 18
>>> from ciscoconfparse import CiscoConfParse
>>> config = ['!',
... 'interface FastEthernet0/1',
... ' switchport access vlan 532',
... ' spanning-tree vlan 532 cost 3',
... '!',
... 'interface FastEthernet0/2',
... ' switchport access vlan 300',
... ' spanning-tree portfast',
... '!',
... 'interface FastEthernet0/3',
... ' duplex full',
... ' speed 100',
... ' switchport access vlan 300',
... ' spanning-tree portfast',
... '!',
... ]
>>> p = CiscoConfParse(config=config)
>>> p.find_parents_w_child('^interface', 'switchport access vlan 300')
['interface FastEthernet0/2', 'interface FastEthernet0/3']
>>>
"""
tmp = self.find_objects_w_child(
parentspec,
childspec,
ignore_ws=ignore_ws,
)
return [ii.text for ii in tmp]

# This method is on CiscoConfParse()
@ logger.catch(reraise=True)
def find_objects_wo_child(self, parentspec, childspec, ignore_ws=False, recurse=False):
Expand Down Expand Up @@ -2333,203 +2245,6 @@ def find_parent_objects_wo_child(self, parentspec, childspec, ignore_ws=False, r
if not obj.re_search_children(childspec, recurse=recurse)
]

# This method is on CiscoConfParse()
@ logger.catch(reraise=True)
def find_parents_wo_child(self, parentspec, childspec, ignore_ws=False):
r"""Parse through all parents matching parentspec, and return a list of parents that did NOT have children match the childspec. For simplicity, this method only finds oldest_ancestors without immediate children that match.
Parameters
----------
parentspec : str
Text regular expression for the line to be matched; this must match the parent's line
childspec : str
Text regular expression for the line to be matched; this must match the child's line
ignore_ws : bool
boolean that controls whether whitespace is ignored
Returns
-------
list
A list of matching parent configuration lines
Examples
--------
This example finds all ports that are autonegotiating in the
following config...
.. code::
!
interface FastEthernet0/1
switchport access vlan 532
spanning-tree vlan 532 cost 3
!
interface FastEthernet0/2
switchport access vlan 300
spanning-tree portfast
!
interface FastEthernet0/2
duplex full
speed 100
switchport access vlan 300
spanning-tree portfast
!
The following interfaces should be returned:
.. code::
interface FastEthernet0/1
interface FastEthernet0/2
We do this by quering `find_parents_wo_child()`; we set our
parent as `^interface` and set the child as `speed\s\d+` (a
regular-expression which matches the word 'speed' followed by
an integer).
.. code-block:: python
:emphasize-lines: 19
>>> from ciscoconfparse import CiscoConfParse
>>> config = ['!',
... 'interface FastEthernet0/1',
... ' switchport access vlan 532',
... ' spanning-tree vlan 532 cost 3',
... '!',
... 'interface FastEthernet0/2',
... ' switchport access vlan 300',
... ' spanning-tree portfast',
... '!',
... 'interface FastEthernet0/3',
... ' duplex full',
... ' speed 100',
... ' switchport access vlan 300',
... ' spanning-tree portfast',
... '!',
... ]
>>> p = CiscoConfParse(config=config)
>>> p.find_parents_wo_child('^interface', 'speed\s\d+')
['interface FastEthernet0/1', 'interface FastEthernet0/2']
>>>
"""
tmp = self.find_parent_objects_wo_child(
parentspec,
childspec,
ignore_ws=ignore_ws,
)
return [ii.text for ii in tmp]

# This method is on CiscoConfParse()
@ logger.catch(reraise=True)
def find_children_w_parents(self, parentspec, childspec, ignore_ws=False):
r"""Parse through the children of all parents matching parentspec,
and return a list of children that matched the childspec.
Parameters
----------
parentspec : str
Text regular expression for the line to be matched; this must match the parent's line
childspec : str
Text regular expression for the line to be matched; this must match the child's line
ignore_ws : bool
boolean that controls whether whitespace is ignored
Returns
-------
list
A list of matching child configuration lines
Examples
--------
This example finds the port-security lines on FastEthernet0/1 in
following config...
.. code::
!
interface FastEthernet0/1
switchport access vlan 532
switchport port-security
switchport port-security violation protect
switchport port-security aging time 5
switchport port-security aging type inactivity
spanning-tree portfast
spanning-tree bpduguard enable
!
interface FastEthernet0/2
switchport access vlan 300
spanning-tree portfast
spanning-tree bpduguard enable
!
interface FastEthernet0/2
duplex full
speed 100
switchport access vlan 300
spanning-tree portfast
spanning-tree bpduguard enable
!
The following lines should be returned:
.. code::
switchport port-security
switchport port-security violation protect
switchport port-security aging time 5
switchport port-security aging type inactivity
We do this by quering `find_children_w_parents()`; we set our
parent as `^interface` and set the child as
`switchport port-security`.
.. code-block:: python
:emphasize-lines: 26
>>> from ciscoconfparse import CiscoConfParse
>>> config = ['!',
... 'interface FastEthernet0/1',
... ' switchport access vlan 532',
... ' switchport port-security',
... ' switchport port-security violation protect',
... ' switchport port-security aging time 5',
... ' switchport port-security aging type inactivity',
... ' spanning-tree portfast',
... ' spanning-tree bpduguard enable',
... '!',
... 'interface FastEthernet0/2',
... ' switchport access vlan 300',
... ' spanning-tree portfast',
... ' spanning-tree bpduguard enable',
... '!',
... 'interface FastEthernet0/3',
... ' duplex full',
... ' speed 100',
... ' switchport access vlan 300',
... ' spanning-tree portfast',
... ' spanning-tree bpduguard enable',
... '!',
... ]
>>> p = CiscoConfParse(config=config)
>>> p.find_children_w_parents('^interface\sFastEthernet0/1',
... 'port-security')
[' switchport port-security', ' switchport port-security violation protect', ' switchport port-security aging time 5', ' switchport port-security aging type inactivity']
>>>
"""
if ignore_ws:
parentspec = build_space_tolerant_regex(parentspec)
childspec = build_space_tolerant_regex(childspec)

retval = set()
childobjs = self._find_line_OBJ(childspec)
for child in childobjs:
parents = child.all_parents
for parent in parents:
if re.search(parentspec, parent.text):
retval.add(child)

return [ii.text for ii in sorted(retval)]

# This method is on CiscoConfParse()
@ logger.catch(reraise=True)
Expand Down Expand Up @@ -5139,11 +4854,6 @@ def parse_global_options():
diff = CiscoConfParse(config=opts.config).find_all_children(opts.arg1)
elif opts.method == "find_blocks":
diff = CiscoConfParse(config=opts.config).find_blocks(opts.arg1)
elif opts.method == "find_parents_w_child":
diff = CiscoConfParse(config=opts.config).find_parents_w_child(
opts.arg1,
opts.arg2,
)
elif opts.method == "find_parents_wo_child":
diff = CiscoConfParse(config=opts.config).find_parents_wo_child(
opts.arg1,
Expand Down
Loading

0 comments on commit a499c6e

Please sign in to comment.