networktocode / ntc-netbox-plugin-onboarding

A plugin for NetBox to easily onboard new devices.
Other
246 stars 47 forks source link
hacktoberfest napalm netbox netbox-plugin netmiko network

NetBox Onboarding plugin

Build Status

A plugin for NetBox to easily onboard new devices.

ntc-netbox-plugin-onboarding is using Netmiko, NAPALM & Django-RQ to simplify the onboarding process of a new device into NetBox down to an IP Address and a site. The goal of this plugin is not to import everything about a device into NetBox but rather to help build quickly an inventory in NetBox that is often the first step into an automation journey.

Installation

If using the installation pattern from the NetBox Documentation, you will need to activate the virtual environment before installing so that you install the package into the virtual environment.

cd /opt/netbox
source venv/bin/activate

The plugin is available as a Python package in pypi and can be installed with pip. Once the installation is completed, then NetBox and the NetBox worker must be restarted.

pip install ntc-netbox-plugin-onboarding
systemctl restart netbox netbox-rq

Compatibility Matrix

Netbox 2.8 Netbox 2.9 Netbox 2.10 Netbox 2.11
Onboarding Plugin 1.3 X
Onboarding Plugin 2.0 X X
Onboarding Plugin 2.1 X X X
Onboarding Plugin 2.2 X X X X

To ensure NetBox Onboarding plugin is automatically re-installed during future upgrades, create a file named local_requirements.txt (if not already existing) in the NetBox root directory (alongside requirements.txt) and list the ntc-netbox-plugin-onboarding package:

# echo ntc-netbox-plugin-onboarding >> local_requirements.txt

Once installed, the plugin needs to be enabled in your configuration.py

# In your configuration.py
PLUGINS = ["netbox_onboarding"]

# PLUGINS_CONFIG = {
#   "netbox_onboarding": {
#     ADD YOUR SETTINGS HERE
#   }
# }

Finally, make sure to run the migrations for this plugin

python3 manage.py migrate

The plugin behavior can be controlled with the following list of settings

Upgrades

When a new release comes out it may be necessary to run a migration of the database to account for any changes in the data models used by this plugin. Execute the command python3 manage.py migratefrom the NetBox install netbox/ directory after updating the package.

Usage

Preparation

To properly onboard a device, the plugin needs to only know the Site as well as device's primary IP address or DNS Name.

For DNS Name Resolution to work, the instance of NetBox must be able to resolve the name of the device to IP address.

Providing other attributes (Platform, Device Type, Device Role) is optional - if any of these attributes is provided, plugin will use provided value for the onboarded device. If Platform, Device Type and/or Device Role are not provided, the plugin will try to identify these information automatically and, based on the settings, it can create them in NetBox as needed.

If the Platform is provided, it must point to an existing NetBox Platform. NAPALM driver of this platform will be used only if it is defined for the platform in NetBox. To use a preferred NAPALM driver, either define it in NetBox per platform or in the plugins settings under platform_map

Onboard a new device

A new device can be onboarded via :

During a successful onboarding process, a new device will be created in NetBox with its management interface and its primary IP assigned. The management interface will be discovered on the device based on the IP address provided.

By default, the plugin is using the credentials defined in the main configuration.py for Napalm (NAPALM_USERNAME/NAPALM_PASSWORD). It's possible to define specific credentials for each onboarding task.

Consult the status of onboarding tasks

The status of the onboarding process for each device is maintained is a dedicated table in NetBox and can be retrived :

API

The plugin includes 4 API endpoints to manage the onbarding tasks

GET        /api/plugins​/onboarding​/onboarding​/       Check status of all onboarding tasks.
POST    ​   /api/plugins​/onboarding​/onboarding​/       Onboard a new device
GET     ​   /api/plugins​/onboarding​/onboarding​/{id}​/  Check the status of a specific onboarding task
DELETE    ​ /api/plugins​/onboarding​/onboarding​/{id}​/  Delete a specific onboarding task

Contributing

Pull requests are welcomed and automatically built and tested against multiple version of Python and multiple version of NetBox through TravisCI.

The project is packaged with a light development environment based on docker-compose to help with the local development of the project and to run the tests within TravisCI.

The project is following Network to Code software development guideline and is leveraging:

CLI Helper Commands

The project is coming with a CLI helper based on invoke to help setup the development environment. The commands are listed below in 3 categories dev environment, utility and testing.

Each command can be executed with invoke <command>. All commands support the arguments --netbox-ver and --python-ver if you want to manually define the version of Python and NetBox to use. Each command also has its own help invoke <command> --help

Local dev environment

  build            Build all docker images.
  debug            Start NetBox and its dependencies in debug mode.
  destroy          Destroy all containers and volumes.
  start            Start NetBox and its dependencies in detached mode.
  stop             Stop NetBox and its dependencies.

Utility

  cli              Launch a bash shell inside the running NetBox container.
  create-user      Create a new user in django (default: admin), will prompt for password.
  makemigrations   Run Make Migration in Django.
  nbshell          Launch a nbshell session.

Testing

  tests            Run all tests for this plugin.
  pylint           Run pylint code analysis.
  pydocstyle       Run pydocstyle to validate docstring formatting adheres to NTC defined standards.
  bandit           Run bandit to validate basic static code security analysis.
  black            Run black to check that Python files adhere to its style standards.
  unittest         Run Django unit tests for the plugin.

Questions

For any questions or comments, please check the FAQ first and feel free to swing by the Network to Code slack channel (channel #networktocode). Sign up here

Screenshots

List of Onboarding Tasks Onboarding Tasks

CSV form to import multiple devices CSV Form

Onboard a single device Single Device Form

Menu Menu