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. + 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, 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/netbox_onboarding/onboard.py b/netbox_onboarding/onboard.py index d646af1..fe63c2a 100644 --- a/netbox_onboarding/onboard.py +++ b/netbox_onboarding/onboard.py @@ -552,10 +552,21 @@ 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() 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() 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"