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

Commit

Permalink
Add commit confirmed feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mirceaulinic committed Mar 15, 2017
1 parent 55750c6 commit 71383f1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion napalm_ios/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def _commit_hostname_handler(self, cmd):
output = ''
return output

def commit_config(self):
def commit_config(self, confirmed=0):
"""
If replacement operation, perform 'configure replace' for the entire config.
Expand All @@ -354,6 +354,8 @@ def commit_config(self):
raise ReplaceConfigException("Candidate config file does not exist")
if self.auto_rollback_on_error:
cmd = 'configure replace {} force revert trigger error'.format(cfg_file)
elif confirmed:
cmd = 'configure replace {} force time {}'.format(cfg_file, confirmed)
else:
cmd = 'configure replace {} force'.format(cfg_file)
output = self._commit_hostname_handler(cmd)
Expand All @@ -372,6 +374,13 @@ def commit_config(self):
cmd = 'copy {} running-config'.format(cfg_file)
self._disable_confirm()
output = self._commit_hostname_handler(cmd)
if confirmed:
# Create the candidate config file
cmd = 'copy running-config {}'.format(self.candidate_cfg)
output += self.device.send_command_expect(cmd)
# Replace with the candidate and force rollback if not confirmed
cmd = 'configure replace {} force time {}'.format(self.candidate_cfg, confirmed)
output += self.device.send_command_expect(cmd)
self._enable_confirm()
if 'Invalid input detected' in output:
self.rollback()
Expand All @@ -381,6 +390,9 @@ def commit_config(self):
# Save config to startup (both replace and merge)
output += self.device.send_command_expect("write mem")

def commit_confirm(self):
output = self.device.send_command_expect('configure confirm')

def discard_config(self):
"""Set candidate_cfg to current running-config. Erase the merge_cfg file."""
discard_candidate = 'copy running-config {}'.format(self._gen_full_path(self.candidate_cfg))
Expand Down

0 comments on commit 71383f1

Please sign in to comment.