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,10 +92,11 @@ 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
@@ -120,14 +130,25 @@ def guess_netmiko_device_type(self):
120130 """Guess the device type of host, based on Netmiko."""
121131 guessed_device_type = None
122132
133+ netmiko_optional_args = netmiko_args (self .optional_args )
134+
123135 remote_device = {
124136 "device_type" : "autodetect" ,
125137 "host" : self .hostname ,
126138 "username" : self .username ,
127139 "password" : self .password ,
128- "secret" : self . secret ,
140+ ** netmiko_optional_args ,
129141 }
130142
143+ if self .secret :
144+ remote_device ["secret" ] = self .secret
145+
146+ if self .port :
147+ remote_device ["port" ] = self .port
148+
149+ if self .timeout :
150+ remote_device ["timeout" ] = self .timeout
151+
131152 try :
132153 logger .info ("INFO guessing device type: %s" , self .hostname )
133154 guesser = SSHDetect (** remote_device )
@@ -201,8 +222,13 @@ def get_onboarding_facts(self):
201222 self .check_napalm_driver_name ()
202223
203224 driver = get_network_driver (self .napalm_driver )
204- optional_args = settings .NAPALM_ARGS .copy ()
205- optional_args ["secret" ] = self .secret
225+
226+ optional_args = self .optional_args .copy ()
227+ if self .port :
228+ optional_args ["port" ] = self .port
229+
230+ if self .secret :
231+ optional_args ["secret" ] = self .secret
206232
207233 napalm_device = driver (
208234 hostname = self .hostname ,
0 commit comments