From 35bcca56a1db429a525085ad8707fb37ee7a6b9b Mon Sep 17 00:00:00 2001 From: anas-shami Date: Sun, 27 Oct 2019 11:42:11 +0200 Subject: [PATCH] Support discard uploaded file or loaded text function and add it to readme file --- README.md | 1 + napalm_onyx/onyx_ssh.py | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6b000b0..109bed5 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,4 @@ This driver initially targets the Mellanox device with Onyx OS though other, sim * get_lldp_neighbors * is_alive * cli +* discard_config diff --git a/napalm_onyx/onyx_ssh.py b/napalm_onyx/onyx_ssh.py index 5078c7a..6f64697 100644 --- a/napalm_onyx/onyx_ssh.py +++ b/napalm_onyx/onyx_ssh.py @@ -160,9 +160,9 @@ def close(self): self._delete_file(self.backup_file) self._netmiko_close() - def _send_command(self, command): + def _send_command(self, command, expect_string=None): """Wrapper for Netmiko's send_command method.""" - return self.device.send_command(command) + return self.device.send_command(command, expect_string=expect_string) @staticmethod def parse_uptime(uptime_str): @@ -399,21 +399,28 @@ def _load_cfg_from_checkpoint(self): elif rollback_result == []: raise ReplaceConfigException - def _delete_file(self, filename): - commands = [ - 'terminal dont-ask', - 'delete {}'.format(filename), - 'no terminal dont-ask' - ] - for command in commands: - self.device.send_command(command) + def _delete_file(self, filepath): + self.config_terminal() + filename = filepath.split('/')[-1] + command = "configuration text file {0} delete".format(filename) + expected_config_mode = r"\(config\)" + output = self._send_command(command, expect_string=expected_config_mode) + if output and "%" in output: + print(output) + return False + return True def discard_config(self): + """Delete the uploaded file from remote host.""" if self.loaded: self.merge_candidate = '' # clear the buffer + print('Flush candidate loaded data successfully') if self.loaded and self.replace: - self._delete_file(self.replace_file) + is_file_deleted = self._delete_file(self.replace_file) + if is_file_deleted: + print('Candidate uploaded file was deleted successfully') self.loaded = False + self.replace = False def rollback(self): if self.changed: