Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
Improve napalm-ios hostname handler
Browse files Browse the repository at this point in the history
  • Loading branch information
ktbyers committed Sep 29, 2017
1 parent eaaaec6 commit 02082e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions napalm_ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,10 @@ def compare_config(self):
# merge
cmd = 'show archive config incremental-diffs {} ignorecase'.format(new_file_full)
diff = self.device.send_command_expect(cmd)
if '% Invalid' not in diff:
if 'error code 5' in diff or 'returned error 5' in diff:
diff = "You have encountered the obscure 'error 5' message. This generally " \
"means you need to add an 'end' statement to the end of your merge changes."
elif '% Invalid' not in diff:
diff = self._normalize_merge_diff_incr(diff)
else:
cmd = 'more {}'.format(new_file_full)
Expand All @@ -374,17 +377,13 @@ def compare_config(self):

def _commit_hostname_handler(self, cmd):
"""Special handler for hostname change on commit operation."""
try:
current_prompt = self.device.find_prompt()
# Wait 12 seconds for output to come back (.2 * 60)
output = self.device.send_command_expect(cmd, delay_factor=.2, max_loops=60)
except IOError:
# Check if hostname change
if current_prompt == self.device.find_prompt():
raise
else:
self.device.set_base_prompt()
output = ''
current_prompt = self.device.find_prompt().strip()
terminating_char = current_prompt[-1]
pattern = r"[>#{}]\s*$".format(terminating_char)
# Look exclusively for trailing pattern that includes '#' and '>'
output = self.device.send_command_expect(cmd, expect_string=pattern)
# Reset base prompt in case hostname changed
self.device.set_base_prompt()
return output

def commit_config(self):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
napalm_base>=0.25.0
netmiko>=1.4.2
netmiko>=1.4.3

0 comments on commit 02082e0

Please sign in to comment.