-
Notifications
You must be signed in to change notification settings - Fork 40
Add commit confirmed feature #124
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
|
@@ -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 bootflash:{} force time {}'.format(cfg_file, confirmed) | ||
else: | ||
cmd = 'configure replace {} force'.format(cfg_file) | ||
output = self._commit_hostname_handler(cmd) | ||
|
@@ -369,15 +371,31 @@ def commit_config(self): | |
cfg_file = self._gen_full_path(filename) | ||
if not self._check_file_exists(cfg_file): | ||
raise MergeConfigException("Merge source config file does not exist") | ||
cmd = 'copy {} running-config'.format(cfg_file) | ||
self._disable_confirm() | ||
if confirmed: | ||
# Replace running config with the rollback config | ||
# And schedule the revert time | ||
# If not confirmed, it will go back to the current running-config state | ||
cmd = 'configure replace bootflash:{} force time {}'.format(self.rollback_cfg, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't hard-code file system. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably should ensure that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can probably copy it just before to be sure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about copy and then make sure no diffs (and throw an error if differences are found).
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that makes sense to me... didn't know about this command (as many other tricks I have discovered reading the code 😄 ). |
||
confirmed) | ||
output = self.device.send_command_expect(cmd) | ||
# The rest of the commands will be loaded directly through the normal | ||
# merge into the running-config | ||
cmd = 'copy {} running-config'.format(cfg_file) | ||
output = self._commit_hostname_handler(cmd) | ||
self._enable_confirm() | ||
if 'Invalid input detected' in output: | ||
self.rollback() | ||
merge_error = "Configuration merge failed; automatic rollback attempted" | ||
raise MergeConfigException(merge_error) | ||
|
||
if not confirmed: | ||
# Save config to startup (both replace and merge) | ||
output += self.device.send_command_expect("write mem") | ||
|
||
def commit_confirm(self): | ||
# Confirm replacement of running-config | ||
output = self.device.send_command_expect('configure confirm') | ||
# Save config to startup (both replace and merge) | ||
output += self.device.send_command_expect("write mem") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't hard-code the file system
bootflash
. Thecfg_file
variable already has the file_system which either gets auto detected or set by optional_args.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have hardcoded as I have noticed that it wasn't able to detect the file system and for this command it seems that is mandatory -- but I will double check this & fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Netmiko should automatically try to autodectect by doing a
dir
. If this fails, however, you can still set it using NAPALM optional_args.We should create an issue, however, if you are seeing this fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The autodetect happens right as part of the
open
code in the NAPALM code (IIRC).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most probably I missed something. I will check.