Skip to content

Commit 21fab76

Browse files
authored
Merge pull request #3711 from ktbyers/aruba_os_file_transfer2
Minor updates to Aruba OS file transfer
2 parents 5b4315f + e410615 commit 21fab76

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

netmiko/aruba/aruba_os.py

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ def __init__(
7171
)
7272

7373
def file_md5(self, file_name: str, add_newline: bool = False) -> str:
74-
msg = "Aruba OS does not support an MD5-hash operation."
75-
raise AttributeError(msg)
74+
"""Aruba OS does not support an MD5-hash operation."""
75+
raise NotImplementedError
7676

7777
@staticmethod
7878
def process_md5(md5_output: str, pattern: str = "") -> str:
79-
msg = "Aruba OS does not support an MD5-hash operation."
80-
raise AttributeError(msg)
79+
"""Aruba OS does not support an MD5-hash operation."""
80+
raise NotImplementedError
8181

8282
def compare_md5(self) -> bool:
83-
msg = "Aruba OS does not support an MD5-hash operation."
84-
raise AttributeError(msg)
83+
"""Aruba OS does not support an MD5-hash operation."""
84+
raise NotImplementedError
8585

8686
def remote_md5(self, base_cmd: str = "", remote_file: Optional[str] = None) -> str:
87-
msg = "Aruba OS does not support an MD5-hash operation."
88-
raise AttributeError(msg)
87+
"""Aruba OS does not support an MD5-hash operation."""
88+
raise NotImplementedError
8989

9090
def check_file_exists(self, remote_cmd: str = "") -> bool:
9191
"""Check if the dest_file already exists on the file system (return boolean)."""
@@ -97,11 +97,17 @@ def check_file_exists(self, remote_cmd: str = "") -> bool:
9797
if "Cannot get directory information" in remote_out:
9898
return False
9999

100+
# dir search default.cfg
101+
# -rw-r--r-- 1 root root 16283 Nov 9 12:25 default.cfg
102+
# -rw-r--r-- 1 root root 22927 May 25 12:21 default.cfg.2016-05-25_20-21-38
103+
# -rw-r--r-- 2 root root 19869 May 9 12:20 default.cfg.2016-05-09_12-20-22
104+
# Construct a list of the last column
100105
return self.dest_file in [
101-
split_line[-1]
106+
fields[-1]
102107
for line in remote_out.splitlines()
103-
if (split_line := line.split())
108+
if (fields := line.split())
104109
]
110+
105111
elif self.direction == "get":
106112
return os.path.exists(self.dest_file)
107113
else:
@@ -128,20 +134,24 @@ def remote_file_size(
128134
msg = "Unable to find file on remote system"
129135
raise IOError(msg)
130136

131-
file_size = [
132-
split_line[-5]
133-
for line in remote_out.splitlines()
134-
if (split_line := line.split()) and split_line[-1] == remote_file_search
135-
]
136-
137-
if len(file_size) != 1:
138-
msg = (
139-
"Unable to parse remote file size, found file count is not equal to one"
140-
)
137+
# dir search default.cfg
138+
# -rw-r--r-- 1 root root 16283 Nov 9 12:25 default.cfg
139+
# -rw-r--r-- 1 root root 22927 May 25 12:21 default.cfg.2016-05-25_20-21-38
140+
# -rw-r--r-- 2 root root 19869 May 9 12:20 default.cfg.2016-05-09_12-20-22
141+
for line in remote_out.splitlines():
142+
if line:
143+
fields = line.split()
144+
if len(fields) >= 5:
145+
file_size = fields[4]
146+
f_name = fields[-1]
147+
if f_name == remote_file_search:
148+
break
149+
else:
150+
msg = "Unable to find file on remote system"
141151
raise IOError(msg)
142152

143153
try:
144-
return int(file_size[0])
154+
return int(file_size)
145155
except ValueError as ve:
146156
msg = "Unable to parse remote file size, wrong field in use or malformed command output"
147157
raise IOError(msg) from ve
@@ -165,23 +175,26 @@ def remote_space_available(self, search_pattern: str = "") -> int:
165175
remote_cmd = "show storage"
166176
remote_output = self.ssh_ctl_chan._send_command_str(remote_cmd).strip()
167177

168-
# df -h ouput
178+
# show storage (df -h)
179+
# Filesystem Size Used Available Use% Mounted on
180+
# /dev/root 57.0M 54.6M 2.3M 96% /
181+
# /dev/usbdisk/1 3.9G 131.0M 3.8G 3% /mnt/usbdisk/1
169182
available_sizes = [
170-
split_line[-3]
183+
fields[-3]
171184
for line in remote_output.splitlines()
172-
if (split_line := line.split()) and split_line[-1] == "/flash"
185+
if (fields := line.split()) and fields[-1] == "/flash"
173186
]
174187

175188
if not available_sizes:
176189
msg = "Could not determine remote space available."
177190
raise ValueError(msg)
178191

179192
space_available = 0
180-
193+
# There is potentially more than one filesystem for /flash
181194
for available_size in available_sizes:
182-
size_names = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"]
183-
184-
size_str, suffix = available_size[:-1], available_size[-1]
195+
size_names = ["B", "K", "M", "G", "T", "P", "E"]
196+
suffix = available_size[-1]
197+
size_str = available_size[:-1]
185198

186199
if suffix not in size_names:
187200
msg = "Could not determine remote space available."
@@ -193,7 +206,7 @@ def remote_space_available(self, search_pattern: str = "") -> int:
193206
msg = "Could not determine remote space available."
194207
raise ValueError(msg) from ve
195208

196-
space_available += size * 1024 ** size_names.index(suffix)
209+
space_available += size * (1024 ** size_names.index(suffix))
197210

198211
return int(space_available)
199212

0 commit comments

Comments
 (0)