1919from django .conf import settings
2020from napalm import get_network_driver
2121from napalm .base .exceptions import ConnectionException , CommandErrorException
22+ from napalm .base .netmiko_helpers import netmiko_args
2223from netmiko .ssh_autodetect import SSHDetect
2324from netmiko .ssh_exception import NetMikoAuthenticationException
2425from netmiko .ssh_exception import NetMikoTimeoutException
@@ -62,7 +63,15 @@ class NetdevKeeper:
6263 """Used to maintain information about the network device during the onboarding process."""
6364
6465 def __init__ ( # pylint: disable=R0913
65- self , hostname , port = None , timeout = None , username = None , password = None , secret = None , napalm_driver = None
66+ self ,
67+ hostname ,
68+ port = None ,
69+ timeout = None ,
70+ username = None ,
71+ password = None ,
72+ secret = None ,
73+ napalm_driver = None ,
74+ optional_args = None ,
6675 ):
6776 """Initialize the network device keeper instance and ensure the required configuration parameters are provided.
6877
@@ -83,17 +92,21 @@ def __init__( # pylint: disable=R0913
8392 self .hostname = hostname
8493 self .port = port
8594 self .timeout = timeout
86- self .username = username or settings . NAPALM_USERNAME
87- self .password = password or settings . NAPALM_PASSWORD
88- self .secret = secret or settings . NAPALM_ARGS . get ( "secret" , None )
95+ self .username = username
96+ self .password = password
97+ self .secret = secret
8998 self .napalm_driver = napalm_driver
99+ self .optional_args = optional_args
90100
91101 self .facts = None
92102 self .ip_ifs = None
93103 self .netmiko_device_type = None
94104 self .onboarding_class = StandaloneOnboarding
95105 self .driver_addon_result = None
96106
107+ # Enable loading driver extensions
108+ self .load_driver_extension = True
109+
97110 def check_reachability (self ):
98111 """Ensure that the device at the mgmt-ipaddr provided is reachable.
99112
@@ -120,14 +133,25 @@ def guess_netmiko_device_type(self):
120133 """Guess the device type of host, based on Netmiko."""
121134 guessed_device_type = None
122135
136+ netmiko_optional_args = netmiko_args (self .optional_args )
137+
123138 remote_device = {
124139 "device_type" : "autodetect" ,
125140 "host" : self .hostname ,
126141 "username" : self .username ,
127142 "password" : self .password ,
128- "secret" : self . secret ,
143+ ** netmiko_optional_args ,
129144 }
130145
146+ if self .secret :
147+ remote_device ["secret" ] = self .secret
148+
149+ if self .port :
150+ remote_device ["port" ] = self .port
151+
152+ if self .timeout :
153+ remote_device ["timeout" ] = self .timeout
154+
131155 try :
132156 logger .info ("INFO guessing device type: %s" , self .hostname )
133157 guesser = SSHDetect (** remote_device )
@@ -201,8 +225,13 @@ def get_onboarding_facts(self):
201225 self .check_napalm_driver_name ()
202226
203227 driver = get_network_driver (self .napalm_driver )
204- optional_args = settings .NAPALM_ARGS .copy ()
205- optional_args ["secret" ] = self .secret
228+
229+ optional_args = self .optional_args .copy ()
230+ if self .port :
231+ optional_args ["port" ] = self .port
232+
233+ if self .secret :
234+ optional_args ["secret" ] = self .secret
206235
207236 napalm_device = driver (
208237 hostname = self .hostname ,
@@ -222,7 +251,7 @@ def get_onboarding_facts(self):
222251
223252 module_name = PLUGIN_SETTINGS ["onboarding_extensions_map" ].get (self .napalm_driver )
224253
225- if module_name :
254+ if module_name and self . load_driver_extension :
226255 try :
227256 module = importlib .import_module (module_name )
228257 driver_addon_class = module .OnboardingDriverExtensions (napalm_device = napalm_device )
0 commit comments