From d053df4406ce8695a7bd96f3e55b10d5e2176e01 Mon Sep 17 00:00:00 2001 From: jeremypng <23668453+jeremypng@users.noreply.github.com> Date: Mon, 27 Jul 2020 14:55:06 -0500 Subject: [PATCH 1/6] Issue 63 - pass secret to NetdevKeeper --- netbox_onboarding/worker.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/netbox_onboarding/worker.py b/netbox_onboarding/worker.py index bf0b1a1..c26cfa8 100644 --- a/netbox_onboarding/worker.py +++ b/netbox_onboarding/worker.py @@ -29,6 +29,7 @@ def onboard_device(task_id, credentials): """Process a single OnboardingTask instance.""" username = credentials.username password = credentials.password + secret = credentials.secret try: ot = OnboardingTask.objects.get(id=task_id) @@ -43,7 +44,7 @@ def onboard_device(task_id, credentials): ot.status = OnboardingStatusChoices.STATUS_RUNNING ot.save() - netdev = NetdevKeeper(ot, username, password) + netdev = NetdevKeeper(ot, username, password, secret) nbk = NetboxKeeper(netdev=netdev) netdev.get_required_info() From 98190433ee6e9f90991bc068dcb28d90fc10fa72 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Wed, 29 Jul 2020 16:31:31 -0400 Subject: [PATCH 2/6] Fixes #74 --- netbox_onboarding/onboard.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/netbox_onboarding/onboard.py b/netbox_onboarding/onboard.py index d646af1..b436120 100644 --- a/netbox_onboarding/onboard.py +++ b/netbox_onboarding/onboard.py @@ -552,10 +552,22 @@ def ensure_primary_ip(self): self.device.primary_ip4 = self.primary_ip self.device.save() + def check_if_device_already_exist(self): + """Check if a device with the same name / site already exist in the database.""" + try: + Device.objects.get(name=self.netdev.hostname, site=self.netdev.ot.site) + return True + except Device.DoesNotExist: + return False + def ensure_device(self): """Ensure that the device represented by the DevNetKeeper exists in the NetBox system.""" - self.ensure_device_type() - self.ensure_device_role() + + # Only check the device role and device type if the device do not exist already + if not self.check_if_device_already_exist(): + self.ensure_device_type() + self.ensure_device_role() + self.ensure_device_instance() if PLUGIN_SETTINGS["create_management_interface_if_missing"]: self.ensure_interface() From 5890b02b2601b92853b3c157ac5720b0a7ad11de Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Wed, 29 Jul 2020 16:37:14 -0400 Subject: [PATCH 3/6] Update FAQ regarding webhooks limitation --- FAQ.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/FAQ.md b/FAQ.md index 7a9c5e6..9bbcb4b 100644 --- a/FAQ.md +++ b/FAQ.md @@ -46,4 +46,8 @@ > **No**, The plugin is leveraging the existing RQ Worker infrastructure already in place in NetBox, the only requirement is to ensure the plugin itself is installed in the Worker node. +## Why don't I see a webhook generated when a new device is onboarded successfully ? + +> It's expected that any changes done asynchronously in NetBox currently (within a worker) will not generate a webhook. + From 8253eade2a3f61c858608835fcaa7d2f11671a4f Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Wed, 29 Jul 2020 17:47:35 -0400 Subject: [PATCH 4/6] Fix for Netbox issue 4910 --- development/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/development/Dockerfile b/development/Dockerfile index 4bdd11f..602937d 100644 --- a/development/Dockerfile +++ b/development/Dockerfile @@ -13,8 +13,11 @@ RUN pip install --upgrade pip\ # ------------------------------------------------------------------------------------- # Install NetBox # ------------------------------------------------------------------------------------- +# Remove redis==3.4.1 from the requirements.txt file as a workaround to #4910 +# https://github.com/netbox-community/netbox/issues/4910, required for version 2.8.8 and earlier RUN git clone --single-branch --branch ${netbox_ver} https://github.com/netbox-community/netbox.git /opt/netbox/ && \ cd /opt/netbox/ && \ + sed -i '/^redis\=\=/d' /opt/netbox/requirements.txt && \ pip install -r /opt/netbox/requirements.txt # Make the django-debug-toolbar always visible when DEBUG is enabled, From 0b8aac045f21c365b510eec259cbb0091f72f357 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Wed, 29 Jul 2020 17:53:29 -0400 Subject: [PATCH 5/6] Fix pydocstyle --- netbox_onboarding/onboard.py | 1 - 1 file changed, 1 deletion(-) diff --git a/netbox_onboarding/onboard.py b/netbox_onboarding/onboard.py index b436120..fe63c2a 100644 --- a/netbox_onboarding/onboard.py +++ b/netbox_onboarding/onboard.py @@ -562,7 +562,6 @@ def check_if_device_already_exist(self): def ensure_device(self): """Ensure that the device represented by the DevNetKeeper exists in the NetBox system.""" - # Only check the device role and device type if the device do not exist already if not self.check_if_device_already_exist(): self.ensure_device_type() From d51bdb918592b24baacb00073e3f075d03a8c215 Mon Sep 17 00:00:00 2001 From: Damien Garros Date: Thu, 30 Jul 2020 07:58:13 -0400 Subject: [PATCH 6/6] Increase version to 1.3.0 --- netbox_onboarding/__init__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox_onboarding/__init__.py b/netbox_onboarding/__init__.py index c2fd85b..964f4a9 100644 --- a/netbox_onboarding/__init__.py +++ b/netbox_onboarding/__init__.py @@ -12,7 +12,7 @@ limitations under the License. """ -__version__ = "1.2.0" +__version__ = "1.3.0" from extras.plugins import PluginConfig diff --git a/pyproject.toml b/pyproject.toml index 2df2dcb..2c81e31 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "ntc-netbox-plugin-onboarding" -version = "1.2.0" +version = "1.3.0" description = "A plugin for NetBox to easily onboard new devices." authors = ["Network to Code, LLC "] license = "Apache-2.0"