Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# NetBox Plugin Development Tutorial

This guide seeks to demonstrate the process of developing a custom plugin for NetBox v3.2 or later. By following each of the prescribed steps, the reader will create from scratch a simple plugin for managing access lists in NetBox, utilizing all major components of the NetBox plugin framework.
This guide seeks to demonstrate the process of developing a custom plugin for NetBox v4.5 or later.
By following each of the prescribed steps, the reader will create from scratch a simple plugin for managing access lists in NetBox, using all major components of the NetBox plugin framework.

A completed copy of the demo plugin created in this tutorial is available in the [`netbox-plugin-demo`](https://github.com/netbox-community/netbox-plugin-demo) repository for reference. For your convenience, the completed code corresponding to each step in the tutorial exists as a named branch in the demo repo. For example, if you want to start fresh on step 5, simply check out the `step04-forms` branch.
A completed copy of the demo plugin created in this tutorial is available in the [`netbox-plugin-demo`](https://github.com/netbox-community/netbox-plugin-demo) repository for reference.
For your convenience, the completed code corresponding to each step in the tutorial exists as a named branch in the demo repo.
For example, if you want to start fresh on step 5, check out the `step04-forms` branch.

### Prerequisites

Expand All @@ -15,17 +18,19 @@ Before attempting to create a plugin, please assess your personal ability. Plugi

### Contents

* [Step 1: Initial Setup](/tutorial/step01-initial-setup.md) :arrow_left: Start here!
* [Step 0: Initial Setup](/tutorial/step00-initial-setup.md) :arrow_left: Start here!
* [Step 1: Plugin Configuration](/tutorial/step01-plugin-configuration.md)
* [Step 2: Models](/tutorial/step02-models.md)
* [Step 3: Tables](/tutorial/step03-tables.md)
* [Step 4: Forms](/tutorial/step04-forms.md)
* [Step 5: Views](/tutorial/step05-views.md)
* [Step 6: Templates](/tutorial/step06-templates.md)
* [Step 7: Navigation](/tutorial/step07-navigation.md)
* [Step 8: Filter Sets](/tutorial/step08-filter-sets.md)
* [Step 9: REST API](/tutorial/step09-rest-api.md)
* [Step 10: GraphQL API](/tutorial/step10-graphql-api.md)
* [Step 11: Search](/tutorial/step11-search.md)
* [Step 6: URLs](/tutorial/step06-urls.md)
* [Step 7: Templates](/tutorial/step07-templates.md)
* [Step 8: Navigation](/tutorial/step08-navigation.md)
* [Step 9: Filter Sets](/tutorial/step09-filter-sets.md)
* [Step 10: REST API](/tutorial/step10-rest-api.md)
* [Step 11: GraphQL API](/tutorial/step11-graphql-api.md)
* [Step 12: Search](/tutorial/step12-search.md)

### Reference

Expand Down
Binary file removed images/step01-django-admin-plugins.png
Binary file not shown.
Binary file added images/step01-netbox-plugin-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/step05-accesslist-form.png
Binary file not shown.
Binary file removed images/step05-accesslist-list.png
Binary file not shown.
Binary file added images/step06-accesslist-form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step06-accesslist-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/step06-accesslist1.png
Binary file not shown.
Binary file removed images/step06-accesslist2.png
Binary file not shown.
Binary file removed images/step06-accesslistrule.png
Binary file not shown.
Binary file added images/step07-accesslist1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step07-accesslist2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step07-accesslist3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step07-accesslistrule.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/step07-menu-items1.png
Binary file not shown.
Binary file removed images/step07-menu-items2.png
Binary file not shown.
Binary file removed images/step08-filter-form.png
Binary file not shown.
Binary file added images/step08-menu-items1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step08-menu-items2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step09-filter-form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/step09-rest-api1.png
Binary file not shown.
Binary file removed images/step09-rest-api2.png
Binary file not shown.
Binary file removed images/step10-graphiql.png
Binary file not shown.
Binary file added images/step10-rest-api1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step10-rest-api2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/step11-graphiql.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/step11-search-results.png
Diff not rendered.
Binary file added images/step12-search-results.png
105 changes: 105 additions & 0 deletions tutorial/step00-initial-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Step 0: Initial Setup

Before we start writing our plugin, we need a working local NetBox development environment. In this step we'll:

- Install (or verify) a local NetBox dev setup
- Enable development-friendly settings
- Optionally clone the demo plugin repository so you can follow along (or jump between tutorial steps)

:warning: **Warning:** This tutorial requires **NetBox v4.5 or later**. Attempting to use an earlier NetBox release will not work.

## Install the NetBox Development Environment

Plugin development requires a local installation of NetBox.

If you don't already have NetBox installed, follow the official [installation instructions](https://netbox.readthedocs.io/en/stable/installation/). For development, installing from the Git repository is recommended because it makes it easy to switch between NetBox versions/tags.

:green_circle: **Tip:** If you're setting this up *only* for local development, you can usually stop once you can successfully start the development server (e.g. `manage.py runserver`). You can always come back later and complete any optional production hardening steps.

Before you start developing, make sure NetBox is running in development mode with debugging enabled. From your NetBox installation root, edit `netbox/netbox/configuration.py` and set:

```python
DEBUG = True
DEVELOPER = True
```

These settings ensure that:

- static assets can be served by the development server
- you'll get full tracebacks in the browser when an error occurs

:blue_square: **Note:** If NetBox is already running, restart the development server after changing these settings.

:warning: **Warning:** Never enable `DEBUG = True` in a production environment.

## Prepare the Plugin Development Environment

A NetBox plugin is a standard Python package that contains a NetBox-specific Django application. Your plugin project should be structured according to the [Python Packaging User Guide](https://packaging.python.org/en/latest/tutorials/packaging-projects/).

There are two ways to follow this tutorial:

1. **Create the directory structure manually** (you can optionally use the demo repository as a reference).
2. **Use the cookiecutter template** ([cookiecutter-netbox-plugin](https://github.com/netbox-community/cookiecutter-netbox-plugin)) to generate a new plugin project.

In this tutorial, we'll use the **manual approach**, building up a project that will eventually look similar to this:

```text
.
├── netbox_access_lists
│ ├── api
│ │ ├── __init__.py
│ │ ├── serializers.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── choices.py
│ ├── filtersets.py
│ ├── forms.py
│ ├── graphql
│ │ ├── enums.py
│ │ ├── filters.py
│ │ ├── __init__.py
│ │ ├── schema.py
│ │ └── types.py
│ ├── __init__.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ └── __init__.py
│ ├── models.py
│ ├── navigation.py
│ ├── search.py
│ ├── tables.py
│ ├── templates
│ │ └── netbox_access_lists
│ │ ├── accesslist.html
│ │ └── accesslistrule.html
│ ├── urls.py
│ └── views.py
├── pyproject.toml
└── README.md
```

:blue_square: **Note:** You don't need to create all of this up front. We'll add files and directories as we go.

If you prefer to use the cookiecutter template, you can skip ahead to [Step 1](/tutorial/step01-plugin-configuration.md). Keep in mind that cookiecutter generates a slightly different (and more complete) project layout, which is especially helpful if you plan to publish your plugin on PyPI.

If you're following the manual approach and want a reference implementation to compare against, see the next section.

### Demo Git repository (optional)

The demo repository contains the completed plugin project from this tutorial. Each tutorial step builds on the previous one, and the demo repo includes a snapshot of the code at each step as a separate Git branch.

To clone the demo repository, `cd` to your preferred workspace (your home directory is fine) and run:

```bash
git clone --branch step00-empty https://github.com/netbox-community/netbox-plugin-demo
```

:blue_square: **Note:** Cloning the demo repository is optional, but it makes it easy to jump between steps and compare your work to a known-good implementation if you get stuck.

This completes our initial setup.

<div align="center">

[Step 1: Plugin Configuration](/tutorial/step01-plugin-configuration.md) :arrow_right:

</div>
163 changes: 0 additions & 163 deletions tutorial/step01-initial-setup.md

This file was deleted.

Loading