Skip to content
This repository was archived by the owner on Feb 10, 2018. It is now read-only.

Commit

Permalink
Merge pull request #216 from ckishimo/devel-hop
Browse files Browse the repository at this point in the history
implement find operation in cli
  • Loading branch information
mirceaulinic authored Oct 24, 2017
2 parents 09cc86c + 1425d3b commit 9444206
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions napalm_junos/junos.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,17 @@ def _match(txt, pattern):
]
return '\n'.join(matched)

def _find(txt, pattern):
'''
Search for first occurrence of pattern.
'''
rgx = '^.*({pattern})(.*)$'.format(pattern=pattern)
match = re.search(rgx, txt, re.I | re.M | re.DOTALL)
if match:
return '{pattern}{rest}'.format(pattern=pattern, rest=match.group(2))
else:
return '\nPattern not found'

def _process_pipe(cmd, txt):
'''
Process CLI output from Juniper device that
Expand All @@ -768,6 +779,7 @@ def _process_pipe(cmd, txt):
_OF_MAP['last'] = _last
_OF_MAP['trim'] = _trim
_OF_MAP['count'] = _count
_OF_MAP['find'] = _find
# the operations order matter in this case!
exploded_cmd = cmd.split('|')
pipe_oper_args = {}
Expand Down

0 comments on commit 9444206

Please sign in to comment.