Skip to content

Commit 9d6d9d2

Browse files
author
renan.lopes
committed
logs finished
1 parent 5686762 commit 9d6d9d2

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

networkapi/plugins/Netconf/plugin.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ def __try_lock(self):
1616
"""
1717
return True
1818

19-
def connect(self) -> manager.connect:
19+
def connect(self):
2020
"""
2121
2222
Connects to equipment using NCClient to provide Netconf access
2323
2424
:raises:
2525
IOError: If can't connect to host
2626
Exception: to any other unhandled exceptions
27-
:return:
28-
NCClient connect object
27+
:return: None
2928
"""
3029

30+
log.info("Connection to equipment method started")
31+
3132
### If equipment access was not provided, then search the access ###
3233
if self.equipment_access is None:
3334
try:
35+
log.info("Searching for equipment access...")
3436
self.equipment_access = EquipamentoAcesso.search(
3537
None, self.equipment, 'netconf').uniqueResult()
3638
except Exception:
@@ -48,13 +50,15 @@ def connect(self) -> manager.connect:
4850

4951
### Runs connection ###
5052
try:
53+
log.info("Starting connection to '%s' using NCClient..." % device)
5154
self.session_manager = manager.connect(
5255
host = device,
5356
port = self.connection_port,
5457
username = username,
5558
password = password,
5659
hostkey_verify = False
5760
)
61+
log.info('Connection succesfully...')
5862

5963
### Exception handler
6064
except IOError, e:
@@ -65,11 +69,12 @@ def connect(self) -> manager.connect:
6569

6670
def apply_config_to_equipment(self, config, use_vrf=None, tarqet='running'):
6771

72+
log.info("Starting method to apply config on equipment... Config: '%s'" % config)
6873
try:
6974
if use_vrf is None:
7075
use_vrf = self.management_vrf
7176

72-
log.info("Config to apply: '%s'", % config)
77+
log.info("Config to apply: '%s'" % config)
7378

7479
response = self.connect.edit_config(tarqet=tarqet, config=config)
7580
log.info(response)
@@ -108,6 +113,7 @@ def copyScriptFileToConfig(self, filename, use_vrf='', destination=''):
108113
# 'filename' was defined in super class, but in plugin junos the 'file_path' will be used instead
109114
file_path = filename
110115
file_path = self.check_configuration_file_exists(file_path)
116+
log.info("Configuration for file '%s' is valid." % file_path)
111117

112118
try:
113119
command_file = open(file_path, "r")
@@ -135,10 +141,6 @@ def exec_command(self, command, success_regex='', invalid_regex=None, error_rege
135141

136142
try:
137143
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-
142144
with self.session_manager.locked(target='running'):
143145
self.session_manager.edit_config(target='running', config=command)
144146

@@ -159,10 +161,11 @@ def close(self):
159161
160162
:returns: True if success or raise an exception on any error
161163
"""
162-
164+
log.info("Close connection started...")
163165
try:
164166
if self.session_manager:
165167
self.session_manager.close_session()
168+
log.info('Connection closed successfully.')
166169
return True
167170

168171
else:

0 commit comments

Comments
 (0)