Compare commits
47 Commits
Author | SHA1 | Date | |
---|---|---|---|
d92f991cbe | |||
c16f72a2ac | |||
2fe139cb3c | |||
aa68548f41 | |||
a10cd805ae | |||
8b8620864c | |||
d145e9c719 | |||
a120a95184 | |||
97477556e0 | |||
7e6edd1bf5 | |||
b53e886f8f | |||
63062a2634 | |||
2b628b9826 | |||
6cc4c67387 | |||
ab0ce20971 | |||
90ae5cf01d | |||
ebb7779b5f | |||
60f7de1898 | |||
89fddbe0ab | |||
a2b08a6ca5 | |||
86675278ab | |||
791027f77b | |||
819f325bd5 | |||
4053a714f8 | |||
f1ebd4d246 | |||
68e6a62df1 | |||
81f8c7386d | |||
ec1a253bde | |||
bd1c58c91e | |||
05070b3f9f | |||
ab72ba10c2 | |||
4c6ba58ef5 | |||
6d74443f21 | |||
61414b7be7 | |||
d8285b05f2 | |||
968bb9f10f | |||
aafa6483dc | |||
38ea286111 | |||
be0ce47bc6 | |||
2b3f831749 | |||
fb22a19893 | |||
fdefa3465d | |||
645ec1281c | |||
013f81b791 | |||
b8885e4b79 | |||
bf557877d1 | |||
b88974ef9f |
14
Dockerfile
14
Dockerfile
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.6-alpine3.7
|
FROM python:3.6-alpine3.8
|
||||||
|
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
bash \
|
bash \
|
||||||
@ -6,13 +6,13 @@ RUN apk add --no-cache \
|
|||||||
ca-certificates \
|
ca-certificates \
|
||||||
cyrus-sasl-dev \
|
cyrus-sasl-dev \
|
||||||
graphviz \
|
graphviz \
|
||||||
ttf-ubuntu-font-family \
|
|
||||||
jpeg-dev \
|
jpeg-dev \
|
||||||
libffi-dev \
|
libffi-dev \
|
||||||
libxml2-dev \
|
libxml2-dev \
|
||||||
libxslt-dev \
|
libxslt-dev \
|
||||||
openldap-dev \
|
openldap-dev \
|
||||||
postgresql-dev \
|
postgresql-dev \
|
||||||
|
ttf-ubuntu-font-family \
|
||||||
wget
|
wget
|
||||||
|
|
||||||
RUN pip install \
|
RUN pip install \
|
||||||
@ -21,7 +21,13 @@ RUN pip install \
|
|||||||
# napalm is used for gathering information from network devices
|
# napalm is used for gathering information from network devices
|
||||||
napalm \
|
napalm \
|
||||||
# ruamel is used in startup_scripts
|
# ruamel is used in startup_scripts
|
||||||
ruamel.yaml
|
ruamel.yaml \
|
||||||
|
# pinning django to the version required by netbox
|
||||||
|
# adding it here, to install the correct version of
|
||||||
|
# django-rq
|
||||||
|
'Django>=1.11,<2.1' \
|
||||||
|
# django-rq is used for webhooks
|
||||||
|
django-rq
|
||||||
|
|
||||||
WORKDIR /opt
|
WORKDIR /opt
|
||||||
|
|
||||||
@ -45,8 +51,6 @@ WORKDIR /opt/netbox/netbox
|
|||||||
|
|
||||||
ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
|
ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
|
||||||
|
|
||||||
VOLUME ["/etc/netbox-nginx/"]
|
|
||||||
|
|
||||||
CMD ["gunicorn", "-c /etc/netbox/config/gunicorn_config.py", "netbox.wsgi"]
|
CMD ["gunicorn", "-c /etc/netbox/config/gunicorn_config.py", "netbox.wsgi"]
|
||||||
|
|
||||||
LABEL SRC_URL="$URL"
|
LABEL SRC_URL="$URL"
|
||||||
|
125
README.md
125
README.md
@ -5,8 +5,11 @@
|
|||||||
This repository houses the components needed to build NetBox as a Docker container.
|
This repository houses the components needed to build NetBox as a Docker container.
|
||||||
Images built using this code are released to [Docker Hub][netbox-dockerhub] every night.
|
Images built using this code are released to [Docker Hub][netbox-dockerhub] every night.
|
||||||
|
|
||||||
|
Questions? Before opening an issue on Github, please join the [Network To Code][ntc-slack] and ask for help in our `#netbox-docker` channel.
|
||||||
|
|
||||||
[travis]: https://travis-ci.org/ninech/netbox-docker
|
[travis]: https://travis-ci.org/ninech/netbox-docker
|
||||||
[netbox-dockerhub]: https://hub.docker.com/r/ninech/netbox/tags/
|
[netbox-dockerhub]: https://hub.docker.com/r/ninech/netbox/tags/
|
||||||
|
[ntc-slack]: http://slack.networktocode.com/
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
@ -54,7 +57,8 @@ To ensure this, compare the output of `docker --version` and `docker-compose --v
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
You can configure the app using environment variables. These are defined in `netbox.env`.
|
You can configure the app using environment variables.
|
||||||
|
These are defined in `netbox.env`.
|
||||||
Read [Environment Variables in Compose][compose-env] to understand about the various possibilities to overwrite these variables.
|
Read [Environment Variables in Compose][compose-env] to understand about the various possibilities to overwrite these variables.
|
||||||
(The easiest solution being simply adjusting that file.)
|
(The easiest solution being simply adjusting that file.)
|
||||||
|
|
||||||
@ -70,11 +74,12 @@ For example defining `ALLOWED_HOSTS=localhost ::1 127.0.0.1` would allows access
|
|||||||
The default settings are optimized for (local) development environments.
|
The default settings are optimized for (local) development environments.
|
||||||
You should therefore adjust the configuration for production setups, at least the following variables:
|
You should therefore adjust the configuration for production setups, at least the following variables:
|
||||||
|
|
||||||
* `ALLOWED_HOSTS`: Add all URLs that lead to your NetBox instance.
|
* `ALLOWED_HOSTS`: Add all URLs that lead to your NetBox instance, space separated. E.g. `ALLOWED_HOSTS=netbox.mycorp.com server042.mycorp.com 2a02:123::42 10.0.0.42 localhost ::1 127.0.0.1` (It's good advice to always allow localhost connections for easy debugging, i.e. `localhost ::1 127.0.0.1`.)
|
||||||
* `DB_*`: Use a persistent database.
|
* `DB_*`: Use your own persistent database. Don't use the default passwords!
|
||||||
* `EMAIL_*`: Use your own mailserver.
|
* `EMAIL_*`: Use your own mailserver.
|
||||||
* `MAX_PAGE_SIZE`: Use the recommended default of 1000.
|
* `MAX_PAGE_SIZE`: Use the recommended default of 1000.
|
||||||
* `SUPERUSER_*`: Only define those variables during the initial setup, and drop them once the DB is set up.
|
* `SUPERUSER_*`: Only define those variables during the initial setup, and drop them once the DB is set up. Don't use the default passwords!
|
||||||
|
* `REDIS_*`: Use your own persistent redis. Don't use the default passwords!
|
||||||
|
|
||||||
### Running on Docker Swarm / Kubernetes / OpenShift
|
### Running on Docker Swarm / Kubernetes / OpenShift
|
||||||
|
|
||||||
@ -95,6 +100,7 @@ If a secret is defined by an environment variable and in the respective file at
|
|||||||
* `SECRET_KEY`: `/run/secrets/secret_key`
|
* `SECRET_KEY`: `/run/secrets/secret_key`
|
||||||
* `EMAIL_PASSWORD`: `/run/secrets/email_password`
|
* `EMAIL_PASSWORD`: `/run/secrets/email_password`
|
||||||
* `NAPALM_PASSWORD`: `/run/secrets/napalm_password`
|
* `NAPALM_PASSWORD`: `/run/secrets/napalm_password`
|
||||||
|
* `REDIS_PASSWORD`: `/run/secrets/redis_password`
|
||||||
|
|
||||||
Please also consider [the advice about running NetBox in production](#production) above!
|
Please also consider [the advice about running NetBox in production](#production) above!
|
||||||
|
|
||||||
@ -155,7 +161,7 @@ if created:
|
|||||||
|
|
||||||
#### Initializers
|
#### Initializers
|
||||||
|
|
||||||
Initializers are built-in startup scripts for defining NetBox custom fields, groups and users.
|
Initializers are built-in startup scripts for defining NetBox custom fields, groups, users and many other resources.
|
||||||
All you need to do is to mount you own `initializers` folder ([see `docker-compose.yml`][netbox-docker-compose]).
|
All you need to do is to mount you own `initializers` folder ([see `docker-compose.yml`][netbox-docker-compose]).
|
||||||
Look at the [`initializers` folder][netbox-docker-initializers] to learn how the files must look like.
|
Look at the [`initializers` folder][netbox-docker-initializers] to learn how the files must look like.
|
||||||
|
|
||||||
@ -182,6 +188,15 @@ text_field:
|
|||||||
[netbox-docker-initializers]: https://github.com/ninech/netbox-docker/tree/master/initializers
|
[netbox-docker-initializers]: https://github.com/ninech/netbox-docker/tree/master/initializers
|
||||||
[netbox-docker-compose]: https://github.com/ninech/netbox-docker/blob/master/docker-compose.yml
|
[netbox-docker-compose]: https://github.com/ninech/netbox-docker/blob/master/docker-compose.yml
|
||||||
|
|
||||||
|
##### Available Groups for User/Group initializers
|
||||||
|
|
||||||
|
To get an up-to-date list about all the available permissions, run the following command.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Make sure the 'netbox' container is already running! If unsure, run `docker-compose up -d`
|
||||||
|
echo "from django.contrib.auth.models import Permission\nfor p in Permission.objects.all():\n print(p.codename);" | docker-compose exec -T netbox ./manage.py shell
|
||||||
|
```
|
||||||
|
|
||||||
#### Custom Docker Image
|
#### Custom Docker Image
|
||||||
|
|
||||||
You can also build your own NetBox Docker image containing your own startup scripts, custom fields, users and groups
|
You can also build your own NetBox Docker image containing your own startup scripts, custom fields, users and groups
|
||||||
@ -249,6 +264,32 @@ If your issue is not here, look through [the existing issues][issues] and eventu
|
|||||||
* To create a database backup run `docker-compose exec postgres sh -c 'pg_dump -cU $POSTGRES_USER $POSTGRES_DB' | gzip > db_dump.sql.gz`
|
* To create a database backup run `docker-compose exec postgres sh -c 'pg_dump -cU $POSTGRES_USER $POSTGRES_DB' | gzip > db_dump.sql.gz`
|
||||||
* To restore that database backup run `gunzip -c db_dump.sql.gz | docker exec -i $(docker-compose ps -q postgres) sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'`.
|
* To restore that database backup run `gunzip -c db_dump.sql.gz | docker exec -i $(docker-compose ps -q postgres) sh -c 'psql -U $POSTGRES_USER $POSTGRES_DB'`.
|
||||||
|
|
||||||
|
### Nginx doesn't start
|
||||||
|
|
||||||
|
As a first step, stop your docker-compose setup.
|
||||||
|
Then locate the `netbox-nginx-config` volume and remove it:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Stop your local netbox-docker installation
|
||||||
|
$ docker-compose down
|
||||||
|
|
||||||
|
# Find the volume
|
||||||
|
$ docker volume ls | grep netbox-nginx-config
|
||||||
|
local netbox-docker_netbox-nginx-config
|
||||||
|
|
||||||
|
# Remove the volume
|
||||||
|
$ docker volume rm netbox-docker_netbox-nginx-config
|
||||||
|
netbox-docker_netbox-nginx-config
|
||||||
|
```
|
||||||
|
|
||||||
|
Now start everything up again.
|
||||||
|
|
||||||
|
If this didn't help, try to see if there's anything in the logs indicating why nginx doesn't start:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker-compose logs -f nginx
|
||||||
|
```
|
||||||
|
|
||||||
### Getting a "Bad Request (400)"
|
### Getting a "Bad Request (400)"
|
||||||
|
|
||||||
> When connecting to the NetBox instance, I get a "Bad Request (400)" error.
|
> When connecting to the NetBox instance, I get a "Bad Request (400)" error.
|
||||||
@ -257,26 +298,78 @@ This usually happens when the `ALLOWED_HOSTS` variable is not set correctly.
|
|||||||
|
|
||||||
### How to upgrade
|
### How to upgrade
|
||||||
|
|
||||||
> How do I update to a newer version?
|
> How do I update to a newer version of netbox?
|
||||||
|
|
||||||
It should be sufficient to pull the latest image from Docker Hub, stopping the container and starting it up again:
|
It should be sufficient to pull the latest image from Docker Hub, stopping the container and starting it up again:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose pull netbox
|
docker-compose pull netbox
|
||||||
docker-compose stop netbox
|
docker-compose stop netbox netbox-worker
|
||||||
docker-compose rm -f netbox
|
docker-compose rm -f netbox netbox-worker
|
||||||
docker-compose up -d netbox
|
docker-compose up -d netbox netbox-worker
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Webhooks don't work
|
||||||
|
|
||||||
|
First make sure that the webhooks feature is enabled in your Netbox configuration and that a redis host is defined.
|
||||||
|
Check `netbox.env` if the following variables are defined:
|
||||||
|
|
||||||
|
```
|
||||||
|
WEBHOOKS_ENABLED=true
|
||||||
|
REDIS_HOST=redis
|
||||||
|
```
|
||||||
|
|
||||||
|
Then make sure that the `redis` container and at least one `netbox-worker` are running.
|
||||||
|
|
||||||
|
```
|
||||||
|
# check the container status
|
||||||
|
$ docker-compose ps
|
||||||
|
|
||||||
|
Name Command State Ports
|
||||||
|
--------------------------------------------------------------------------------------------------------
|
||||||
|
netbox-docker_netbox-worker_1 /opt/netbox/docker-entrypo ... Up
|
||||||
|
netbox-docker_netbox_1 /opt/netbox/docker-entrypo ... Up
|
||||||
|
netbox-docker_nginx_1 nginx -c /etc/netbox-nginx ... Up 80/tcp, 0.0.0.0:32776->8080/tcp
|
||||||
|
netbox-docker_postgres_1 docker-entrypoint.sh postgres Up 5432/tcp
|
||||||
|
netbox-docker_redis_1 docker-entrypoint.sh redis ... Up 6379/tcp
|
||||||
|
|
||||||
|
# connect to redis and send PING command:
|
||||||
|
$ docker-compose run --rm -T redis sh -c 'redis-cli -h redis -a $REDIS_PASSWORD ping'
|
||||||
|
Warning: Using a password with '-a' option on the command line interface may not be safe.
|
||||||
|
PONG
|
||||||
|
```
|
||||||
|
|
||||||
|
If `redis` and the `netbox-worker` are not available, make sure you have updated your `docker-compose.yml` file!
|
||||||
|
|
||||||
|
Everything's up and running? Then check the log of `netbox-worker` and/or `redis`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose logs -f netbox-worker
|
||||||
|
docker-compose logs -f redis
|
||||||
|
```
|
||||||
|
|
||||||
|
Still no clue? You can connect to the `redis` container and have it report any command that is currently executed on the server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose run --rm -T redis sh -c 'redis-cli -h redis -a $REDIS_PASSWORD monitor'
|
||||||
|
|
||||||
|
# Hit CTRL-C a few times to leave
|
||||||
|
```
|
||||||
|
|
||||||
|
If you don't see anything happening after you triggered a webhook, double-check the configuration of the `netbox` and the `netbox-worker` containers and also check the configuration of your webhook in the admin interface of Netbox.
|
||||||
|
|
||||||
### Breaking Changes
|
### Breaking Changes
|
||||||
|
|
||||||
From time to time it might become necessary to re-order the structure of the container.
|
From time to time it might become necessary to re-engineer the structure of this setup.
|
||||||
Things like the `docker-compose.yml` file or your Kubernets or OpenShift configurations have to be adjusted as a consequence.
|
Things like the `docker-compose.yml` file or your Kubernetes or OpenShift configurations have to be adjusted as a consequence.
|
||||||
Since April 2018 each image built from this repo contains a `NETBOX_DOCKER_PROJECT_VERSION` label.
|
Since April 2018 each image built from this repo contains a `NETBOX_DOCKER_PROJECT_VERSION` label.
|
||||||
You can check the label of your local image by running `docker inspect ninech/netbox:v2.3.1 --format "{{json .ContainerConfig.Labels}}"`.
|
You can check the label of your local image by running `docker inspect ninech/netbox:v2.3.1 --format "{{json .ContainerConfig.Labels}}"`.
|
||||||
|
Compare the version with the list below to check whether a breaking change was introduced with that version.
|
||||||
|
|
||||||
The following is a list of breaking changes:
|
The following is a list of breaking changes of the `netbox-docker` project:
|
||||||
|
|
||||||
|
* 0.5.0: Alpine was updated to 3.8, `*.env` moved to `/env` folder
|
||||||
|
* 0.4.0: In order to use Netbox webhooks you need to add Redis and a netbox-worker to your docker-compose.yml.
|
||||||
* 0.3.0: Field `filterable: <boolean` was replaced with field `filter_logic: loose/exact/disabled`. It will default to `CF_FILTER_LOOSE=loose` when not defined.
|
* 0.3.0: Field `filterable: <boolean` was replaced with field `filter_logic: loose/exact/disabled`. It will default to `CF_FILTER_LOOSE=loose` when not defined.
|
||||||
* 0.2.0: Re-organized paths: `/etc/netbox -> /etc/netbox/config` and `/etc/reports -> /etc/netbox/reports`. Fixes [#54](https://github.com/ninech/netbox-docker/issues/54).
|
* 0.2.0: Re-organized paths: `/etc/netbox -> /etc/netbox/config` and `/etc/reports -> /etc/netbox/reports`. Fixes [#54](https://github.com/ninech/netbox-docker/issues/54).
|
||||||
* 0.1.0: Introduction of the `NETBOX_DOCKER_PROJECT_VERSION`. (Not a breaking change per se.)
|
* 0.1.0: Introduction of the `NETBOX_DOCKER_PROJECT_VERSION`. (Not a breaking change per se.)
|
||||||
@ -304,9 +397,15 @@ You can use the following ENV variables to customize the build:
|
|||||||
Default: https://github.com/${SRC_REPO}/netbox/archive/$BRANCH.tar.gz
|
Default: https://github.com/${SRC_REPO}/netbox/archive/$BRANCH.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Publishing Docker Images
|
||||||
|
|
||||||
|
New Docker Images are built and published every 24h by using travis:
|
||||||
|
|
||||||
|
[][travis]
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
To run the test coming with NetBox, use the `docker-compose.yml` file as such:
|
To run the tests coming with NetBox, use the `docker-compose.yml` file as such:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ docker-compose run netbox ./manage.py test
|
$ docker-compose run netbox ./manage.py test
|
||||||
|
@ -3,9 +3,17 @@
|
|||||||
|
|
||||||
echo "▶️ $0 $*"
|
echo "▶️ $0 $*"
|
||||||
|
|
||||||
|
if [ ! -z "${GITHUB_OAUTH_CLIENT_ID}" ] && [ ! -z "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then
|
||||||
|
echo "🗝 Performing authenticated Github API calls."
|
||||||
|
GITHUB_OAUTH_PARAMS="client_id=${GITHUB_OAUTH_CLIENT_ID}&client_secret=${GITHUB_OAUTH_CLIENT_SECRET}"
|
||||||
|
else
|
||||||
|
echo "🕶 Performing unauthenticated Github API calls. This might result in lower Github rate limits!"
|
||||||
|
GITHUB_OAUTH_PARAMS=""
|
||||||
|
fi
|
||||||
|
|
||||||
ORIGINAL_GITHUB_REPO="digitalocean/netbox"
|
ORIGINAL_GITHUB_REPO="digitalocean/netbox"
|
||||||
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
|
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
|
||||||
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/branches"
|
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/branches?${GITHUB_OAUTH_PARAMS}"
|
||||||
|
|
||||||
CURL="curl -sS"
|
CURL="curl -sS"
|
||||||
|
|
||||||
|
@ -3,9 +3,17 @@
|
|||||||
|
|
||||||
echo "▶️ $0 $*"
|
echo "▶️ $0 $*"
|
||||||
|
|
||||||
|
if [ ! -z "${GITHUB_OAUTH_CLIENT_ID}" ] && [ ! -z "${GITHUB_OAUTH_CLIENT_SECRET}" ]; then
|
||||||
|
echo "🗝 Performing authenticated Github API calls."
|
||||||
|
GITHUB_OAUTH_PARAMS="client_id=${GITHUB_OAUTH_CLIENT_ID}&client_secret=${GITHUB_OAUTH_CLIENT_SECRET}"
|
||||||
|
else
|
||||||
|
echo "🕶 Performing unauthenticated Github API calls. This might result in lower Github rate limits!"
|
||||||
|
GITHUB_OAUTH_PARAMS=""
|
||||||
|
fi
|
||||||
|
|
||||||
ORIGINAL_GITHUB_REPO="digitalocean/netbox"
|
ORIGINAL_GITHUB_REPO="digitalocean/netbox"
|
||||||
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
|
GITHUB_REPO="${GITHUB_REPO-$ORIGINAL_GITHUB_REPO}"
|
||||||
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases"
|
URL_RELEASES="https://api.github.com/repos/${GITHUB_REPO}/releases?${GITHUB_OAUTH_PARAMS}"
|
||||||
|
|
||||||
JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name"
|
JQ_LATEST="group_by(.prerelease) | .[] | sort_by(.published_at) | reverse | .[0] | select(.prerelease==${PRERELEASE-false}) | .tag_name"
|
||||||
|
|
||||||
|
@ -139,6 +139,19 @@ PAGINATE_COUNT = int(os.environ.get('PAGINATE_COUNT', 50))
|
|||||||
# prefer IPv4 instead.
|
# prefer IPv4 instead.
|
||||||
PREFER_IPV4 = os.environ.get('PREFER_IPV4', 'False').lower() == 'true'
|
PREFER_IPV4 = os.environ.get('PREFER_IPV4', 'False').lower() == 'true'
|
||||||
|
|
||||||
|
# The Webhook event backend is disabled by default. Set this to True to enable it. Note that this requires a Redis
|
||||||
|
# database be configured and accessible by NetBox (see `REDIS` below).
|
||||||
|
WEBHOOKS_ENABLED = os.environ.get('WEBHOOKS_ENABLED', 'False').lower() == 'true'
|
||||||
|
|
||||||
|
# Redis database settings (optional). A Redis database is required only if the webhooks backend is enabled.
|
||||||
|
REDIS = {
|
||||||
|
'HOST': os.environ.get('REDIS_HOST', 'localhost'),
|
||||||
|
'PORT': os.environ.get('REDIS_PORT', 6379),
|
||||||
|
'PASSWORD': os.environ.get('REDIS_PASSWORD', read_secret('redis_password')),
|
||||||
|
'DATABASE': os.environ.get('REDIS_DATABASE', '0'),
|
||||||
|
'DEFAULT_TIMEOUT': os.environ.get('REDIS_TIMEOUT', '300'),
|
||||||
|
}
|
||||||
|
|
||||||
# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
|
# The file path where custom reports will be stored. A trailing slash is not needed. Note that the default value of
|
||||||
# this setting is derived from the installed location.
|
# this setting is derived from the installed location.
|
||||||
REPORTS_ROOT = os.environ.get('REPORTS_ROOT', '/etc/netbox/reports')
|
REPORTS_ROOT = os.environ.get('REPORTS_ROOT', '/etc/netbox/reports')
|
||||||
|
@ -1,46 +1,67 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
netbox:
|
netbox: &netbox
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
args:
|
args:
|
||||||
- BRANCH=${VERSION-master}
|
- BRANCH=${VERSION-master}
|
||||||
image: ninech/netbox:${VERSION-latest}
|
image: ninech/netbox:${VERSION-latest}
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgres
|
- postgres
|
||||||
env_file: netbox.env
|
- redis
|
||||||
volumes:
|
- netbox-worker
|
||||||
- ./startup_scripts:/opt/netbox/startup_scripts:ro
|
env_file: env/netbox.env
|
||||||
- ./initializers:/opt/netbox/initializers:ro
|
volumes:
|
||||||
- ./configuration:/etc/netbox/config:ro
|
- ./startup_scripts:/opt/netbox/startup_scripts:ro
|
||||||
- netbox-nginx-config:/etc/netbox-nginx/
|
- ./initializers:/opt/netbox/initializers:ro
|
||||||
- netbox-static-files:/opt/netbox/netbox/static
|
- ./configuration:/etc/netbox/config:ro
|
||||||
- netbox-media-files:/opt/netbox/netbox/media
|
- netbox-nginx-config:/etc/netbox-nginx/
|
||||||
- netbox-report-files:/etc/netbox/reports:ro
|
- netbox-static-files:/opt/netbox/netbox/static
|
||||||
nginx:
|
- netbox-media-files:/opt/netbox/netbox/media
|
||||||
image: nginx:1.13-alpine
|
- netbox-report-files:/etc/netbox/reports:ro
|
||||||
command: nginx -g 'daemon off;' -c /etc/netbox-nginx/nginx.conf
|
netbox-worker:
|
||||||
depends_on:
|
<<: *netbox
|
||||||
- netbox
|
depends_on:
|
||||||
ports:
|
- redis
|
||||||
- 8080
|
entrypoint:
|
||||||
volumes:
|
- python3
|
||||||
- netbox-static-files:/opt/netbox/netbox/static:ro
|
- /opt/netbox/netbox/manage.py
|
||||||
- netbox-nginx-config:/etc/netbox-nginx/:ro
|
command:
|
||||||
postgres:
|
- rqworker
|
||||||
image: postgres:10.4-alpine
|
nginx:
|
||||||
env_file: postgres.env
|
command: nginx -c /etc/netbox-nginx/nginx.conf
|
||||||
volumes:
|
image: nginx:1.15-alpine
|
||||||
- netbox-postgres-data:/var/lib/postgresql/data
|
depends_on:
|
||||||
|
- netbox
|
||||||
|
ports:
|
||||||
|
- 8080
|
||||||
|
volumes:
|
||||||
|
- netbox-static-files:/opt/netbox/netbox/static:ro
|
||||||
|
- netbox-nginx-config:/etc/netbox-nginx/:ro
|
||||||
|
postgres:
|
||||||
|
image: postgres:10.4-alpine
|
||||||
|
env_file: env/postgres.env
|
||||||
|
volumes:
|
||||||
|
- netbox-postgres-data:/var/lib/postgresql/data
|
||||||
|
redis:
|
||||||
|
image: redis:4-alpine
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
||||||
|
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
||||||
|
env_file: env/redis.env
|
||||||
|
volumes:
|
||||||
|
- netbox-redis-data:/data
|
||||||
volumes:
|
volumes:
|
||||||
netbox-static-files:
|
netbox-static-files:
|
||||||
driver: local
|
driver: local
|
||||||
netbox-nginx-config:
|
netbox-nginx-config:
|
||||||
driver: local
|
driver: local
|
||||||
netbox-media-files:
|
netbox-media-files:
|
||||||
driver: local
|
driver: local
|
||||||
netbox-report-files:
|
netbox-report-files:
|
||||||
driver: local
|
driver: local
|
||||||
netbox-postgres-data:
|
netbox-postgres-data:
|
||||||
driver: local
|
driver: local
|
||||||
|
netbox-redis-data:
|
||||||
|
driver: local
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
|
daemon off;
|
||||||
worker_processes 1;
|
worker_processes 1;
|
||||||
|
|
||||||
|
error_log /dev/stderr info;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections 1024;
|
worker_connections 1024;
|
||||||
}
|
}
|
||||||
@ -16,7 +19,6 @@ http {
|
|||||||
|
|
||||||
server {
|
server {
|
||||||
listen 8080;
|
listen 8080;
|
||||||
server_name localhost;
|
|
||||||
access_log off;
|
access_log off;
|
||||||
|
|
||||||
location /static/ {
|
location /static/ {
|
||||||
|
3
netbox.env → env/netbox.env
vendored
3
netbox.env → env/netbox.env
vendored
@ -13,8 +13,11 @@ NAPALM_USERNAME=
|
|||||||
NAPALM_PASSWORD=
|
NAPALM_PASSWORD=
|
||||||
NAPALM_TIMEOUT=10
|
NAPALM_TIMEOUT=10
|
||||||
MAX_PAGE_SIZE=0
|
MAX_PAGE_SIZE=0
|
||||||
|
REDIS_HOST=redis
|
||||||
|
REDIS_PASSWORD=H733Kdjndks81
|
||||||
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
|
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
|
||||||
SUPERUSER_NAME=admin
|
SUPERUSER_NAME=admin
|
||||||
SUPERUSER_EMAIL=admin@example.com
|
SUPERUSER_EMAIL=admin@example.com
|
||||||
SUPERUSER_PASSWORD=admin
|
SUPERUSER_PASSWORD=admin
|
||||||
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
|
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
|
||||||
|
WEBHOOKS_ENABLED=true
|
0
postgres.env → env/postgres.env
vendored
0
postgres.env → env/postgres.env
vendored
1
env/redis.env
vendored
Normal file
1
env/redis.env
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
REDIS_PASSWORD=H733Kdjndks81
|
@ -7,6 +7,8 @@
|
|||||||
# on_objects:
|
# on_objects:
|
||||||
# - dcim.models.Device
|
# - dcim.models.Device
|
||||||
# - dcim.models.Rack
|
# - dcim.models.Rack
|
||||||
|
# - dcim.models.Site
|
||||||
|
# - dcim.models.DeviceType
|
||||||
# - ipam.models.IPAddress
|
# - ipam.models.IPAddress
|
||||||
# - ipam.models.Prefix
|
# - ipam.models.Prefix
|
||||||
# - tenancy.models.Tenant
|
# - tenancy.models.Tenant
|
||||||
|
15
initializers/device_roles.yml
Normal file
15
initializers/device_roles.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# - name: switch
|
||||||
|
# slug: switch
|
||||||
|
# color: Grey
|
||||||
|
# - name: router
|
||||||
|
# slug: router
|
||||||
|
# color: Cyan
|
||||||
|
# - name: load-balancer
|
||||||
|
# slug: load-balancer
|
||||||
|
# color: Red
|
||||||
|
# - name: server
|
||||||
|
# slug: server
|
||||||
|
# color: Blue
|
||||||
|
# - name: patchpanel
|
||||||
|
# slug: patchpanel
|
||||||
|
# color: Black
|
23
initializers/device_types.yml
Normal file
23
initializers/device_types.yml
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# - model: Model 1
|
||||||
|
# manufacturer: Manufacturer 1
|
||||||
|
# slug: model-1
|
||||||
|
# u_height: 2
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - model: Model 2
|
||||||
|
# manufacturer: Manufacturer 1
|
||||||
|
# slug: model-2
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - model: Model 3
|
||||||
|
# manufacturer: Manufacturer 1
|
||||||
|
# slug: model-3
|
||||||
|
# is_full_depth: false
|
||||||
|
# u_height: 0
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - model: Other
|
||||||
|
# manufacturer: NoName
|
||||||
|
# slug: other
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
27
initializers/devices.yml
Normal file
27
initializers/devices.yml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# - name: server01
|
||||||
|
# device_role: server
|
||||||
|
# device_type: Other
|
||||||
|
# site: AMS 1
|
||||||
|
# rack: rack-01
|
||||||
|
# face: Front
|
||||||
|
# position: 1
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - name: server02
|
||||||
|
# device_role: server
|
||||||
|
# device_type: Other
|
||||||
|
# site: AMS 2
|
||||||
|
# rack: rack-02
|
||||||
|
# face: Front
|
||||||
|
# position: 2
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - name: server03
|
||||||
|
# device_role: server
|
||||||
|
# device_type: Other
|
||||||
|
# site: SING 1
|
||||||
|
# rack: rack-03
|
||||||
|
# face: Front
|
||||||
|
# position: 3
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
@ -7,3 +7,10 @@
|
|||||||
# writers:
|
# writers:
|
||||||
# users:
|
# users:
|
||||||
# - writer
|
# - writer
|
||||||
|
# permissions:
|
||||||
|
# - add_device
|
||||||
|
# - change_device
|
||||||
|
# - delete_device
|
||||||
|
# - add_virtualmachine
|
||||||
|
# - change_virtualmachine
|
||||||
|
# - delete_virtualmachine
|
||||||
|
6
initializers/manufacturers.yml
Normal file
6
initializers/manufacturers.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# - name: Manufacturer 1
|
||||||
|
# slug: manufacturer-1
|
||||||
|
# - name: Manufacturer 2
|
||||||
|
# slug: manufacturer-2
|
||||||
|
# - name: NoName
|
||||||
|
# slug: noname
|
19
initializers/platforms.yml
Normal file
19
initializers/platforms.yml
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# # Allowed rpc clients are: juniper-junos, cisco-ios, opengear
|
||||||
|
# - name: Platform 1
|
||||||
|
# slug: platform-1
|
||||||
|
# manufacturer: Manufacturer 1
|
||||||
|
# napalm_driver: driver1
|
||||||
|
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}"
|
||||||
|
# rpc_client: juniper-junos
|
||||||
|
# - name: Platform 2
|
||||||
|
# slug: platform-2
|
||||||
|
# manufacturer: Manufacturer 2
|
||||||
|
# napalm_driver: driver2
|
||||||
|
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}"
|
||||||
|
# rpc_client: opengear
|
||||||
|
# - name: Platform 3
|
||||||
|
# slug: platform-3
|
||||||
|
# manufacturer: NoName
|
||||||
|
# napalm_driver: driver3
|
||||||
|
# napalm_args: "{'arg1': 'value1', 'arg2': 'value2'}"
|
||||||
|
# rpc_client: juniper-junos
|
12
initializers/rack_roles.yml
Normal file
12
initializers/rack_roles.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# - name: Role 1
|
||||||
|
# slug: role-1
|
||||||
|
# color: Pink
|
||||||
|
# - name: Role 2
|
||||||
|
# slug: role-2
|
||||||
|
# color: Cyan
|
||||||
|
# - name: Role 3
|
||||||
|
# slug: role-3
|
||||||
|
# color: Grey
|
||||||
|
# - name: Role 4
|
||||||
|
# slug: role-4
|
||||||
|
# color: Teal
|
24
initializers/racks.yml
Normal file
24
initializers/racks.yml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# - site: AMS 1
|
||||||
|
# name: rack-01
|
||||||
|
# role: Role 1
|
||||||
|
# type: 4-post cabinet
|
||||||
|
# width: 19 inches
|
||||||
|
# u_height: 47
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - site: AMS 2
|
||||||
|
# name: rack-02
|
||||||
|
# role: Role 2
|
||||||
|
# type: 4-post cabinet
|
||||||
|
# width: 19 inches
|
||||||
|
# u_height: 47
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - site: SING 1
|
||||||
|
# name: rack-03
|
||||||
|
# role: Role 3
|
||||||
|
# type: 4-post cabinet
|
||||||
|
# width: 19 inches
|
||||||
|
# u_height: 47
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
10
initializers/regions.yml
Normal file
10
initializers/regions.yml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# - name: Singapore
|
||||||
|
# slug: singapore
|
||||||
|
# - name: Amsterdam
|
||||||
|
# slug: amsterdam
|
||||||
|
# - name: Downtown
|
||||||
|
# slug: downtown
|
||||||
|
# parent: Amsterdam
|
||||||
|
# - name: Suburbs
|
||||||
|
# slug: suburbs
|
||||||
|
# parent: Amsterdam
|
32
initializers/sites.yml
Normal file
32
initializers/sites.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# - name: AMS 1
|
||||||
|
# slug: ams1
|
||||||
|
# region: Downtown
|
||||||
|
# status: 1
|
||||||
|
# facility: Amsterdam 1
|
||||||
|
# asn: 12345
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - name: AMS 2
|
||||||
|
# slug: ams2
|
||||||
|
# region: Downtown
|
||||||
|
# status: 1
|
||||||
|
# facility: Amsterdam 2
|
||||||
|
# asn: 54321
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - name: AMS 3
|
||||||
|
# slug: ams3
|
||||||
|
# region: Suburbs
|
||||||
|
# status: 1
|
||||||
|
# facility: Amsterdam 3
|
||||||
|
# asn: 67890
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
||||||
|
# - name: SING 1
|
||||||
|
# slug: sing1
|
||||||
|
# region: Singapore
|
||||||
|
# status: 1
|
||||||
|
# facility: Singapore 1
|
||||||
|
# asn: 09876
|
||||||
|
# custom_fields:
|
||||||
|
# text_field: Description
|
@ -4,3 +4,10 @@
|
|||||||
# password: reader
|
# password: reader
|
||||||
# writer:
|
# writer:
|
||||||
# password: writer
|
# password: writer
|
||||||
|
# permissions:
|
||||||
|
# - add_device
|
||||||
|
# - change_device
|
||||||
|
# - delete_device
|
||||||
|
# - add_virtualmachine
|
||||||
|
# - change_virtualmachine
|
||||||
|
# - delete_virtualmachine
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import Permission, Group, User
|
||||||
from users.models import Token
|
from users.models import Token
|
||||||
|
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
@ -18,3 +18,11 @@ with open('/opt/netbox/initializers/users.yml', 'r') as stream:
|
|||||||
|
|
||||||
if user_details.get('api_token', 0):
|
if user_details.get('api_token', 0):
|
||||||
Token.objects.create(user=user, key=user_details['api_token'])
|
Token.objects.create(user=user, key=user_details['api_token'])
|
||||||
|
|
||||||
|
user_permissions = user_details.get('permissions', [])
|
||||||
|
if user_permissions:
|
||||||
|
user.user_permissions.clear()
|
||||||
|
for permission_codename in user_details.get('permissions', []):
|
||||||
|
permission = Permission.objects.get(codename=permission_codename)
|
||||||
|
user.user_permissions.add(permission)
|
||||||
|
user.save()
|
27
startup_scripts/010_groups.py
Normal file
27
startup_scripts/010_groups.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
from django.contrib.auth.models import Permission, Group, User
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/groups.yml', 'r') as stream:
|
||||||
|
yaml=YAML(typ='safe')
|
||||||
|
groups = yaml.load(stream)
|
||||||
|
|
||||||
|
if groups is not None:
|
||||||
|
for groupname, group_details in groups.items():
|
||||||
|
group, created = Group.objects.get_or_create(name=groupname)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("👥 Created group", groupname)
|
||||||
|
|
||||||
|
for username in group_details.get('users', []):
|
||||||
|
user = User.objects.get(username=username)
|
||||||
|
|
||||||
|
if user:
|
||||||
|
user.groups.add(group)
|
||||||
|
|
||||||
|
group_permissions = group_details.get('permissions', [])
|
||||||
|
if group_permissions:
|
||||||
|
group.permissions.clear()
|
||||||
|
print("Permissions:", group.permissions.all())
|
||||||
|
for permission_codename in group_details.get('permissions', []):
|
||||||
|
permission = Permission.objects.get(codename=permission_codename)
|
||||||
|
group.permissions.add(permission)
|
25
startup_scripts/030_regions.py
Normal file
25
startup_scripts/030_regions.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from dcim.models import Region
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/regions.yml', 'r') as stream:
|
||||||
|
yaml=YAML(typ='safe')
|
||||||
|
regions = yaml.load(stream)
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'parent': (Region, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
if regions is not None:
|
||||||
|
for params in regions:
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
region, created = Region.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🌐 Created region", region.name)
|
40
startup_scripts/040_sites.py
Normal file
40
startup_scripts/040_sites.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
from dcim.models import Region, Site
|
||||||
|
from extras.models import CustomField, CustomFieldValue
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/sites.yml', 'r') as stream:
|
||||||
|
yaml = YAML(typ='safe')
|
||||||
|
sites = yaml.load(stream)
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'region': (Region, 'name'),
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
if sites is not None:
|
||||||
|
for params in sites:
|
||||||
|
custom_fields = params.pop('custom_fields', None)
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
site, created = Site.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
if custom_fields is not None:
|
||||||
|
for cf_name, cf_value in custom_fields.items():
|
||||||
|
custom_field = CustomField.objects.get(name=cf_name)
|
||||||
|
custom_field_value = CustomFieldValue.objects.create(
|
||||||
|
field=custom_field,
|
||||||
|
obj=site,
|
||||||
|
value=cf_value
|
||||||
|
)
|
||||||
|
|
||||||
|
site.custom_field_values.add(custom_field_value)
|
||||||
|
|
||||||
|
print("📍 Created site", site.name)
|
13
startup_scripts/050_manufacturers.py
Normal file
13
startup_scripts/050_manufacturers.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from dcim.models import Manufacturer
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/manufacturers.yml', 'r') as stream:
|
||||||
|
yaml = YAML(typ='safe')
|
||||||
|
manufacturers = yaml.load(stream)
|
||||||
|
|
||||||
|
if manufacturers is not None:
|
||||||
|
for params in manufacturers:
|
||||||
|
manufacturer, created = Manufacturer.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🏭 Created Manufacturer", manufacturer.name)
|
51
startup_scripts/060_device_types.py
Normal file
51
startup_scripts/060_device_types.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
from dcim.models import DeviceType, Manufacturer, Region
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from extras.models import CustomField, CustomFieldValue
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/device_types.yml', 'r') as stream:
|
||||||
|
yaml = YAML(typ='safe')
|
||||||
|
device_types = yaml.load(stream)
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'manufacturer': (Manufacturer, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'region': (Region, 'name'),
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
if device_types is not None:
|
||||||
|
for params in device_types:
|
||||||
|
custom_fields = params.pop('custom_fields', None)
|
||||||
|
|
||||||
|
for assoc, details in required_assocs.items():
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
device_type, created = DeviceType.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
if custom_fields is not None:
|
||||||
|
for cf_name, cf_value in custom_fields.items():
|
||||||
|
custom_field = CustomField.objects.get(name=cf_name)
|
||||||
|
custom_field_value = CustomFieldValue.objects.create(
|
||||||
|
field=custom_field,
|
||||||
|
obj=device_type,
|
||||||
|
value=cf_value
|
||||||
|
)
|
||||||
|
|
||||||
|
device_type.custom_field_values.add(custom_field_value)
|
||||||
|
|
||||||
|
print("🔡 Created device type", device_type.manufacturer, device_type.model)
|
||||||
|
|
21
startup_scripts/070_rack_roles.py
Normal file
21
startup_scripts/070_rack_roles.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from dcim.models import RackRole
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
from utilities.forms import COLOR_CHOICES
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/rack_roles.yml', 'r') as stream:
|
||||||
|
yaml=YAML(typ='safe')
|
||||||
|
rack_roles = yaml.load(stream)
|
||||||
|
|
||||||
|
if rack_roles is not None:
|
||||||
|
for params in rack_roles:
|
||||||
|
if 'color' in params:
|
||||||
|
color = params.pop('color')
|
||||||
|
|
||||||
|
for color_tpl in COLOR_CHOICES:
|
||||||
|
if color in color_tpl:
|
||||||
|
params['color'] = color_tpl[0]
|
||||||
|
|
||||||
|
rack_role, created = RackRole.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🎨 Created rack role", rack_role.name)
|
60
startup_scripts/080_racks.py
Normal file
60
startup_scripts/080_racks.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
from dcim.models import Site, RackRole, Rack, RackGroup
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from extras.models import CustomField, CustomFieldValue
|
||||||
|
from dcim.constants import RACK_TYPE_CHOICES, RACK_WIDTH_CHOICES
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/racks.yml', 'r') as stream:
|
||||||
|
yaml = YAML(typ='safe')
|
||||||
|
racks = yaml.load(stream)
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'site': (Site, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'role': (RackRole, 'name'),
|
||||||
|
'tenant': (Tenant, 'name'),
|
||||||
|
'group': (RackGroup, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
if racks is not None:
|
||||||
|
for params in racks:
|
||||||
|
custom_fields = params.pop('custom_fields', None)
|
||||||
|
|
||||||
|
for assoc, details in required_assocs.items():
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
for rack_type in RACK_TYPE_CHOICES:
|
||||||
|
if params['type'] in rack_type:
|
||||||
|
params['type'] = rack_type[0]
|
||||||
|
|
||||||
|
for rack_width in RACK_WIDTH_CHOICES:
|
||||||
|
if params['width'] in rack_width:
|
||||||
|
params['width'] = rack_width[0]
|
||||||
|
|
||||||
|
rack, created = Rack.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
if custom_fields is not None:
|
||||||
|
for cf_name, cf_value in custom_fields.items():
|
||||||
|
custom_field = CustomField.objects.get(name=cf_name)
|
||||||
|
custom_field_value = CustomFieldValue.objects.create(
|
||||||
|
field=custom_field,
|
||||||
|
obj=rack,
|
||||||
|
value=cf_value
|
||||||
|
)
|
||||||
|
|
||||||
|
rack.custom_field_values.add(custom_field_value)
|
||||||
|
|
||||||
|
print("🔳 Created rack", rack.site, rack.name)
|
22
startup_scripts/090_device_roles.py
Normal file
22
startup_scripts/090_device_roles.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from dcim.models import DeviceRole
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
from utilities.forms import COLOR_CHOICES
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/device_roles.yml', 'r') as stream:
|
||||||
|
yaml=YAML(typ='safe')
|
||||||
|
device_roles = yaml.load(stream)
|
||||||
|
|
||||||
|
if device_roles is not None:
|
||||||
|
for params in device_roles:
|
||||||
|
|
||||||
|
if 'color' in params:
|
||||||
|
color = params.pop('color')
|
||||||
|
|
||||||
|
for color_tpl in COLOR_CHOICES:
|
||||||
|
if color in color_tpl:
|
||||||
|
params['color'] = color_tpl[0]
|
||||||
|
|
||||||
|
device_role, created = DeviceRole.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🎨 Created device role", device_role.name)
|
25
startup_scripts/100_platforms.py
Normal file
25
startup_scripts/100_platforms.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
from dcim.models import Manufacturer, Platform
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/platforms.yml', 'r') as stream:
|
||||||
|
yaml = YAML(typ='safe')
|
||||||
|
platforms = yaml.load(stream)
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'manufacturer': (Manufacturer, 'name'),
|
||||||
|
}
|
||||||
|
|
||||||
|
if platforms is not None:
|
||||||
|
for params in platforms:
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
platform, created = Platform.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("💾 Created platform", platform.name)
|
@ -1,19 +0,0 @@
|
|||||||
from django.contrib.auth.models import Group, User
|
|
||||||
from ruamel.yaml import YAML
|
|
||||||
|
|
||||||
with open('/opt/netbox/initializers/groups.yml', 'r') as stream:
|
|
||||||
yaml=YAML(typ='safe')
|
|
||||||
groups = yaml.load(stream)
|
|
||||||
|
|
||||||
if groups is not None:
|
|
||||||
for groupname, group_details in groups.items():
|
|
||||||
group, created = Group.objects.get_or_create(name=groupname)
|
|
||||||
|
|
||||||
if created:
|
|
||||||
print("👥 Created group", groupname)
|
|
||||||
|
|
||||||
for username in group_details['users']:
|
|
||||||
user = User.objects.get(username=username)
|
|
||||||
|
|
||||||
if user:
|
|
||||||
user.groups.add(group)
|
|
64
startup_scripts/110_devices.py
Normal file
64
startup_scripts/110_devices.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
from dcim.models import Site, Rack, DeviceRole, DeviceType, Device, Platform
|
||||||
|
from dcim.constants import RACK_FACE_CHOICES
|
||||||
|
from ipam.models import IPAddress
|
||||||
|
from virtualization.models import Cluster
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from extras.models import CustomField, CustomFieldValue
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
with open('/opt/netbox/initializers/devices.yml', 'r') as stream:
|
||||||
|
yaml = YAML(typ='safe')
|
||||||
|
devices = yaml.load(stream)
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'device_role': (DeviceRole, 'name'),
|
||||||
|
'device_type': (DeviceType, 'model'),
|
||||||
|
'site': (Site, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name'),
|
||||||
|
'platform': (Platform, 'name'),
|
||||||
|
'rack': (Rack, 'name'),
|
||||||
|
'cluster': (Cluster, 'name'),
|
||||||
|
'primary_ip4': (IPAddress, 'address'),
|
||||||
|
'primary_ip6': (IPAddress, 'address')
|
||||||
|
}
|
||||||
|
|
||||||
|
if devices is not None:
|
||||||
|
for params in devices:
|
||||||
|
custom_fields = params.pop('custom_fields', None)
|
||||||
|
|
||||||
|
for assoc, details in required_assocs.items():
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
|
||||||
|
if 'face' in params:
|
||||||
|
for rack_face in RACK_FACE_CHOICES:
|
||||||
|
if params['face'] in rack_face:
|
||||||
|
params['face'] = rack_face[0]
|
||||||
|
|
||||||
|
device, created = Device.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
if custom_fields is not None:
|
||||||
|
for cf_name, cf_value in custom_fields.items():
|
||||||
|
custom_field = CustomField.objects.get(name=cf_name)
|
||||||
|
custom_field_value = CustomFieldValue.objects.create(
|
||||||
|
field=custom_field,
|
||||||
|
obj=device,
|
||||||
|
value=cf_value
|
||||||
|
)
|
||||||
|
|
||||||
|
device.custom_field_values.add(custom_field_value)
|
||||||
|
|
||||||
|
print("🖥️ Created device", device.name)
|
Reference in New Issue
Block a user