Skip to content

Commit 758584d

Browse files
committed
v1.3.5 ConfigTools SSH/SCP Performance Improvements
1 parent ea01553 commit 758584d

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "BS1200_driver"
3-
version = "1.3.4"
3+
version = "1.3.5"
44
authors = [{ name = "Mikhail Kharitonov", email = "[email protected]"}]
55
description= "Python interface to the Bloomy BS1200"
66
readme = "README.md"

src/bs1200/cfg_tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def __init__(self, tgt: str, user: str, password : str):
1111
self.tgt_address = tgt
1212
self.username = user
1313
self.password = password
14-
14+
1515
def get_file(self, tgt_path, dest_path) -> str:
1616
try:
1717
with FTP(self.tgt_address, self.username, self.password) as f:
@@ -39,6 +39,7 @@ def __init__(self, tgt: str, user: str, password : str):
3939
self.tgt_address = tgt
4040
self.username = user
4141
self.password = password
42+
self.open()
4243

4344
def __enter__(self, *args, **kwargs):
4445
try:

src/bs1200/configuration.py

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,48 @@ def __init__(self, tgt_address, username= "admin", password= ""):
2020
self.user = username
2121
self.pwd = password
2222
self.FTP = FtpHelper(tgt_address, username, password)
23+
self.SCP = ScpHelper(tgt_address, username, password)
2324
self.ini_parser = ConfigParser()
25+
self.__9603 = False
2426

2527
def retrieve_file(self, tgt_file: str, dest: str):
26-
#First try the FTP, if this fails to connect use SCP
27-
try:
28-
local_copy = self.FTP.get_file(tgt_file, dest)
29-
except:
30-
#if error from FTP, use SCP via SSH
28+
if(self.__9603):
3129
#fix the path to ni-rt.ini if ni-rt linux is target
32-
print("Could not connect to target via FTP, using SCP")
3330
if("ni-rt.ini" in tgt_file):
34-
tgt_file = "/etc/natinst/share/ni-rt.ini"
35-
with ScpHelper(self.ip_address, self.user, self.pwd) as s:
36-
local_copy = s.get_file(tgt_file, dest)
37-
finally:
38-
return local_copy
31+
tgt_file = "/etc/natinst/share/ni-rt.ini"
32+
local_copy = self.SCP.get_file(tgt_file, dest)
33+
else:
34+
#Try the FTP, if this fails to connect use SCP
35+
try:
36+
local_copy = self.FTP.get_file(tgt_file, dest)
37+
except:
38+
#if error from FTP, use SCP via SSH
39+
print("Could not connect to target via FTP, using SCP")
40+
self.__9603 = True
41+
if("ni-rt.ini" in tgt_file):
42+
tgt_file = "/etc/natinst/share/ni-rt.ini"
43+
local_copy = self.SCP.get_file(tgt_file, dest)
44+
45+
return local_copy
46+
3947

4048
def send_file(self, tgt, dest_path):
41-
#First try the FTP, if this fails to connect use SCP
42-
try:
43-
self.FTP.upload_file(tgt, dest_path)
44-
except:
45-
#if error from FTP, use SCP via SSH
49+
if(self.__9603):
4650
#fix the path to ni-rt.ini if ni-rt linux is target
47-
if("ni-rt.ini" in dest_path):
48-
dest_path = "/etc/natinst/share/ni-rt.ini"
49-
with ScpHelper(self.ip_address, self.user, self.pwd) as s:
50-
s.upload_file(tgt, dest_path)
51+
if("ni-rt.ini" in dest_path):
52+
dest_path = "/etc/natinst/share/ni-rt.ini"
53+
self.SCP.upload_file(tgt, dest_path)
54+
else:
55+
#Try the FTP, if this fails to connect use SCP
56+
try:
57+
self.FTP.upload_file(tgt, dest_path)
58+
except:
59+
#if error from FTP, use SCP via SSH
60+
self.__9603 = True
61+
#fix the path to ni-rt.ini if ni-rt linux is target
62+
if("ni-rt.ini" in dest_path):
63+
dest_path = "/etc/natinst/share/ni-rt.ini"
64+
self.SCP.upload_file(tgt, dest_path)
5165

5266
def apply_config_file(self, cfg_file_path, restart: bool = True):
5367
"""
@@ -428,6 +442,10 @@ def __restart_unit(self):
428442
"""
429443
Use nisyscfg library to restart the target unit
430444
"""
445+
#need to close SCP helper before restarting so socket isnt force closed
446+
if(self.__9603):
447+
#print("Closing SCP connection")
448+
self.SCP.close()
431449
#open a nisyscfg session to the BS1200 to restart it
432450
with nisyscfg.Session(self.ip_address, self.user, self.pwd) as s:
433451
#updates IP address for the ConfigTools instance to the new IP address once restart complete
@@ -442,6 +460,11 @@ def __restart_unit(self):
442460
self.FTP.tgt_address = self.ip_address
443461
sys.stdout.flush()
444462
print("\r\n"+f"BS1200 at {self.ip_address} is back online")
463+
sys.stdout.flush()
464+
print("\n")
465+
if(self.__9603):
466+
#print("Reopening SCP connection")
467+
self.SCP.open()
445468

446469
def __animate(self, loadingtext: str):
447470
"""Animation loop for the restart wait"""

0 commit comments

Comments
 (0)