Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds utility functions for ios parser #139

Closed
wants to merge 109 commits into from
Closed

Adds utility functions for ios parser #139

wants to merge 109 commits into from

Conversation

mundruid
Copy link
Contributor

@mundruid mundruid commented Aug 2, 2022

Adds:

  • get_path
  • get_path_with_children

Addresses partially issue: #124

ubajze and others added 30 commits May 12, 2021 15:57
Move to constants, fix doctest, make dns actions more clear, clean up wording to be more clear
* Add ASA parser

Co-authored-by: Justin Drew <[email protected]>
* Add BASE_INTERFACES for hp_comware & checkpoint

Co-authored-by: Josef Fuchs <[email protected]>
Adds docs for readthedocs
Updated attribution and contribution doc start-lines
move sphinx to dev dep, update docs, update metadata
* Small performance enhancers

- remove redundant call to `str`
- `get_all_host` list to generator to avoid memory overhead of very
large lists

* Add lookup table for netmasks

There are only 32 + 128 valid IPv4/6 netmasks, so I created a lookup
table for easy validation.  If there are concerns about the memory
overhead, a computed version is easy enough to implement.

* Make netutils dual-stack

I modified functions where I could to make them compatible with IPv6.
Per [RFC4291](https://datatracker.ietf.org/doc/html/rfc4291#section-4),
I have assumed any addresses in the ::/8 range are IPv4.
The one exception is `cidr_to_netmask`.  I added a v6 version of that
function.

* Modify/add tests for proposed functionality
* remove count_bits tests

* Remove count_bits in favor of simpler/faster function
* interface_range_expansion function added
Co-authored-by: Adam Byczkowski <[email protected]>
Co-authored-by: Adam Byczkowski <[email protected]>
Add interface sorting support.
jeffkala and others added 9 commits April 23, 2022 11:41
* Updated lib mapping docs

* Updated per review suggestions
Update banner parsing for EOS
* fixes encrypt type7
* initial pass at type hinting and getting mypy to run

* update tasks and ci to do mypy as well

* rm unused import

* fix contributing end-line number

* fix contributing end-line number

* Add py.typed file to signify availability of type hints to third parties.

* Updates to type hinting.

* Add EOS _build_banner type hints.

* Address feedback.

* Linting.

* Remove .idea from commit and ignore in .gitignore.

* Remove remnants of merge conflict.

* PR feedback.

* PR comments.

* Ignore pylint errors for abstract-method.

* Black.

* add examples and better exception messaging

Co-authored-by: Leo Kirchner <[email protected]>
@itdependsnetworks
Copy link
Contributor

Nice!! Two thoughts

  • Can you move to BaseSpaceConfigParser, this "should" be the same for all configs that inherit from BaseSpaceConfigParser
  • Does it make sense to use the language that CiscoConfParse uses? This would be helpful for training/documentation, which seems to define:
find_all_children
find_blocks
find_children
find_children_w_parents
find_interface_objects
find_lineage
find_lines
find_object_branches
find_objects
find_objects_dna
find_objects_w_all_children
find_objects_w_child
find_objects_w_missing_children
find_objects_w_parents
find_objects_wo_child
find_parents_w_child
find_parents_wo_child

We could use "get" instead of find potentially, worth a convo at a min.

neighbor 192.168.1.2 activate
network 172.17.1.0 mas
"""
children = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think method could be solved with [a.config_line for a in config_tree.build_config_relationship() if a.parents and a.parents[0] == pattern]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you are suggesting does not return anything, it returns an empty list.

neighbor 192.168.1.2 activate
network 172.17.1.0 mas
"""
parents_and_children = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method can be handled with [a.config_line for a in config_tree.build_config_relationship() if a.parents and a.parents[0] == pattern or a.config_line == pattern]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you are suggesting does not return anything, it returns an empty list.

@@ -72,7 +72,7 @@ def test_sphinx_build(data):
sphinx_dummy_build = subprocess.run( # pylint: disable=W1510
["sphinx-build", "-b", "dummy", "-W", data["source_dir"], data["build_dir"]], stdout=subprocess.PIPE
)
assert sphinx_dummy_build.returncode == 0
assert sphinx_dummy_build.returncode == 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why docs are failing, but shouldn't expect a non-zero return code (unless testing for specific failure)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed based on the suggestion, the test works now.

Comment on lines +611 to +616
Example:
root_obj.get_path("router bgp 45000")
# Returns
address-family ipv4 unicast
neighbor 192.168.1.2 activate
network 172.17.1.0 mas
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Example:
root_obj.get_path("router bgp 45000")
# Returns
address-family ipv4 unicast
neighbor 192.168.1.2 activate
network 172.17.1.0 mas
Example:
>>> config = '''
... router bgp 45000
... address-family ipv4 unicast
... neighbor 192.168.1.2 activate
... network 172.17.1.0 mas'''
>>> bgp_conf = IOSConfigParser.get_path(config)
>>> print(bgp_conf)
address-family ipv4 unicast
neighbor 192.168.1.2 activate
network 172.17.1.0 mas

Sphinx doesn't like the indentation in the docstring here and the function below. The suggestion should be good though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed based on the suggestion, the test works now.

"""Returns configuration part for specific pattern not including parents.

Args:
pattern (str): pattern that describes for parent.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this full library is type hinted we no longer need to provide the "types" within the docstrings.

Suggested change
pattern (str): pattern that describes for parent.
pattern: pattern that describes for parent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

pattern (str): pattern that describes for parent.

Returns:
list: configuration under that parent pattern.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
list: configuration under that parent pattern.
configuration under that parent pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

"""Returns configuration part for specific pattern including parents and children.

Args:
pattern (str): pattern that describes for parent.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pattern (str): pattern that describes for parent.
pattern: pattern that describes for parent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

pattern (str): pattern that describes for parent.

Returns:
list: configuration under that parent pattern.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
list: configuration under that parent pattern.
configuration under that parent pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

return grouped_data

def get_path(self, pattern: str) -> t.List[str]:
"""Returns configuration part for specific pattern not including parents.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Returns configuration part for specific pattern not including parents.
"""Returns child configurations for a specific pattern not including parents.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

return children

def get_path_with_parents(self, pattern: str) -> t.List[str]:
"""Returns configuration part for specific pattern including parents and children.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Returns configuration part for specific pattern including parents and children.
"""Returns configuration section for a specific pattern including parents and children.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

@jeffkala
Copy link
Collaborator

jeffkala commented Aug 3, 2022

Something seemed to happen with this PR, showing 182 filles changed.

@mundruid
Copy link
Contributor Author

mundruid commented Aug 3, 2022

Overlaps with #140

@mundruid mundruid closed this Aug 3, 2022
@mundruid mundruid deleted the x/get_certificate branch August 4, 2022 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.