-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from networktocode/develop-2.0
Release 2.0
- Loading branch information
Showing
39 changed files
with
2,320 additions
and
1,070 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
"""Example of custom onboarding class. | ||
(c) 2020 Network To Code | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
from netbox_onboarding.netbox_keeper import NetboxKeeper | ||
from netbox_onboarding.onboarding.onboarding import Onboarding | ||
|
||
|
||
class MyOnboardingClass(Onboarding): | ||
"""Custom onboarding class example. | ||
Main purpose of this class is to access and modify the onboarding_kwargs. | ||
By accessing the onboarding kwargs, user gains ability to modify | ||
onboarding parameters before the objects are created in NetBox. | ||
This class adds the get_device_role method that does the static | ||
string comparison and returns the device role. | ||
""" | ||
|
||
def run(self, onboarding_kwargs): | ||
"""Ensures network device.""" | ||
# Access hostname from onboarding_kwargs and get device role automatically | ||
device_new_role = self.get_device_role(hostname=onboarding_kwargs["netdev_hostname"]) | ||
|
||
# Update the device role in onboarding kwargs dictionary | ||
onboarding_kwargs["netdev_nb_role_slug"] = device_new_role | ||
|
||
nb_k = NetboxKeeper(**onboarding_kwargs) | ||
nb_k.ensure_device() | ||
|
||
self.created_device = nb_k.device | ||
|
||
@staticmethod | ||
def get_device_role(hostname): | ||
"""Returns the device role based on hostname data. | ||
This is a static analysis of hostname string content only | ||
""" | ||
hostname_lower = hostname.lower() | ||
if ("rtr" in hostname_lower) or ("router" in hostname_lower): | ||
role = "router" | ||
elif ("sw" in hostname_lower) or ("switch" in hostname_lower): | ||
role = "switch" | ||
elif ("fw" in hostname_lower) or ("firewall" in hostname_lower): | ||
role = "firewall" | ||
elif "dc" in hostname_lower: | ||
role = "datacenter" | ||
else: | ||
role = "generic" | ||
|
||
return role | ||
|
||
|
||
class OnboardingDriverExtensions: | ||
"""This is an example of a custom onboarding driver extension. | ||
This extension sets the onboarding_class to MyOnboardingClass, | ||
which is an example class of how to access and modify the device | ||
role automatically through the onboarding process. | ||
""" | ||
|
||
def __init__(self, napalm_device): | ||
"""Inits the class.""" | ||
self.napalm_device = napalm_device | ||
self.onboarding_class = MyOnboardingClass | ||
self.ext_result = None | ||
|
||
def get_onboarding_class(self): | ||
"""Return onboarding class for IOS driver. | ||
Currently supported is Standalone Onboarding Process | ||
Result of this method is used by the OnboardingManager to | ||
initiate the instance of the onboarding class. | ||
""" | ||
return self.onboarding_class | ||
|
||
def get_ext_result(self): | ||
"""This method is used to store any object as a return value. | ||
Result of this method is passed to the onboarding class as | ||
driver_addon_result argument. | ||
:return: Any() | ||
""" | ||
return self.ext_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# ntc-netbox-plugin-onboarding v2.0 Release Notes | ||
|
||
## v2.0 | ||
|
||
### Enhancements | ||
|
||
* NetBox 2.9 support - Supported releases 2.8 and 2.9 | ||
* Onboarding extensions - Customizable onboarding process through Python modules. | ||
* Onboarding details exposed in a device view - Date, Status, Last success and Latest task id related to the onboarded device are presented under the device view. | ||
* Onboarding task view - Onboarding details exposed in a dedicated view, including NetBox's ChangeLog. | ||
* Onboarding Changelog - Onboarding uses NetBox's ChangeLog to display user and changes made to the Onboarding Task object. | ||
* Skip onboarding feature - New attribute in the OnboardingDevice model allows to skip the onboarding request on devices with disabled onboarding setting. | ||
|
||
### Bug Fixes | ||
|
||
* Fixed race condition in `worker.py` | ||
* Improved logging | ||
|
||
### Additional Changes | ||
|
||
* Platform map now includes NAPALM drivers as defined in NetBox | ||
* Tests have been refactored to inherit NetBox's tests | ||
* Onboarding process will update the Device found by the IP-address lookup. In case of no existing device with onboarded IP-address is found in NetBox, onboarding might update the existing NetBox' looking up by network device's hostname. | ||
* Onboarding will raise Exception when `create_device_type_if_missing` is set to `False` for existing Device with DeviceType mismatch (behaviour pre https://github.com/networktocode/ntc-netbox-plugin-onboarding/issues/74) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,5 +32,5 @@ class OnboardingTaskAdmin(admin.ModelAdmin): | |
"failed_reason", | ||
"port", | ||
"timeout", | ||
"created_on", | ||
"created", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Exceptions. | ||
(c) 2020 Network To Code | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
|
||
|
||
class OnboardException(Exception): | ||
"""A failure occurred during the onboarding process. | ||
The exception includes a reason "slug" as defined below as well as a humanized message. | ||
""" | ||
|
||
REASONS = ( | ||
"fail-config", # config provided is not valid | ||
"fail-connect", # device is unreachable at IP:PORT | ||
"fail-execute", # unable to execute device/API command | ||
"fail-login", # bad username/password | ||
"fail-dns", # failed to get IP address from name resolution | ||
"fail-general", # other error | ||
) | ||
|
||
def __init__(self, reason, message, **kwargs): | ||
"""Exception Init.""" | ||
super(OnboardException, self).__init__(kwargs) | ||
self.reason = reason | ||
self.message = message | ||
|
||
def __str__(self): | ||
"""Exception __str__.""" | ||
return f"{self.__class__.__name__}: {self.reason}: {self.message}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Plugin additions to the NetBox navigation menu. | ||
(c) 2020 Network To Code | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
from prometheus_client import Counter | ||
|
||
onboardingtask_results_counter = Counter( | ||
name="onboardingtask_results_total", documentation="Count of results for Onboarding Task", labelnames=("status",) | ||
) |
Oops, something went wrong.