@@ -35,10 +35,12 @@ def napalm(self, request, pk):
3535 )
3636 if device .platform is None :
3737 raise ServiceUnavailable ("No platform is configured for this device." )
38- if (
39- not hasattr (device .platform , "napalm" )
40- or not device .platform .napalm .napalm_driver
41- ):
38+ # Checks to see if NapalmPlatform object exists
39+ if not NapalmPlatformConfig .objects .filter (platform = device .platform ).exists ():
40+ raise ServiceUnavailable (
41+ f"No NAPALM Platform Mapping is configured for this device's platform: { device .platform } ."
42+ )
43+ if NapalmPlatformConfig .objects .get (platform = device .platform ).napalm_driver == "" :
4244 raise ServiceUnavailable (
4345 f"No NAPALM driver is configured for this device's platform: { device .platform } ."
4446 )
@@ -75,11 +77,11 @@ def napalm(self, request, pk):
7577
7678 # Validate the configured driver
7779 try :
78- driver = napalm .get_network_driver (device .platform .napalm_driver )
80+ driver = napalm .get_network_driver (NapalmPlatformConfig . objects . get ( platform = device .platform ) .napalm_driver )
7981 except ModuleImportError :
8082 raise ServiceUnavailable (
8183 "NAPALM driver for platform {} not found: {}." .format (
82- device .platform , device .platform .napalm_driver
84+ device .platform , NapalmPlatformConfig . objects . get ( platform = device .platform ) .napalm_driver
8385 )
8486 )
8587
@@ -94,9 +96,8 @@ def napalm(self, request, pk):
9496 password = get_plugin_config ('netbox_napalm_plugin' , 'NAPALM_PASSWORD' )
9597 timeout = get_plugin_config ('netbox_napalm_plugin' , 'NAPALM_TIMEOUT' )
9698 optional_args = get_plugin_config ('netbox_napalm_plugin' , 'NAPALM_ARGS' ).copy ()
97- if device .platform .napalm_args is not None :
98- optional_args .update (device .platform .napalm_args )
99-
99+ if NapalmPlatformConfig .objects .get (platform = device .platform ).napalm_args is not None :
100+ optional_args .update (NapalmPlatformConfig .objects .get (platform = device .platform ).napalm_args )
100101 # Update NAPALM parameters according to the request headers
101102 for header in request .headers :
102103 if header [:9 ].lower () != "x-napalm-" :
0 commit comments