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

Projects
None yet
2 participants
@mirceaulinic
Copy link
Member

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 mirceaulinic:ciscoconfparse-mod branch from 44f92fc to e4d03b8 Jul 24, 2018

@rallytime
Copy link
Contributor

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

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 26, 2018

Contributor

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'):
'''

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 26, 2018

Contributor

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,

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 26, 2018

Contributor

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

This comment has been minimized.

Copy link
@mirceaulinic

mirceaulinic Jul 31, 2018

Author Member

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.

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 31, 2018

Contributor

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,

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 26, 2018

Contributor

Same comment here. Maybe find_child_lines?

return [line.text for line in lines]


def find_objects_wo_child(config=None,

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 26, 2018

Contributor

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,

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 26, 2018

Contributor

Same comment here: find_lines_no_child?



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

This comment has been minimized.

Copy link
@rallytime

rallytime Jul 26, 2018

Contributor

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.

This comment has been minimized.

Copy link
@mirceaulinic

mirceaulinic Jul 31, 2018

Author Member

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

continuous-integration/jenkins/pr-merge This commit cannot be built
Details
codeclimate 14 issues to fix
Details
jenkins/pr/py2-centos-7 The py2-centos-7 job has failed
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has failed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has failed
Details
WIP ready for review
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint The lint job has passed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has passed
Details

@mirceaulinic mirceaulinic deleted the mirceaulinic:ciscoconfparse-mod branch Aug 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.