Skip to content

Commit e556df2

Browse files
committed
initial commit
0 parents  commit e556df2

29 files changed

+3114
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ntc_netbox_plugin_onboarding.egg-info

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
language: python
3+
4+
python:
5+
- "3.6"
6+
- "3.7"
7+
- "3.8"
8+
9+
env:
10+
- NETBOX_VER=v2.8.1
11+
# - NETBOX_VER=latest
12+
13+
services:
14+
- docker
15+
16+
before_script:
17+
- pip install invoke docker-compose poetry
18+
19+
script:
20+
- invoke build --python-ver $TRAVIS_PYTHON_VERSION

.yamllint.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
truthy: disable
6+
brackets: { min-spaces-inside: 0, max-spaces-inside: 1 }
7+
braces: { min-spaces-inside: 0, max-spaces-inside: 1 }
8+
line-length: { allow-non-breakable-inline-mappings: true, allow-non-breakable-words: true, max: 180 }
9+
comments-indentation: disable

development/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
ARG python_ver=3.7
3+
FROM python:${python_ver}
4+
5+
ARG netbox_ver=master
6+
ENV PYTHONUNBUFFERED 1
7+
8+
RUN mkdir -p /opt
9+
10+
RUN pip install --upgrade pip\
11+
&& pip install poetry
12+
13+
# -------------------------------------------------------------------------------------
14+
# Install NetBox
15+
# -------------------------------------------------------------------------------------
16+
RUN git clone --single-branch --branch ${netbox_ver} https://github.com/netbox-community/netbox.git /opt/netbox/ && \
17+
cd /opt/netbox/ && \
18+
pip install -r /opt/netbox/requirements.txt
19+
20+
# -------------------------------------------------------------------------------------
21+
# Install Netbox Plugin
22+
# -------------------------------------------------------------------------------------
23+
RUN mkdir -p /source
24+
WORKDIR /source
25+
COPY . /source
26+
RUN poetry config virtualenvs.create false \
27+
&& poetry install --no-interaction --no-ansi
28+
29+
WORKDIR /opt/netbox/netbox/

development/dev.env

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ALLOWED_HOSTS=*
2+
DB_NAME=netbox
3+
DB_USER=netbox
4+
DB_PASSWORD=decinablesprewad
5+
PGPASSWORD=decinablesprewad
6+
DB_HOST=postgres
7+
NAPALM_TIMEOUT=5
8+
MAX_PAGE_SIZE=0
9+
SECRET_KEY=bqn8nn4qmjvx4hv2u5qr4pp46s3w9skbb63y
10+
POSTGRES_USER=netbox
11+
POSTGRES_PASSWORD=decinablesprewad
12+
POSTGRES_DB=netbox
13+
CHANGELOG_RETENTION=0
14+
REDIS_HOST=redis
15+
REDIS_PORT=6379
16+
# Uncomment REDIS_SSL if using SSL
17+
# REDIS_SSL=True
18+
REDIS_PASSWORD=decinablesprewad
19+

development/docker-compose.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
version: '3'
3+
services:
4+
netbox:
5+
build:
6+
context: ../
7+
dockerfile: development/Dockerfile
8+
command: >
9+
sh -c "python manage.py migrate &&
10+
python manage.py runserver 0.0.0.0:8000"
11+
ports:
12+
- "8000:8000"
13+
depends_on:
14+
- postgres
15+
- redis
16+
env_file:
17+
- ./dev.env
18+
volumes:
19+
- ./netbox_master/configuration.py:/opt/netbox/netbox/netbox/configuration.py
20+
- ../netbox_onboarding:/source/netbox_onboarding
21+
tty: true
22+
worker:
23+
build:
24+
context: ../
25+
dockerfile: development/Dockerfile
26+
command: sh -c "python manage.py rqworker"
27+
depends_on:
28+
- netbox
29+
env_file:
30+
- ./dev.env
31+
volumes:
32+
- ./netbox_master/configuration.py:/opt/netbox/netbox/netbox/configuration.py
33+
- ../netbox_onboarding:/source/netbox_onboarding
34+
tty: true
35+
postgres:
36+
image: postgres:10
37+
env_file: dev.env
38+
volumes:
39+
- pgdata_netbox_onboarding:/var/lib/postgresql/data
40+
redis:
41+
image: redis:5-alpine
42+
command:
43+
- sh
44+
- -c # this is to evaluate the $REDIS_PASSWORD from the env
45+
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
46+
env_file: ./dev.env
47+
volumes:
48+
pgdata_netbox_onboarding:
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import os
2+
3+
# For reference see http://netbox.readthedocs.io/en/latest/configuration/mandatory-settings/
4+
# Based on https://github.com/digitalocean/netbox/blob/develop/netbox/netbox/configuration.example.py
5+
6+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7+
8+
#########################
9+
# #
10+
# Required settings #
11+
# #
12+
#########################
13+
14+
# This is a list of valid fully-qualified domain names (FQDNs) for the NetBox server. NetBox will not permit write
15+
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
16+
#
17+
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
18+
ALLOWED_HOSTS = os.environ.get("ALLOWED_HOSTS", "").split(" ")
19+
20+
# PostgreSQL database configuration.
21+
DATABASE = {
22+
"NAME": os.environ.get("DB_NAME", "netbox"), # Database name
23+
"USER": os.environ.get("DB_USER", ""), # PostgreSQL username
24+
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
25+
# PostgreSQL password
26+
"HOST": os.environ.get("DB_HOST", "localhost"), # Database server
27+
"PORT": os.environ.get("DB_PORT", ""), # Database port (leave blank for default)
28+
}
29+
30+
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
31+
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
32+
# symbols. NetBox will not run without this defined. For more information, see
33+
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
34+
SECRET_KEY = os.environ.get("SECRET_KEY", "")
35+
36+
# Redis database settings. The Redis database is used for caching and background processing such as webhooks
37+
# Seperate sections for webhooks and caching allow for connecting to seperate Redis instances/datbases if desired.
38+
# Full connection details are required in both sections, even if they are the same.
39+
REDIS = {
40+
"caching": {
41+
"HOST": os.environ.get("REDIS_HOST", "redis"),
42+
"PORT": int(os.environ.get("REDIS_PORT", 6379)),
43+
"PASSWORD": os.environ.get("REDIS_PASSWORD", ""),
44+
"DATABASE": 1,
45+
"DEFAULT_TIMEOUT": 300,
46+
"SSL": bool(os.environ.get("REDIS_SSL", False)),
47+
},
48+
"tasks": {
49+
"HOST": os.environ.get("REDIS_HOST", "redis"),
50+
"PORT": int(os.environ.get("REDIS_PORT", 6379)),
51+
"PASSWORD": os.environ.get("REDIS_PASSWORD", ""),
52+
"DATABASE": 0,
53+
"DEFAULT_TIMEOUT": 300,
54+
"SSL": bool(os.environ.get("REDIS_SSL", False)),
55+
},
56+
}
57+
58+
59+
#########################
60+
# #
61+
# Optional settings #
62+
# #
63+
#########################
64+
65+
# Specify one or more name and email address tuples representing NetBox administrators. These people will be notified of
66+
# application errors (assuming correct email settings are provided).
67+
ADMINS = [
68+
# ['John Doe', '[email protected]'],
69+
]
70+
71+
# Optionally display a persistent banner at the top and/or bottom of every page. HTML is allowed. To display the same
72+
# content in both banners, define BANNER_TOP and set BANNER_BOTTOM = BANNER_TOP.
73+
BANNER_TOP = os.environ.get("BANNER_TOP", None)
74+
BANNER_BOTTOM = os.environ.get("BANNER_BOTTOM", None)
75+
76+
# Text to include on the login page above the login form. HTML is allowed.
77+
BANNER_LOGIN = os.environ.get("BANNER_LOGIN", "")
78+
79+
# Base URL path if accessing NetBox within a directory. For example, if installed at http://example.com/netbox/, set:
80+
# BASE_PATH = 'netbox/'
81+
BASE_PATH = os.environ.get("BASE_PATH", "")
82+
83+
# Maximum number of days to retain logged changes. Set to 0 to retain changes indefinitely. (Default: 90)
84+
CHANGELOG_RETENTION = int(os.environ.get("CHANGELOG_RETENTION", 0))
85+
86+
# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
87+
# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
88+
# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
89+
CORS_ORIGIN_ALLOW_ALL = True
90+
CORS_ORIGIN_WHITELIST = []
91+
CORS_ORIGIN_REGEX_WHITELIST = []
92+
93+
# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal
94+
# sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging
95+
# on a production system.
96+
DEBUG = True
97+
DEVELOPER = True
98+
99+
# Email settings
100+
EMAIL = {
101+
"SERVER": "localhost",
102+
"PORT": 25,
103+
"USERNAME": "",
104+
"PASSWORD": "",
105+
"TIMEOUT": 10,
106+
"FROM_EMAIL": "",
107+
}
108+
109+
# Enforcement of unique IP space can be toggled on a per-VRF basis.
110+
# To enforce unique IP space within the global table (all prefixes and IP addresses not assigned to a VRF),
111+
# set ENFORCE_GLOBAL_UNIQUE to True.
112+
ENFORCE_GLOBAL_UNIQUE = False
113+
114+
# Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
115+
# https://docs.djangoproject.com/en/1.11/topics/logging/
116+
LOGGING = {}
117+
118+
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
119+
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
120+
LOGIN_REQUIRED = False
121+
122+
# Base URL path if accessing NetBox within a directory. For example, if installed at http://example.com/netbox/, set:
123+
# BASE_PATH = 'netbox/'
124+
BASE_PATH = os.environ.get("BASE_PATH", "")
125+
126+
# Setting this to True will display a "maintenance mode" banner at the top of every page.
127+
MAINTENANCE_MODE = os.environ.get("MAINTENANCE_MODE", False)
128+
129+
# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
130+
# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
131+
# all objects by specifying "?limit=0".
132+
MAX_PAGE_SIZE = int(os.environ.get("MAX_PAGE_SIZE", 1000))
133+
134+
# The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that
135+
# the default value of this setting is derived from the installed location.
136+
MEDIA_ROOT = os.environ.get("MEDIA_ROOT", os.path.join(BASE_DIR, "media"))
137+
138+
NAPALM_USERNAME = os.environ.get("NAPALM_USERNAME", "")
139+
NAPALM_PASSWORD = os.environ.get("NAPALM_PASSWORD", "")
140+
141+
# NAPALM timeout (in seconds). (Default: 30)
142+
NAPALM_TIMEOUT = os.environ.get("NAPALM_TIMEOUT", 30)
143+
144+
# NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
145+
# be provided as a dictionary.
146+
NAPALM_ARGS = {
147+
"secret": NAPALM_PASSWORD,
148+
# Include any additional args here
149+
}
150+
151+
# Determine how many objects to display per page within a list. (Default: 50)
152+
PAGINATE_COUNT = os.environ.get("PAGINATE_COUNT", 50)
153+
154+
# Enable installed plugins. Add the name of each plugin to the list.
155+
PLUGINS = ["netbox_onboarding"]
156+
157+
# Plugins configuration settings. These settings are used by various plugins that the user may have installed.
158+
# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
159+
PLUGINS_CONFIG = {"netbox_sotagg": {"github_repo": "networktocode-llc/gizmo-sot"}}
160+
161+
# When determining the primary IP address for a device, IPv6 is preferred over IPv4 by default. Set this to True to
162+
# prefer IPv4 instead.
163+
PREFER_IPV4 = os.environ.get("PREFER_IPV4", False)
164+
165+
# Remote authentication support
166+
REMOTE_AUTH_ENABLED = False
167+
REMOTE_AUTH_BACKEND = "utilities.auth_backends.RemoteUserBackend"
168+
REMOTE_AUTH_HEADER = "HTTP_REMOTE_USER"
169+
REMOTE_AUTH_AUTO_CREATE_USER = True
170+
REMOTE_AUTH_DEFAULT_GROUPS = []
171+
REMOTE_AUTH_DEFAULT_PERMISSIONS = []
172+
173+
# This determines how often the GitHub API is called to check the latest release of NetBox. Must be at least 1 hour.
174+
RELEASE_CHECK_TIMEOUT = 24 * 3600
175+
176+
# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the
177+
# version check or use the URL below to check for release in the official NetBox repository.
178+
RELEASE_CHECK_URL = None
179+
# RELEASE_CHECK_URL = 'https://api.github.com/repos/netbox-community/netbox/releases'
180+
181+
SESSION_FILE_PATH = None
182+
183+
# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
184+
# this setting is derived from the installed location.
185+
REPORTS_ROOT = os.environ.get("REPORTS_ROOT", os.path.join(BASE_DIR, "reports"))
186+
187+
# Time zone (default: UTC)
188+
TIME_ZONE = os.environ.get("TIME_ZONE", "UTC")
189+
190+
# Date/time formatting. See the following link for supported formats:
191+
# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
192+
DATE_FORMAT = os.environ.get("DATE_FORMAT", "N j, Y")
193+
SHORT_DATE_FORMAT = os.environ.get("SHORT_DATE_FORMAT", "Y-m-d")
194+
TIME_FORMAT = os.environ.get("TIME_FORMAT", "g:i a")
195+
SHORT_TIME_FORMAT = os.environ.get("SHORT_TIME_FORMAT", "H:i:s")
196+
DATETIME_FORMAT = os.environ.get("DATETIME_FORMAT", "N j, Y g:i a")
197+
SHORT_DATETIME_FORMAT = os.environ.get("SHORT_DATETIME_FORMAT", "Y-m-d H:i")

netbox_onboarding/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
(c) 2020 Network To Code
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
__version__ = "1.0.0"
15+
16+
from extras.plugins import PluginConfig
17+
18+
19+
class OnboardingConfig(PluginConfig):
20+
name = "netbox_onboarding"
21+
verbose_name = "Plugin for Easy Device Onboarding"
22+
version = "1.0.0"
23+
author = "Network to Code"
24+
description = ""
25+
base_url = "onboarding"
26+
required_settings = []
27+
default_settings = {}
28+
caching_config = {}
29+
30+
config = OnboardingConfig

netbox_onboarding/api/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)