Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support discard uploaded file or loaded text function #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 18 additions & 11 deletions napalm_onyx/onyx_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was done in another commit
we'll have conflicts here.

Copy link
Contributor Author

@anas-shami anas-shami Oct 29, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that what I told u about its shared code that all of them will use

I use it here
self._send_command(command, expect_string=expected_config_mode)
if u want I can replace it with
self.device.send_command(command, expect_string=expect_string) #original one

"""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):
Expand Down Expand Up @@ -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:
Expand Down