@@ -16,21 +16,23 @@ def __try_lock(self):
16
16
"""
17
17
return True
18
18
19
- def connect (self ) -> manager . connect :
19
+ def connect (self ):
20
20
"""
21
21
22
22
Connects to equipment using NCClient to provide Netconf access
23
23
24
24
:raises:
25
25
IOError: If can't connect to host
26
26
Exception: to any other unhandled exceptions
27
- :return:
28
- NCClient connect object
27
+ :return: None
29
28
"""
30
29
30
+ log .info ("Connection to equipment method started" )
31
+
31
32
### If equipment access was not provided, then search the access ###
32
33
if self .equipment_access is None :
33
34
try :
35
+ log .info ("Searching for equipment access..." )
34
36
self .equipment_access = EquipamentoAcesso .search (
35
37
None , self .equipment , 'netconf' ).uniqueResult ()
36
38
except Exception :
@@ -48,13 +50,15 @@ def connect(self) -> manager.connect:
48
50
49
51
### Runs connection ###
50
52
try :
53
+ log .info ("Starting connection to '%s' using NCClient..." % device )
51
54
self .session_manager = manager .connect (
52
55
host = device ,
53
56
port = self .connection_port ,
54
57
username = username ,
55
58
password = password ,
56
59
hostkey_verify = False
57
60
)
61
+ log .info ('Connection succesfully...' )
58
62
59
63
### Exception handler
60
64
except IOError , e :
@@ -65,11 +69,12 @@ def connect(self) -> manager.connect:
65
69
66
70
def apply_config_to_equipment (self , config , use_vrf = None , tarqet = 'running' ):
67
71
72
+ log .info ("Starting method to apply config on equipment... Config: '%s'" % config )
68
73
try :
69
74
if use_vrf is None :
70
75
use_vrf = self .management_vrf
71
76
72
- log .info ("Config to apply: '%s'" , % config )
77
+ log .info ("Config to apply: '%s'" % config )
73
78
74
79
response = self .connect .edit_config (tarqet = tarqet , config = config )
75
80
log .info (response )
@@ -108,6 +113,7 @@ def copyScriptFileToConfig(self, filename, use_vrf='', destination=''):
108
113
# 'filename' was defined in super class, but in plugin junos the 'file_path' will be used instead
109
114
file_path = filename
110
115
file_path = self .check_configuration_file_exists (file_path )
116
+ log .info ("Configuration for file '%s' is valid." % file_path )
111
117
112
118
try :
113
119
command_file = open (file_path , "r" )
@@ -135,10 +141,6 @@ def exec_command(self, command, success_regex='', invalid_regex=None, error_rege
135
141
136
142
try :
137
143
self .__try_lock () # Do nothing, will be executed by the locked method of ncclient
138
- # with self.connect() as connection:
139
- # with connection.locked(target='running'):
140
- # connection.edit_config(target='running', config=command)
141
-
142
144
with self .session_manager .locked (target = 'running' ):
143
145
self .session_manager .edit_config (target = 'running' , config = command )
144
146
@@ -159,10 +161,11 @@ def close(self):
159
161
160
162
:returns: True if success or raise an exception on any error
161
163
"""
162
-
164
+ log . info ( "Close connection started..." )
163
165
try :
164
166
if self .session_manager :
165
167
self .session_manager .close_session ()
168
+ log .info ('Connection closed successfully.' )
166
169
return True
167
170
168
171
else :
0 commit comments