Skip to content

Commit b32cbf1

Browse files
committed
Credentials attribute in onboarding class
1 parent 1ed1277 commit b32cbf1

File tree

3 files changed

+9
-47
lines changed

3 files changed

+9
-47
lines changed

netbox_onboarding/netdev_keeper.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -107,46 +107,6 @@ def __init__( # pylint: disable=R0913
107107
# Enable loading driver extensions
108108
self.load_driver_extension = True
109109

110-
def check_ip(self):
111-
"""Method to check if the IP address form field was an IP address.
112-
113-
If it is a DNS name, attempt to resolve the DNS address and assign the IP address to the
114-
name.
115-
116-
Returns:
117-
(bool): True if the IP address is an IP address, or a DNS entry was found and
118-
reassignment of the ot.ip_address was done.
119-
False if unable to find a device IP (error)
120-
121-
Raises:
122-
OnboardException("fail-general"):
123-
When a prefix was entered for an IP address
124-
OnboardException("fail-dns"):
125-
When a Name lookup via DNS fails to resolve an IP address
126-
"""
127-
try:
128-
# Assign checked_ip to None for error handling
129-
# If successful, this is an IP address and can pass
130-
checked_ip = netaddr.IPAddress(self.hostname)
131-
return True
132-
# Catch when someone has put in a prefix address, raise an exception
133-
except ValueError:
134-
raise OnboardException(
135-
reason="fail-general", message=f"ERROR appears a prefix was entered: {self.hostname}"
136-
)
137-
# An AddrFormatError exception means that there is not an IP address in the field, and should continue on
138-
except AddrFormatError:
139-
try:
140-
# Do a lookup of name to get the IP address to connect to
141-
checked_ip = socket.gethostbyname(self.hostname)
142-
self.hostname = checked_ip
143-
return True
144-
except socket.gaierror:
145-
# DNS Lookup has failed, Raise an exception for unable to complete DNS lookup
146-
raise OnboardException(
147-
reason="fail-dns", message=f"ERROR failed to complete DNS lookup: {self.hostname}"
148-
)
149-
150110
def check_reachability(self):
151111
"""Ensure that the device at the mgmt-ipaddr provided is reachable.
152112

netbox_onboarding/onboard.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,20 @@ class OnboardingManager:
8787

8888
def __init__(self, ot, username, password, secret):
8989
"""Inits class."""
90-
self.username = username
91-
self.password = password
92-
self.secret = secret
93-
9490
# Create instance of Onboarding Task Manager class:
9591
otm = OnboardingTaskManager(ot)
9692

93+
self.username = username or settings.NAPALM_USERNAME
94+
self.password = password or settings.NAPALM_PASSWORD
95+
self.secret = secret or otm.optional_args.get("secret", None) or settings.NAPALM_ARGS.get("secret", None)
96+
9797
netdev = NetdevKeeper(
9898
hostname=otm.ip_address,
9999
port=otm.port,
100100
timeout=otm.timeout,
101-
username=self.username or settings.NAPALM_USERNAME,
102-
password=self.password or settings.NAPALM_PASSWORD,
103-
secret=self.secret or otm.optional_args.get("secret", None) or settings.NAPALM_ARGS.get("secret", None),
101+
username=self.username,
102+
password=self.password,
103+
secret=self.secret,
104104
napalm_driver=otm.napalm_driver,
105105
optional_args=otm.optional_args or settings.NAPALM_ARGS,
106106
)
@@ -129,6 +129,7 @@ def __init__(self, ot, username, password, secret):
129129
}
130130

131131
onboarding_cls = netdev_dict["onboarding_class"]()
132+
onboarding_cls.credentials = {"username": self.username, "password": self.password, "secret": self.secret}
132133
onboarding_cls.run(onboarding_kwargs=onboarding_kwargs)
133134

134135
self.created_device = onboarding_cls.created_device

netbox_onboarding/onboarding/onboarding.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Onboarding:
2121
def __init__(self):
2222
"""Init the class."""
2323
self.created_device = None
24+
self.credentials = None
2425

2526
def run(self, onboarding_kwargs):
2627
"""Implement run method."""

0 commit comments

Comments
 (0)