Skip to content

Commit 9665016

Browse files
author
Josh VanDeraa
committed
Adds exception values
1 parent f8648d9 commit 9665016

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

netbox_onboarding/choices.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ class OnboardingFailChoices(ChoiceSet):
3939
FAIL_CONNECT = "fail-connect"
4040
FAIL_EXECUTE = "fail-execute"
4141
FAIL_GENERAL = "fail-general"
42+
FAIL_DNS = "fail-dns"
4243

4344
CHOICES = (
4445
(FAIL_LOGIN, "fail-login"),
4546
(FAIL_CONFIG, "fail-config"),
4647
(FAIL_CONNECT, "fail-connect"),
4748
(FAIL_EXECUTE, "fail-execute"),
4849
(FAIL_GENERAL, "fail-general"),
50+
(FAIL_DNS, "fail-dns"),
51+
()
4952
)

netbox_onboarding/onboard.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class OnboardException(Exception):
5050
"fail-connect", # device is unreachable at IP:PORT
5151
"fail-execute", # unable to execute device/API command
5252
"fail-login", # bad username/password
53+
"fail-dns", # failed to get IP address from name resolution
5354
"fail-general", # other error
5455
)
5556

@@ -211,6 +212,11 @@ def check_ip(self):
211212
reassignment of the ot.ip_address was done.
212213
False if unable to find a device IP (error)
213214
215+
Raises:
216+
OnboardException("fail-general"):
217+
When a prefix was entered for an IP address
218+
OnboardException("fail-dns"):
219+
When a Name lookup via DNS fails to resolve an IP address
214220
"""
215221
try:
216222
# Assign checked_ip to None for error handling
@@ -220,7 +226,7 @@ def check_ip(self):
220226
# Catch when someone has put in a prefix address, raise an exception
221227
except ValueError:
222228
raise OnboardException(
223-
reason="fail-prefix", message=f"ERROR appears a prefix was entered: {self.ot.ip_address}"
229+
reason="fail-general", message=f"ERROR appears a prefix was entered: {self.ot.ip_address}"
224230
)
225231
# An AddrFormatError exception means that there is not an IP address in the field, and should continue on
226232
except AddrFormatError:

0 commit comments

Comments
 (0)