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

Add ciscoconfparse execution module for various text config mainipulations #48733

Merged
merged 5 commits into from Jul 31, 2018

Conversation

@mirceaulinic
Copy link
Member

@mirceaulinic mirceaulinic commented Jul 24, 2018

Adding a simple execution module for various text manipulation when working with configuration style formatted according to a very poor "industry standard" Cisco IOS (space based hierarchy), but not limited to.

This helps identifying individual lines having a specific pattern, or if their children have a given pattern as well.

This can have unlimited use cases, and can be equally helpful from the command line, e.g., identify what interfaces are administratively shut down: salt <net device> napalm.config_lines_w_child '^interface' '^\s?shutdown', as well as parsing various chunks of configuration from a Jinja template, etc.

The functions added to the napalm module are helpers to easier access the ciscoconfparse features applying directly on the running / startup / candidate config as preferred.

Also updating the autodoc for the napalm module (which I have renamed yesterday from napalm.py to napalm_mod.py: #48707, but forgot to update the RST build).

@mirceaulinic mirceaulinic force-pushed the ciscoconfparse-mod branch from 44f92fc to e4d03b8 Jul 24, 2018
Copy link
Contributor

@rallytime rallytime left a comment

I like this in general, but I think some of the function names could be a little more direct. Let me know what you think.



def __virtual__():
return HAS_CISCOCONFPARSE
Copy link
Contributor

@rallytime rallytime Jul 26, 2018

Might be good to give the reason (missing dependency) if this virtual check fails, like we do in other modules.



def _get_ccp(config=None, config_path=None, saltenv='base'):
'''
Copy link
Contributor

@rallytime rallytime Jul 26, 2018

Did you mean to add some docs here? I think that would be good. :)

return [line.text for line in lines]


def find_objects_w_child(config=None,
Copy link
Contributor

@rallytime rallytime Jul 26, 2018

Maybe find_child_objects? I think this function name is a bit awkward as it sits currently.

Copy link
Member Author

@mirceaulinic mirceaulinic Jul 31, 2018

I used this name to preserve the nomenclature of the underlying library, e.g., http://www.pennington.net/py/ciscoconfparse/tutorial_parent_child.html#method-3-find-objects-w-child
I agree that name is a bit awkward, but I'm happy to change it as suggested. I'll let you reply with your thoughts given my reasoning above, then I can update if necessary.

Copy link
Contributor

@rallytime rallytime Jul 31, 2018

Ah, OK. If that's the way people are used to using these, then that is fine.

return lines


def find_lines_w_child(config=None,
Copy link
Contributor

@rallytime rallytime Jul 26, 2018

Same comment here. Maybe find_child_lines?

return [line.text for line in lines]


def find_objects_wo_child(config=None,
Copy link
Contributor

@rallytime rallytime Jul 26, 2018

What about find_objects_no_child? I'm not sure if that's better, but I think the wo is a tad confusing.

return lines


def find_lines_wo_child(config=None,
Copy link
Contributor

@rallytime rallytime Jul 26, 2018

Same comment here: find_lines_no_child?



@depends(HAS_CISCOCONFPARSE)
def config_lines_w_child(parent_regex, child_regex, source='running'):
Copy link
Contributor

@rallytime rallytime Jul 26, 2018

I think the functions in this file could use some new names as well, just like above. I won't comment on each one though, you get the idea.

Copy link
Member Author

@mirceaulinic mirceaulinic Jul 31, 2018

Please see #48733 (comment) for my reasoning - happy to update if you think that's best - no problem at all!

@rallytime rallytime merged commit 232db0a into saltstack:develop Jul 31, 2018
4 of 9 checks passed
@mirceaulinic mirceaulinic deleted the ciscoconfparse-mod branch Aug 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants