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

nokia_sros: Add support for md-cli only mode #3496

Merged
merged 1 commit into from
Sep 17, 2024
Merged
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
15 changes: 7 additions & 8 deletions netmiko/nokia/nokia_sros.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,12 @@ def __init__(
hash_supported=hash_supported,
)

def _file_cmd_prefix(self) -> str:
def _file_list_command(self) -> str:
"""
Allow MD-CLI to execute file operations by using classical CLI.
return the md-cli command in mdcli mode, otherwise classic

Returns "//" if the current prompt is MD-CLI (empty string otherwise).
"""
return "//" if "@" in self.ssh_ctl_chan.base_prompt else ""
return "file list " if "@" in self.ssh_ctl_chan.base_prompt else "file dir "

def remote_space_available(
self, search_pattern: str = r"(\d+)\s+\w+\s+free"
Expand All @@ -315,7 +314,7 @@ def remote_space_available(

# Sample text for search_pattern.
# " 3 Dir(s) 961531904 bytes free."
remote_cmd = self._file_cmd_prefix() + "file dir {}".format(self.file_system)
remote_cmd = self._file_list_command() + "{}".format(self.file_system)
remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd)
match = re.search(search_pattern, remote_output)
assert match is not None
Expand All @@ -326,7 +325,7 @@ def check_file_exists(self, remote_cmd: str = "") -> bool:

if self.direction == "put":
if not remote_cmd:
remote_cmd = self._file_cmd_prefix() + "file dir {}/{}".format(
remote_cmd = self._file_list_command() + "{}/{}".format(
self.file_system, self.dest_file
)
dest_file_name = self.dest_file.replace("\\", "/").split("/")[-1]
Expand Down Expand Up @@ -355,12 +354,12 @@ def remote_file_size(
else:
raise ValueError("Unexpected value for self.direction")
if not remote_cmd:
remote_cmd = self._file_cmd_prefix() + "file dir {}/{}".format(
remote_cmd = self._file_list_command() + "{}/{}".format(
self.file_system, remote_file
)
remote_out = self.ssh_ctl_chan._send_command_str(remote_cmd)

if "File Not Found" in remote_out:
if "File Not Found" in remote_out or "Invalid element value" in remote_out:
raise IOError("Unable to find file on remote system")

dest_file_name = remote_file.replace("\\", "/").split("/")[-1]
Expand Down