1313"""
1414
1515import logging
16- import os
1716import re
1817import socket
1918
@@ -70,13 +69,14 @@ def __str__(self):
7069class NetdevKeeper :
7170 """Used to maintain information about the network device during the onboarding process."""
7271
73- def __init__ (self , onboarding_task , username = None , password = None ):
72+ def __init__ (self , onboarding_task , username = None , password = None , secret = None ):
7473 """Initialize the network device keeper instance and ensure the required configuration parameters are provided.
7574
7675 Args:
7776 onboarding_task (OnboardingTask): Task being processed
78- username (str): Device username (if unspecified, NAPALM_USERNAME environment variable will be used)
79- password (str): Device password (if unspecified, NAPALM_PASSWORD environment variable will be used)
77+ username (str): Device username (if unspecified, NAPALM_USERNAME settings variable will be used)
78+ password (str): Device password (if unspecified, NAPALM_PASSWORD settings variable will be used)
79+ secret (str): Device secret password (if unspecified, NAPALM_ARGS["secret"] settings variable will be used)
8080
8181 Raises:
8282 OnboardException('fail-config'):
@@ -92,8 +92,9 @@ def __init__(self, onboarding_task, username=None, password=None):
9292 self .serial_number = None
9393 self .mgmt_ifname = None
9494 self .mgmt_pflen = None
95- self .username = username or os .environ .get ("NAPALM_USERNAME" , None )
96- self .password = password or os .environ .get ("NAPALM_PASSWORD" , None )
95+ self .username = username or settings .NAPALM_USERNAME
96+ self .password = password or settings .NAPALM_PASSWORD
97+ self .secret = secret or settings .NAPALM_ARGS .get ("secret" , None )
9798
9899 def check_reachability (self ):
99100 """Ensure that the device at the mgmt-ipaddr provided is reachable.
@@ -129,6 +130,7 @@ def guess_netmiko_device_type(**kwargs):
129130 "host" : kwargs .get ("host" ),
130131 "username" : kwargs .get ("username" ),
131132 "password" : kwargs .get ("password" ),
133+ "secret" : kwargs .get ("secret" ),
132134 }
133135
134136 try :
@@ -159,7 +161,7 @@ def get_platform_slug(self):
159161 platform_slug = self .ot .platform .slug
160162 else :
161163 platform_slug = self .guess_netmiko_device_type (
162- host = self .ot .ip_address , username = self .username , password = self .password
164+ host = self .ot .ip_address , username = self .username , password = self .password , secret = self . secret ,
163165 )
164166
165167 logging .info ("PLATFORM NAME is %s" , platform_slug )
@@ -233,7 +235,15 @@ def get_required_info(
233235 )
234236
235237 driver = get_network_driver (driver_name )
236- dev = driver (hostname = mgmt_ipaddr , username = self .username , password = self .password , timeout = self .ot .timeout )
238+ optional_args = settings .NAPALM_ARGS .copy ()
239+ optional_args ["secret" ] = self .secret
240+ dev = driver (
241+ hostname = mgmt_ipaddr ,
242+ username = self .username ,
243+ password = self .password ,
244+ timeout = self .ot .timeout ,
245+ optional_args = optional_args ,
246+ )
237247
238248 dev .open ()
239249 logging .info ("COLLECT: device facts" )
@@ -265,16 +275,13 @@ def get_mgmt_info():
265275 return (if_name , if_addr_data ["prefix_length" ])
266276 return (default_mgmt_if , default_mgmt_pfxlen )
267277
268- mgmt_ifname , mgmt_pflen = get_mgmt_info ()
269-
270278 # retain the attributes that will be later used by NetBox processing.
271279
272280 self .hostname = facts ["hostname" ]
273281 self .vendor = facts ["vendor" ].title ()
274282 self .model = facts ["model" ].lower ()
275283 self .serial_number = facts ["serial_number" ]
276- self .mgmt_ifname = mgmt_ifname
277- self .mgmt_pflen = mgmt_pflen
284+ self .mgmt_ifname , self .mgmt_pflen = get_mgmt_info ()
278285
279286
280287# -----------------------------------------------------------------------------
0 commit comments