Skip to content

Update plugin tutorial to align with NetBox 4.0 plugin API changes #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jeffgdotorg opened this issue May 9, 2024 · 2 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@jeffgdotorg
Copy link
Contributor

This tutorial needs some updates to bring it fully into line with the plugin API changes introduced in NetBox 4.0.

As a starting point, tutorial/step01-initial-setup.md still instructs the author to import from extras.plugins, instead of the new netbox.plugins package.

Refer to Migrating Your Plugin to NetBox 4.0 in the main NetBox docs for the full set of needed changes.

@jeffgdotorg jeffgdotorg added the documentation Improvements or additions to documentation label May 9, 2024
adammccartney added a commit to adammccartney/netbox-plugin-tutorial that referenced this issue Jun 10, 2024
Fixes some of the code segments that relate to the issue
netbox-community#36
@agt-the-walker
Copy link

agt-the-walker commented Feb 4, 2025

FWIW, I ran across the following issue in step09-rest-api.md (Step 9: REST API) against a development instance of Netbox (v4.2.1):

$ python3 manage.py runserver 0.0.0.0:8000 --insecure
[...]
  File "/home/agt/netbox-plugin-demo/netbox_access_lists/api/urls.py", line 2, in <module>
    from . import views
  File "/home/agt/netbox-plugin-demo/netbox_access_lists/api/views.py", line 6, in <module>
    from .serializers import AccessListSerializer, AccessListRuleSerializer
  File "/home/agt/netbox-plugin-demo/netbox_access_lists/api/serializers.py", line 3, in <module>
    from ipam.api.serializers import NestedPrefixSerializer
ImportError: cannot import name 'NestedPrefixSerializer' from 'ipam.api.serializers' (/opt/netbox/netbox/ipam/api/serializers.py). Did you mean: 'PrefixSerializer'?

The following change was enough to fix the problem (at first glance):

$ git diff remotes/origin/step09-rest-api -- ':!netbox_access_lists/__init__.py' ':!netbox_access_lists/navigation.py' ':!netbox_access_lists/migrations/0001_initial.py' ':!*.pyc'
diff --git a/netbox_access_lists/api/serializers.py b/netbox_access_lists/api/serializers.py
index 00c509e..4a58a92 100644
--- a/netbox_access_lists/api/serializers.py
+++ b/netbox_access_lists/api/serializers.py
@@ -1,6 +1,6 @@
 from rest_framework import serializers

-from ipam.api.serializers import NestedPrefixSerializer
+from ipam.api.serializers import PrefixSerializer
 from netbox.api.serializers import NetBoxModelSerializer, WritableNestedSerializer
 from ..models import AccessList, AccessListRule

@@ -52,8 +52,8 @@ class AccessListRuleSerializer(NetBoxModelSerializer):
         view_name='plugins-api:netbox_access_lists-api:accesslistrule-detail'
     )
     access_list = NestedAccessListSerializer()
-    source_prefix = NestedPrefixSerializer()
-    destination_prefix = NestedPrefixSerializer()
+    source_prefix = PrefixSerializer(nested=True)
+    destination_prefix = PrefixSerializer(nested=True)

     class Meta:
         model = AccessListRule

@deliciouslytyped
Copy link

I just spent half an hour on this wondering why my buttons weren't showing up, because /AFAICT/ netbox appears to have hidden whatever errors this causes.

As a starting point, tutorial/step01-initial-setup.md still instructs the author to import from extras.plugins, instead of the new netbox.plugins package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants