mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-18 04:56:29 -06:00
Moves location of the IP address / hostname check and assignment
This commit is contained in:
parent
cac48924ae
commit
ba8b99d3b8
@ -379,6 +379,22 @@ class DeviceViewSet(CustomFieldModelViewSet):
|
|||||||
device.platform
|
device.platform
|
||||||
))
|
))
|
||||||
|
|
||||||
|
# Check for primary IP address from NetBox object
|
||||||
|
if device.primary_ip:
|
||||||
|
host = str(device.primary_ip.address.ip)
|
||||||
|
else:
|
||||||
|
# Raise exception for no IP address and no Name if device.name does not exist
|
||||||
|
if not device.name:
|
||||||
|
raise ServiceUnavailable(
|
||||||
|
"This device does not have a primary IP address or device name to lookup configured.")
|
||||||
|
try:
|
||||||
|
# Attempt to complete a DNS name resolution if no primary_ip is set
|
||||||
|
host = socket.gethostbyname(device.name)
|
||||||
|
except socket.gaierror:
|
||||||
|
# Name lookup failure
|
||||||
|
raise ServiceUnavailable(
|
||||||
|
f"Name lookup failure, unable to resolve IP address for {device.name}. Please set Primary IP or setup name resolution.")
|
||||||
|
|
||||||
# Check that NAPALM is installed
|
# Check that NAPALM is installed
|
||||||
try:
|
try:
|
||||||
import napalm
|
import napalm
|
||||||
@ -398,20 +414,6 @@ class DeviceViewSet(CustomFieldModelViewSet):
|
|||||||
if not request.user.has_perm('dcim.napalm_read'):
|
if not request.user.has_perm('dcim.napalm_read'):
|
||||||
return HttpResponseForbidden()
|
return HttpResponseForbidden()
|
||||||
|
|
||||||
# Check for primary IP address from NetBox object
|
|
||||||
if device.primary_ip:
|
|
||||||
host = str(device.primary_ip.address.ip)
|
|
||||||
else:
|
|
||||||
# Raise exception for no IP address and no Name if device.name does not exist
|
|
||||||
if not device.name:
|
|
||||||
raise ServiceUnavailable("This device does not have a primary IP address or device name to lookup configured.")
|
|
||||||
try:
|
|
||||||
# Attempt to complete a DNS name resolution if no primary_ip is set
|
|
||||||
host = socket.gethostbyname(device.name)
|
|
||||||
except socket.gaierror:
|
|
||||||
# Name lookup failure
|
|
||||||
raise ServiceUnavailable(f"Name lookup failure, unable to resolve IP address for {device.name}. Please set Primary IP or setup name resolution.")
|
|
||||||
|
|
||||||
napalm_methods = request.GET.getlist('method')
|
napalm_methods = request.GET.getlist('method')
|
||||||
response = OrderedDict([(m, None) for m in napalm_methods])
|
response = OrderedDict([(m, None) for m in napalm_methods])
|
||||||
username = settings.NAPALM_USERNAME
|
username = settings.NAPALM_USERNAME
|
||||||
|
Loading…
Reference in New Issue
Block a user