@@ -20,34 +20,48 @@ def __init__(self, tgt_address, username= "admin", password= ""):
20
20
self .user = username
21
21
self .pwd = password
22
22
self .FTP = FtpHelper (tgt_address , username , password )
23
+ self .SCP = ScpHelper (tgt_address , username , password )
23
24
self .ini_parser = ConfigParser ()
25
+ self .__9603 = False
24
26
25
27
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 ):
31
29
#fix the path to ni-rt.ini if ni-rt linux is target
32
- print ("Could not connect to target via FTP, using SCP" )
33
30
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
+
39
47
40
48
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 ):
46
50
#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 )
51
65
52
66
def apply_config_file (self , cfg_file_path , restart : bool = True ):
53
67
"""
@@ -428,6 +442,10 @@ def __restart_unit(self):
428
442
"""
429
443
Use nisyscfg library to restart the target unit
430
444
"""
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 ()
431
449
#open a nisyscfg session to the BS1200 to restart it
432
450
with nisyscfg .Session (self .ip_address , self .user , self .pwd ) as s :
433
451
#updates IP address for the ConfigTools instance to the new IP address once restart complete
@@ -442,6 +460,11 @@ def __restart_unit(self):
442
460
self .FTP .tgt_address = self .ip_address
443
461
sys .stdout .flush ()
444
462
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 ()
445
468
446
469
def __animate (self , loadingtext : str ):
447
470
"""Animation loop for the restart wait"""
0 commit comments