Compare commits
137 Commits
Author | SHA1 | Date | |
---|---|---|---|
4dd7a51c7d | |||
c7e259e116 | |||
3cbe07cb0e | |||
70b38d52b9 | |||
a21d146b60 | |||
6e7a64bd81 | |||
f8360ba6aa | |||
bab8373f66 | |||
ad93c99f46 | |||
ed6256172f | |||
5109e340ca | |||
62d31fda58 | |||
ed141c8a4e | |||
4d8d02e35a | |||
96132e1dcc | |||
896651ed97 | |||
f810d0342d | |||
323e18278a | |||
a0f7737916 | |||
7f8cc76af6 | |||
21bd7f426c | |||
3758bc805a | |||
72859ca71a | |||
0022392f03 | |||
385c66e30d | |||
65023a7dd4 | |||
426adb2333 | |||
584566b0f0 | |||
5399f8c890 | |||
2372c1eeff | |||
788aeacd9b | |||
00fa1793d0 | |||
4260e9b864 | |||
02713e1465 | |||
728a16c93d | |||
742560c571 | |||
d273391773 | |||
380cb77080 | |||
92b6608403 | |||
94509f86d7 | |||
818266ace1 | |||
dfb0327340 | |||
e3946af27c | |||
8d8c58df54 | |||
cbaaffc589 | |||
0f1cc9eea0 | |||
90018fc6d7 | |||
621fa12934 | |||
3094665092 | |||
31f52041f8 | |||
6ab38472be | |||
aa4d630a0f | |||
4e8588accf | |||
07469b2b72 | |||
a7c1d9f550 | |||
5605b9b218 | |||
b92c652d99 | |||
d77b3c1222 | |||
e383fd42bd | |||
234baa40a5 | |||
77d3dcded0 | |||
349e269356 | |||
5c9bea8b50 | |||
036f94a450 | |||
9d51762161 | |||
4276c941eb | |||
3cbdf26773 | |||
fbfce46ce5 | |||
255889288c | |||
c068db1751 | |||
378784a19c | |||
dcb3b5495d | |||
60f4e8b2ed | |||
a51ad36801 | |||
953ee09b0c | |||
94047d60ed | |||
80bfd98000 | |||
7694fd320a | |||
097bea8702 | |||
a3c21ae0ac | |||
074960327b | |||
e1462d9ca4 | |||
a5aa1bfd3b | |||
cb02450783 | |||
8307560c88 | |||
43aea3a1dd | |||
bb2ac7bd71 | |||
30a98c5009 | |||
a52a5547be | |||
120a605d35 | |||
e51f9cbc18 | |||
071401b771 | |||
911488242f | |||
5512ea68b3 | |||
7d055fbcaf | |||
3d244a1946 | |||
e18d6c53b3 | |||
48decdeb0e | |||
6ac65a64c9 | |||
f46d8a7782 | |||
64d82b5e42 | |||
58050e5287 | |||
2dba2b8811 | |||
d0c7b87925 | |||
ec3fd8a790 | |||
75554ef5b4 | |||
dad0608834 | |||
dc77f1a0b1 | |||
16b567939c | |||
20820e10c2 | |||
553c8ea470 | |||
811618b359 | |||
7429835970 | |||
43c05d816d | |||
fd3d3d11d1 | |||
121c3f800d | |||
9287995df4 | |||
85fbb0af70 | |||
6bada6660a | |||
df3ab69c0f | |||
38f4474b14 | |||
51331621ab | |||
156681f68d | |||
9f4a9f528c | |||
cad803ed31 | |||
9efaccadf7 | |||
f553d17655 | |||
2b361c4541 | |||
c744603a85 | |||
1133ef50de | |||
b33a509e25 | |||
79f0b997f3 | |||
32cef1dcf8 | |||
74833a9b21 | |||
a68f315acb | |||
df72d6bbb5 | |||
a9232e4f30 |
14
.github/FUNDING.yml
vendored
Normal file
14
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||||
|
- cimnine
|
||||||
|
- tobiasge
|
||||||
|
patreon: # Replace with a single Patreon username
|
||||||
|
open_collective: # Replace with a single Open Collective username
|
||||||
|
ko_fi: # Replace with a single Ko-fi username
|
||||||
|
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||||
|
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||||
|
liberapay: # Replace with a single Liberapay username
|
||||||
|
issuehunt: # Replace with a single IssueHunt username
|
||||||
|
otechie: # Replace with a single Otechie username
|
||||||
|
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -65,13 +65,3 @@ If your log is very long, create a Gist instead (and post the link to it): https
|
|||||||
```text
|
```text
|
||||||
LOG LOG LOG
|
LOG LOG LOG
|
||||||
```
|
```
|
||||||
|
|
||||||
The output of `docker-compose logs nginx`:
|
|
||||||
<!--
|
|
||||||
Only if you have gotten a 5xx http error, else delete this section.
|
|
||||||
If your log is very long, create a Gist instead (and post the link to it): https://gist.github.com
|
|
||||||
-->
|
|
||||||
|
|
||||||
```text
|
|
||||||
LOG LOG LOG
|
|
||||||
```
|
|
||||||
|
13
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
13
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: The \#netbox-docker Slack channel
|
||||||
|
url: http://slack.networktocode.com/
|
||||||
|
about: It's usually the quickest way to seek help when you're in trouble with regards to Netbox Docker.
|
||||||
|
|
||||||
|
- name: Github Discussions
|
||||||
|
url: https://github.com/netbox-community/netbox-docker/discussions
|
||||||
|
about: This is the right place to ask questions about how to use or do certain things with Netbox Docker.
|
||||||
|
|
||||||
|
- name: Have you had a look at our Wiki?
|
||||||
|
url: https://github.com/netbox-community/netbox-docker/wiki
|
||||||
|
about: Our wiki contains information for common problems and tips for operating Netbox Docker in production.
|
9
.github/workflows/push.yml
vendored
9
.github/workflows/push.yml
vendored
@ -10,6 +10,7 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
continue-on-error: ${{ matrix.docker_from == 'alpine:edge' }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
build_cmd:
|
build_cmd:
|
||||||
@ -18,17 +19,15 @@ jobs:
|
|||||||
- ./build-next.sh
|
- ./build-next.sh
|
||||||
- ./build.sh develop
|
- ./build.sh develop
|
||||||
docker_from:
|
docker_from:
|
||||||
- '' # use the default of the DOCKERFILE
|
- '' # use the default of the build script
|
||||||
- python:3.7-alpine
|
- alpine:edge
|
||||||
- python:3.8-alpine
|
|
||||||
# - python:3.9-rc-alpine # disable until Netbox's unit tests work
|
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: Builds new Netbox Docker Images
|
name: Builds new Netbox Docker Images
|
||||||
steps:
|
steps:
|
||||||
- id: git-checkout
|
- id: git-checkout
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v1
|
uses: actions/checkout@v2
|
||||||
- id: docker-build
|
- id: docker-build
|
||||||
name: Build the image from '${{ matrix.docker_from }}' with '${{ matrix.build_cmd }}'
|
name: Build the image from '${{ matrix.docker_from }}' with '${{ matrix.build_cmd }}'
|
||||||
run: ${{ matrix.build_cmd }}
|
run: ${{ matrix.build_cmd }}
|
||||||
|
31
.github/workflows/release.yml
vendored
31
.github/workflows/release.yml
vendored
@ -50,3 +50,34 @@ jobs:
|
|||||||
name: Logout of the Docker Registry
|
name: Logout of the Docker Registry
|
||||||
run: docker logout "${DOCKER_REGISTRY}"
|
run: docker logout "${DOCKER_REGISTRY}"
|
||||||
if: steps.docker-build.outputs.skipped != 'true'
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
|
||||||
|
# Quay.io
|
||||||
|
- id: quayio-docker-build
|
||||||
|
name: Build the image with '${{ matrix.build_cmd }}'
|
||||||
|
run: ${{ matrix.build_cmd }}
|
||||||
|
env:
|
||||||
|
DOCKER_REGISTRY: quay.io
|
||||||
|
GH_ACTION: enable
|
||||||
|
- id: quayio-registry-login
|
||||||
|
name: Login to the Quay.io Registry
|
||||||
|
run: |
|
||||||
|
echo "::add-mask::$QUAYIO_USERNAME"
|
||||||
|
echo "::add-mask::$QUAYIO_PASSWORD"
|
||||||
|
docker login -u "$QUAYIO_USERNAME" --password "${QUAYIO_PASSWORD}" "${DOCKER_REGISTRY}"
|
||||||
|
env:
|
||||||
|
DOCKER_REGISTRY: quay.io
|
||||||
|
QUAYIO_USERNAME: ${{ secrets.quayio_username }}
|
||||||
|
QUAYIO_PASSWORD: ${{ secrets.quayio_password }}
|
||||||
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
- id: quayio-registry-push
|
||||||
|
name: Push the image
|
||||||
|
run: ${{ matrix.build_cmd }} --push-only
|
||||||
|
env:
|
||||||
|
DOCKER_REGISTRY: quay.io
|
||||||
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
- id: quayio-registry-logout
|
||||||
|
name: Logout of the Docker Registry
|
||||||
|
run: docker logout "${DOCKER_REGISTRY}"
|
||||||
|
env:
|
||||||
|
DOCKER_REGISTRY: quay.io
|
||||||
|
if: steps.docker-build.outputs.skipped != 'true'
|
||||||
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -3,3 +3,9 @@
|
|||||||
.initializers
|
.initializers
|
||||||
docker-compose.override.yml
|
docker-compose.override.yml
|
||||||
*.pem
|
*.pem
|
||||||
|
configuration/*
|
||||||
|
!configuration/configuration.py
|
||||||
|
!configuration/extra.py
|
||||||
|
configuration/ldap/*
|
||||||
|
!configuration/ldap/ldap_config.py
|
||||||
|
prometheus.yml
|
||||||
|
51
Dockerfile
51
Dockerfile
@ -12,27 +12,15 @@ RUN apk add --no-cache \
|
|||||||
libffi-dev \
|
libffi-dev \
|
||||||
libxslt-dev \
|
libxslt-dev \
|
||||||
openldap-dev \
|
openldap-dev \
|
||||||
postgresql-dev
|
postgresql-dev \
|
||||||
|
py3-pip \
|
||||||
WORKDIR /install
|
python3-dev \
|
||||||
|
&& python3 -m venv /opt/netbox/venv \
|
||||||
RUN pip install --prefix="/install" --no-warn-script-location \
|
&& /opt/netbox/venv/bin/python3 -m pip install --upgrade pip setuptools
|
||||||
# gunicorn is used for launching netbox
|
|
||||||
gunicorn \
|
|
||||||
greenlet \
|
|
||||||
eventlet \
|
|
||||||
# napalm is used for gathering information from network devices
|
|
||||||
napalm \
|
|
||||||
# ruamel is used in startup_scripts
|
|
||||||
'ruamel.yaml>=0.15,<0.16' \
|
|
||||||
# django_auth_ldap is required for ldap
|
|
||||||
django_auth_ldap \
|
|
||||||
# django-storages was introduced in 2.7 and is optional
|
|
||||||
django-storages
|
|
||||||
|
|
||||||
ARG NETBOX_PATH
|
ARG NETBOX_PATH
|
||||||
COPY ${NETBOX_PATH}/requirements.txt /
|
COPY ${NETBOX_PATH}/requirements.txt requirements-container.txt /
|
||||||
RUN pip install --prefix="/install" --no-warn-script-location -r /requirements.txt
|
RUN /opt/netbox/venv/bin/pip install -r /requirements.txt -r /requirements-container.txt
|
||||||
|
|
||||||
###
|
###
|
||||||
# Main stage
|
# Main stage
|
||||||
@ -44,6 +32,7 @@ FROM ${FROM} as main
|
|||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
bash \
|
bash \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
curl \
|
||||||
graphviz \
|
graphviz \
|
||||||
libevent \
|
libevent \
|
||||||
libffi \
|
libffi \
|
||||||
@ -51,35 +40,38 @@ RUN apk add --no-cache \
|
|||||||
libressl \
|
libressl \
|
||||||
libxslt \
|
libxslt \
|
||||||
postgresql-libs \
|
postgresql-libs \
|
||||||
ttf-ubuntu-font-family
|
python3 \
|
||||||
|
py3-pip \
|
||||||
|
ttf-ubuntu-font-family \
|
||||||
|
unit \
|
||||||
|
unit-python3
|
||||||
|
|
||||||
WORKDIR /opt
|
WORKDIR /opt
|
||||||
|
|
||||||
COPY --from=builder /install /usr/local
|
COPY --from=builder /opt/netbox/venv /opt/netbox/venv
|
||||||
|
|
||||||
ARG NETBOX_PATH
|
ARG NETBOX_PATH
|
||||||
COPY ${NETBOX_PATH} /opt/netbox
|
COPY ${NETBOX_PATH} /opt/netbox
|
||||||
|
|
||||||
COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
|
COPY docker/configuration.docker.py /opt/netbox/netbox/netbox/configuration.py
|
||||||
COPY configuration/gunicorn_config.py /etc/netbox/config/
|
|
||||||
COPY docker/nginx.conf /etc/netbox-nginx/nginx.conf
|
|
||||||
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
|
COPY docker/docker-entrypoint.sh /opt/netbox/docker-entrypoint.sh
|
||||||
|
COPY docker/launch-netbox.sh /opt/netbox/launch-netbox.sh
|
||||||
COPY startup_scripts/ /opt/netbox/startup_scripts/
|
COPY startup_scripts/ /opt/netbox/startup_scripts/
|
||||||
COPY initializers/ /opt/netbox/initializers/
|
COPY initializers/ /opt/netbox/initializers/
|
||||||
COPY configuration/configuration.py /etc/netbox/config/configuration.py
|
COPY configuration/ /etc/netbox/config/
|
||||||
|
COPY docker/nginx-unit.json /etc/unit/
|
||||||
|
|
||||||
WORKDIR /opt/netbox/netbox
|
WORKDIR /opt/netbox/netbox
|
||||||
|
|
||||||
# Must set permissions for '/opt/netbox/netbox/static' directory
|
|
||||||
# to g+w so that `./manage.py collectstatic` can be executed during
|
|
||||||
# container startup.
|
|
||||||
# Must set permissions for '/opt/netbox/netbox/media' directory
|
# Must set permissions for '/opt/netbox/netbox/media' directory
|
||||||
# to g+w so that pictures can be uploaded to netbox.
|
# to g+w so that pictures can be uploaded to netbox.
|
||||||
RUN mkdir static && chmod -R g+w static media
|
RUN mkdir -p static /opt/unit/state/ /opt/unit/tmp/ \
|
||||||
|
&& chmod -R g+w media /opt/unit/ \
|
||||||
|
&& SECRET_KEY="dummy" /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py collectstatic --no-input
|
||||||
|
|
||||||
ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
|
ENTRYPOINT [ "/opt/netbox/docker-entrypoint.sh" ]
|
||||||
|
|
||||||
CMD ["gunicorn", "-c /etc/netbox/config/gunicorn_config.py", "netbox.wsgi"]
|
CMD [ "/opt/netbox/launch-netbox.sh" ]
|
||||||
|
|
||||||
LABEL ORIGINAL_TAG="" \
|
LABEL ORIGINAL_TAG="" \
|
||||||
NETBOX_GIT_BRANCH="" \
|
NETBOX_GIT_BRANCH="" \
|
||||||
@ -122,4 +114,3 @@ RUN apk add --no-cache \
|
|||||||
util-linux
|
util-linux
|
||||||
|
|
||||||
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
|
COPY docker/ldap_config.docker.py /opt/netbox/netbox/netbox/ldap_config.py
|
||||||
COPY configuration/ldap_config.py /etc/netbox/config/ldap_config.py
|
|
||||||
|
17
README.md
17
README.md
@ -10,7 +10,7 @@
|
|||||||
[][netbox-docker-license]
|
[][netbox-docker-license]
|
||||||
|
|
||||||
[The Github repository](netbox-docker-github) houses the components needed to build Netbox as a Docker container.
|
[The Github repository](netbox-docker-github) houses the components needed to build Netbox as a Docker container.
|
||||||
Images are built using this code and are released to [Docker Hub][netbox-dockerhub] once a day.
|
Images are built using this code and are released to [Docker Hub][netbox-dockerhub] and [Quay.io][netbox-quayio] once a day.
|
||||||
|
|
||||||
Do you have any questions?
|
Do you have any questions?
|
||||||
Before opening an issue on Github, please join the [Network To Code][ntc-slack] Slack and ask for help in our [`#netbox-docker`][netbox-docker-slack] channel.
|
Before opening an issue on Github, please join the [Network To Code][ntc-slack] Slack and ask for help in our [`#netbox-docker`][netbox-docker-slack] channel.
|
||||||
@ -18,11 +18,12 @@ Before opening an issue on Github, please join the [Network To Code][ntc-slack]
|
|||||||
[github-stargazers]: https://github.com/netbox-community/netbox-docker/stargazers
|
[github-stargazers]: https://github.com/netbox-community/netbox-docker/stargazers
|
||||||
[github-release]: https://github.com/netbox-community/netbox-docker/releases
|
[github-release]: https://github.com/netbox-community/netbox-docker/releases
|
||||||
[netbox-docker-microbadger]: https://microbadger.com/images/netboxcommunity/netbox
|
[netbox-docker-microbadger]: https://microbadger.com/images/netboxcommunity/netbox
|
||||||
[netbox-dockerhub]: https://hub.docker.com/r/netboxcommunity/netbox/tags/
|
[netbox-dockerhub]: https://hub.docker.com/r/netboxcommunity/netbox/
|
||||||
[netbox-docker-github]: https://github.com/netbox-community/netbox-docker/
|
[netbox-docker-github]: https://github.com/netbox-community/netbox-docker/
|
||||||
[ntc-slack]: http://slack.networktocode.com/
|
[ntc-slack]: http://slack.networktocode.com/
|
||||||
[netbox-docker-slack]: https://slack.com/app_redirect?channel=netbox-docker&team=T09LQ7E9E
|
[netbox-docker-slack]: https://slack.com/app_redirect?channel=netbox-docker&team=T09LQ7E9E
|
||||||
[netbox-docker-license]: https://github.com/netbox-community/netbox-docker/blob/release/LICENSE
|
[netbox-docker-license]: https://github.com/netbox-community/netbox-docker/blob/release/LICENSE
|
||||||
|
[netbox-quayio]: https://quay.io/repository/netboxcommunity/netbox
|
||||||
|
|
||||||
## Docker Tags
|
## Docker Tags
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ cd netbox-docker
|
|||||||
tee docker-compose.override.yml <<EOF
|
tee docker-compose.override.yml <<EOF
|
||||||
version: '3.4'
|
version: '3.4'
|
||||||
services:
|
services:
|
||||||
nginx:
|
netbox:
|
||||||
ports:
|
ports:
|
||||||
- 8000:8080
|
- 8000:8080
|
||||||
EOF
|
EOF
|
||||||
@ -79,17 +80,19 @@ The default credentials are:
|
|||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Please refer [to our wiki on Github][netbox-docker-wiki] for further information on how to use this Netbox Docker image properly.
|
Please refer [to our wiki on Github][netbox-docker-wiki] for further information on how to use this Netbox Docker image properly.
|
||||||
It covers advanced topics such as using secret files, deployment to Kubernetes as well as NAPALM and LDAP configuration.
|
It covers advanced topics such as using files for secrets, deployment to Kubernetes, monitoring and configuring NAPALM or LDAP.
|
||||||
|
|
||||||
[netbox-docker-wiki]: https://github.com/netbox-community/netbox-docker/wiki/
|
[netbox-docker-wiki]: https://github.com/netbox-community/netbox-docker/wiki/
|
||||||
|
|
||||||
## Getting Help
|
## Getting Help
|
||||||
|
|
||||||
Please join [our Slack channel `#netbox-docker`][netbox-docker-slack] on the [Network To Code Slack][ntc-slack].
|
Feel free to ask questions in our [Github Community][netbox-community] or join [our Slack channel `#netbox-docker`][netbox-docker-slack] on the [Network To Code Slack][ntc-slack],
|
||||||
It's free to use and there are almost always people online that can help.
|
which is free to use and where there are almost always people online that can help you in the Slack channel.
|
||||||
|
|
||||||
If you need help with using Netbox or developing for it or against it's API you may find the `#netbox` channel on the same Slack instance very helpful.
|
If you need help with using Netbox or developing for it or against it's API you may find the `#netbox` channel on the same Slack instance very helpful.
|
||||||
|
|
||||||
|
[netbox-community]: https://github.com/netbox-community/netbox-docker/discussions
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
This project relies only on *Docker* and *docker-compose* meeting these requirements:
|
This project relies only on *Docker* and *docker-compose* meeting these requirements:
|
||||||
@ -104,7 +107,7 @@ To check the version installed on your system run `docker --version` and `docker
|
|||||||
The `docker-compose.yml` file is prepared to run a specific version of Netbox, instead of `latest`.
|
The `docker-compose.yml` file is prepared to run a specific version of Netbox, instead of `latest`.
|
||||||
To use this feature, set and export the environment-variable `VERSION` before launching `docker-compose`, as shown below.
|
To use this feature, set and export the environment-variable `VERSION` before launching `docker-compose`, as shown below.
|
||||||
`VERSION` may be set to the name of
|
`VERSION` may be set to the name of
|
||||||
[any tag of the `netboxcommunity/netbox` Docker image on Docker Hub][netbox-dockerhub].
|
[any tag of the `netboxcommunity/netbox` Docker image on Docker Hub][netbox-dockerhub] or [Quay.io][netbox-quayio].
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export VERSION=v2.7.1
|
export VERSION=v2.7.1
|
||||||
|
16
build.sh
16
build.sh
@ -49,7 +49,7 @@ if [ "${1}x" == "x" ] || [ "${1}" == "--help" ] || [ "${1}" == "-h" ]; then
|
|||||||
echo " DOCKERFILE The name of Dockerfile to use."
|
echo " DOCKERFILE The name of Dockerfile to use."
|
||||||
echo " Default: Dockerfile"
|
echo " Default: Dockerfile"
|
||||||
echo " DOCKER_FROM The base image to use."
|
echo " DOCKER_FROM The base image to use."
|
||||||
echo " Default: 'python:3.7-alpine'"
|
echo " Default: 'alpine:3.13'"
|
||||||
echo " DOCKER_TARGET A specific target to build."
|
echo " DOCKER_TARGET A specific target to build."
|
||||||
echo " It's currently not possible to pass multiple targets."
|
echo " It's currently not possible to pass multiple targets."
|
||||||
echo " Default: main ldap"
|
echo " Default: main ldap"
|
||||||
@ -106,7 +106,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
###
|
###
|
||||||
# Variables for fetching the source
|
# Variables for fetching the Netbox source
|
||||||
###
|
###
|
||||||
SRC_ORG="${SRC_ORG-netbox-community}"
|
SRC_ORG="${SRC_ORG-netbox-community}"
|
||||||
SRC_REPO="${SRC_REPO-netbox}"
|
SRC_REPO="${SRC_REPO-netbox}"
|
||||||
@ -115,10 +115,10 @@ URL="${URL-https://github.com/${SRC_ORG}/${SRC_REPO}.git}"
|
|||||||
NETBOX_PATH="${NETBOX_PATH-.netbox}"
|
NETBOX_PATH="${NETBOX_PATH-.netbox}"
|
||||||
|
|
||||||
###
|
###
|
||||||
# Fetching the source
|
# Fetching the Netbox source
|
||||||
###
|
###
|
||||||
if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ] ; then
|
if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ] ; then
|
||||||
echo "🌐 Checking out '${NETBOX_BRANCH}' of netbox from the url '${URL}' into '${NETBOX_PATH}'"
|
echo "🌐 Checking out '${NETBOX_BRANCH}' of Netbox from the url '${URL}' into '${NETBOX_PATH}'"
|
||||||
if [ ! -d "${NETBOX_PATH}" ]; then
|
if [ ! -d "${NETBOX_PATH}" ]; then
|
||||||
$DRY git clone -q --depth 10 -b "${NETBOX_BRANCH}" "${URL}" "${NETBOX_PATH}"
|
$DRY git clone -q --depth 10 -b "${NETBOX_BRANCH}" "${URL}" "${NETBOX_PATH}"
|
||||||
fi
|
fi
|
||||||
@ -135,7 +135,7 @@ if [ "${2}" != "--push-only" ] && [ -z "${SKIP_GIT}" ] ; then
|
|||||||
$DRY git checkout -qf FETCH_HEAD
|
$DRY git checkout -qf FETCH_HEAD
|
||||||
$DRY git prune
|
$DRY git prune
|
||||||
)
|
)
|
||||||
echo "✅ Checked out netbox"
|
echo "✅ Checked out Netbox"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###
|
###
|
||||||
@ -157,7 +157,7 @@ fi
|
|||||||
# Determining the value for DOCKER_FROM
|
# Determining the value for DOCKER_FROM
|
||||||
###
|
###
|
||||||
if [ -z "$DOCKER_FROM" ]; then
|
if [ -z "$DOCKER_FROM" ]; then
|
||||||
DOCKER_FROM="python:3.7-alpine"
|
DOCKER_FROM="alpine:3.13"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
###
|
###
|
||||||
@ -216,7 +216,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
|
|||||||
TARGET_DOCKER_TAG="${TARGET_DOCKER_TAG}-${DOCKER_TARGET}"
|
TARGET_DOCKER_TAG="${TARGET_DOCKER_TAG}-${DOCKER_TARGET}"
|
||||||
fi
|
fi
|
||||||
if [ -n "${GH_ACTION}" ]; then
|
if [ -n "${GH_ACTION}" ]; then
|
||||||
echo "::set-env name=FINAL_DOCKER_TAG::${TARGET_DOCKER_TAG}"
|
echo "FINAL_DOCKER_TAG=${TARGET_DOCKER_TAG}" >> $GITHUB_ENV
|
||||||
echo "::set-output name=skipped::false"
|
echo "::set-output name=skipped::false"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -271,7 +271,7 @@ for DOCKER_TARGET in "${DOCKER_TARGETS[@]}"; do
|
|||||||
|
|
||||||
if ! printf '%s\n' "${IMAGES_LAYERS_OLD[@]}" | grep -q -P "^${PYTHON_LAST_LAYER}\$"; then
|
if ! printf '%s\n' "${IMAGES_LAYERS_OLD[@]}" | grep -q -P "^${PYTHON_LAST_LAYER}\$"; then
|
||||||
SHOULD_BUILD="true"
|
SHOULD_BUILD="true"
|
||||||
BUILD_REASON="${BUILD_REASON} python"
|
BUILD_REASON="${BUILD_REASON} alpine"
|
||||||
fi
|
fi
|
||||||
if [ "${NETBOX_GIT_REF}" != "${NETBOX_GIT_REF_OLD}" ]; then
|
if [ "${NETBOX_GIT_REF}" != "${NETBOX_GIT_REF_OLD}" ]; then
|
||||||
SHOULD_BUILD="true"
|
SHOULD_BUILD="true"
|
||||||
|
@ -1,21 +1,28 @@
|
|||||||
import os
|
####
|
||||||
import re
|
## We recommend to not edit this file.
|
||||||
import socket
|
## Create separate files to overwrite the settings.
|
||||||
|
## See `extra.py` as an example.
|
||||||
|
####
|
||||||
|
|
||||||
# For reference see http://netbox.readthedocs.io/en/latest/configuration/mandatory-settings/
|
import re
|
||||||
# Based on https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/configuration.example.py
|
|
||||||
|
from os.path import dirname, abspath, join
|
||||||
|
from os import environ
|
||||||
|
|
||||||
|
# For reference see https://netbox.readthedocs.io/en/stable/configuration/
|
||||||
|
# Based on https://github.com/netbox-community/netbox/blob/master/netbox/netbox/configuration.example.py
|
||||||
|
|
||||||
# Read secret from file
|
# Read secret from file
|
||||||
def read_secret(secret_name):
|
def _read_secret(secret_name, default = None):
|
||||||
try:
|
try:
|
||||||
f = open('/run/secrets/' + secret_name, 'r', encoding='utf-8')
|
f = open('/run/secrets/' + secret_name, 'r', encoding='utf-8')
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
return ''
|
return default
|
||||||
else:
|
else:
|
||||||
with f:
|
with f:
|
||||||
return f.readline().strip()
|
return f.readline().strip()
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
_BASE_DIR = dirname(dirname(abspath(__file__)))
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# #
|
# #
|
||||||
@ -27,55 +34,49 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||||||
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
|
# access to the server via any other hostnames. The first FQDN in the list will be treated as the preferred name.
|
||||||
#
|
#
|
||||||
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
|
# Example: ALLOWED_HOSTS = ['netbox.example.com', 'netbox.internal.local']
|
||||||
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', '*').split(' ')
|
ALLOWED_HOSTS = environ.get('ALLOWED_HOSTS', '*').split(' ')
|
||||||
|
|
||||||
# PostgreSQL database configuration.
|
# PostgreSQL database configuration. See the Django documentation for a complete list of available parameters:
|
||||||
|
# https://docs.djangoproject.com/en/stable/ref/settings/#databases
|
||||||
DATABASE = {
|
DATABASE = {
|
||||||
'NAME': os.environ.get('DB_NAME', 'netbox'), # Database name
|
'NAME': environ.get('DB_NAME', 'netbox'), # Database name
|
||||||
'USER': os.environ.get('DB_USER', ''), # PostgreSQL username
|
'USER': environ.get('DB_USER', ''), # PostgreSQL username
|
||||||
'PASSWORD': os.environ.get('DB_PASSWORD', read_secret('db_password')),
|
'PASSWORD': _read_secret('db_password', environ.get('DB_PASSWORD', '')),
|
||||||
# PostgreSQL password
|
# PostgreSQL password
|
||||||
'HOST': os.environ.get('DB_HOST', 'localhost'), # Database server
|
'HOST': environ.get('DB_HOST', 'localhost'), # Database server
|
||||||
'PORT': os.environ.get('DB_PORT', ''), # Database port (leave blank for default)
|
'PORT': environ.get('DB_PORT', ''), # Database port (leave blank for default)
|
||||||
'OPTIONS': {'sslmode': os.environ.get('DB_SSLMODE', 'prefer')},
|
'OPTIONS': {'sslmode': environ.get('DB_SSLMODE', 'prefer')},
|
||||||
# Database connection SSLMODE
|
# Database connection SSLMODE
|
||||||
'CONN_MAX_AGE': int(os.environ.get('DB_CONN_MAX_AGE', '300')),
|
'CONN_MAX_AGE': int(environ.get('DB_CONN_MAX_AGE', '300')),
|
||||||
# Database connection persistence
|
# Max database connection age
|
||||||
|
}
|
||||||
|
|
||||||
|
# Redis database settings. Redis is used for caching and for queuing background tasks such as webhook events. A separate
|
||||||
|
# configuration exists for each. Full connection details are required in both sections, and it is strongly recommended
|
||||||
|
# to use two separate database IDs.
|
||||||
|
REDIS = {
|
||||||
|
'tasks': {
|
||||||
|
'HOST': environ.get('REDIS_HOST', 'localhost'),
|
||||||
|
'PORT': int(environ.get('REDIS_PORT', 6379)),
|
||||||
|
'PASSWORD': _read_secret('redis_password', environ.get('REDIS_PASSWORD', '')),
|
||||||
|
'DATABASE': int(environ.get('REDIS_DATABASE', 0)),
|
||||||
|
'SSL': environ.get('REDIS_SSL', 'False').lower() == 'true',
|
||||||
|
},
|
||||||
|
'caching': {
|
||||||
|
'HOST': environ.get('REDIS_CACHE_HOST', environ.get('REDIS_HOST', 'localhost')),
|
||||||
|
'PORT': int(environ.get('REDIS_CACHE_PORT', environ.get('REDIS_PORT', 6379))),
|
||||||
|
'PASSWORD': _read_secret('redis_cache_password', environ.get('REDIS_CACHE_PASSWORD', environ.get('REDIS_PASSWORD', ''))),
|
||||||
|
'DATABASE': int(environ.get('REDIS_CACHE_DATABASE', 1)),
|
||||||
|
'SSL': environ.get('REDIS_CACHE_SSL', environ.get('REDIS_SSL', 'False')).lower() == 'true',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
|
# This key is used for secure generation of random numbers and strings. It must never be exposed outside of this file.
|
||||||
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
|
# For optimal security, SECRET_KEY should be at least 50 characters in length and contain a mix of letters, numbers, and
|
||||||
# symbols. NetBox will not run without this defined. For more information, see
|
# symbols. NetBox will not run without this defined. For more information, see
|
||||||
# https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-SECRET_KEY
|
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-SECRET_KEY
|
||||||
SECRET_KEY = os.environ.get('SECRET_KEY', read_secret('secret_key'))
|
SECRET_KEY = _read_secret('secret_key', environ.get('SECRET_KEY', ''))
|
||||||
|
|
||||||
# Redis database settings. The Redis database is used for caching and background processing such as webhooks
|
|
||||||
REDIS = {
|
|
||||||
'tasks': {
|
|
||||||
'HOST': os.environ.get('REDIS_HOST', 'localhost'),
|
|
||||||
'PORT': int(os.environ.get('REDIS_PORT', 6379)),
|
|
||||||
'PASSWORD': os.environ.get('REDIS_PASSWORD', read_secret('redis_password')),
|
|
||||||
'DATABASE': int(os.environ.get('REDIS_DATABASE', 0)),
|
|
||||||
'DEFAULT_TIMEOUT': int(os.environ.get('REDIS_TIMEOUT', 300)),
|
|
||||||
'SSL': os.environ.get('REDIS_SSL', 'False').lower() == 'true',
|
|
||||||
},
|
|
||||||
'webhooks': { # legacy setting, can be removed after Netbox seizes support for it
|
|
||||||
'HOST': os.environ.get('REDIS_HOST', 'localhost'),
|
|
||||||
'PORT': int(os.environ.get('REDIS_PORT', 6379)),
|
|
||||||
'PASSWORD': os.environ.get('REDIS_PASSWORD', read_secret('redis_password')),
|
|
||||||
'DATABASE': int(os.environ.get('REDIS_DATABASE', 0)),
|
|
||||||
'DEFAULT_TIMEOUT': int(os.environ.get('REDIS_TIMEOUT', 300)),
|
|
||||||
'SSL': os.environ.get('REDIS_SSL', 'False').lower() == 'true',
|
|
||||||
},
|
|
||||||
'caching': {
|
|
||||||
'HOST': os.environ.get('REDIS_CACHE_HOST', os.environ.get('REDIS_HOST', 'localhost')),
|
|
||||||
'PORT': int(os.environ.get('REDIS_CACHE_PORT', os.environ.get('REDIS_PORT', 6379))),
|
|
||||||
'PASSWORD': os.environ.get('REDIS_CACHE_PASSWORD', os.environ.get('REDIS_PASSWORD', read_secret('redis_cache_password'))),
|
|
||||||
'DATABASE': int(os.environ.get('REDIS_CACHE_DATABASE', 1)),
|
|
||||||
'DEFAULT_TIMEOUT': int(os.environ.get('REDIS_CACHE_TIMEOUT', os.environ.get('REDIS_TIMEOUT', 300))),
|
|
||||||
'SSL': os.environ.get('REDIS_CACHE_SSL', os.environ.get('REDIS_SSL', 'False')).lower() == 'true',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# #
|
# #
|
||||||
@ -89,128 +90,159 @@ ADMINS = [
|
|||||||
# ['John Doe', 'jdoe@example.com'],
|
# ['John Doe', 'jdoe@example.com'],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# URL schemes that are allowed within links in NetBox
|
||||||
|
ALLOWED_URL_SCHEMES = (
|
||||||
|
'file', 'ftp', 'ftps', 'http', 'https', 'irc', 'mailto', 'sftp', 'ssh', 'tel', 'telnet', 'tftp', 'vnc', 'xmpp',
|
||||||
|
)
|
||||||
|
|
||||||
# Optionally display a persistent banner at the top and/or bottom of every page. HTML is allowed. To display the same
|
# Optionally display a persistent banner at the top and/or bottom of every page. HTML is allowed. To display the same
|
||||||
# content in both banners, define BANNER_TOP and set BANNER_BOTTOM = BANNER_TOP.
|
# content in both banners, define BANNER_TOP and set BANNER_BOTTOM = BANNER_TOP.
|
||||||
BANNER_TOP = os.environ.get('BANNER_TOP', '')
|
BANNER_TOP = environ.get('BANNER_TOP', '')
|
||||||
BANNER_BOTTOM = os.environ.get('BANNER_BOTTOM', '')
|
BANNER_BOTTOM = environ.get('BANNER_BOTTOM', '')
|
||||||
|
|
||||||
# Text to include on the login page above the login form. HTML is allowed.
|
# Text to include on the login page above the login form. HTML is allowed.
|
||||||
BANNER_LOGIN = os.environ.get('BANNER_LOGIN', '')
|
BANNER_LOGIN = environ.get('BANNER_LOGIN', '')
|
||||||
|
|
||||||
# Base URL path if accessing NetBox within a directory. For example, if installed at http://example.com/netbox/, set:
|
# Base URL path if accessing NetBox within a directory. For example, if installed at http://example.com/netbox/, set:
|
||||||
# BASE_PATH = 'netbox/'
|
# BASE_PATH = 'netbox/'
|
||||||
BASE_PATH = os.environ.get('BASE_PATH', '')
|
BASE_PATH = environ.get('BASE_PATH', '')
|
||||||
|
|
||||||
# Cache timeout in seconds. Set to 0 to dissable caching. Defaults to 900 (15 minutes)
|
# Cache timeout in seconds. Set to 0 to dissable caching. Defaults to 900 (15 minutes)
|
||||||
CACHE_TIMEOUT = int(os.environ.get('CACHE_TIMEOUT', 900))
|
CACHE_TIMEOUT = int(environ.get('CACHE_TIMEOUT', 900))
|
||||||
|
|
||||||
# Maximum number of days to retain logged changes. Set to 0 to retain changes indefinitely. (Default: 90)
|
# Maximum number of days to retain logged changes. Set to 0 to retain changes indefinitely. (Default: 90)
|
||||||
CHANGELOG_RETENTION = int(os.environ.get('CHANGELOG_RETENTION', 90))
|
CHANGELOG_RETENTION = int(environ.get('CHANGELOG_RETENTION', 90))
|
||||||
|
|
||||||
# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
|
# API Cross-Origin Resource Sharing (CORS) settings. If CORS_ORIGIN_ALLOW_ALL is set to True, all origins will be
|
||||||
# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
|
# allowed. Otherwise, define a list of allowed origins using either CORS_ORIGIN_WHITELIST or
|
||||||
# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
|
# CORS_ORIGIN_REGEX_WHITELIST. For more information, see https://github.com/ottoyiu/django-cors-headers
|
||||||
CORS_ORIGIN_ALLOW_ALL = os.environ.get('CORS_ORIGIN_ALLOW_ALL', 'False').lower() == 'true'
|
CORS_ORIGIN_ALLOW_ALL = environ.get('CORS_ORIGIN_ALLOW_ALL', 'False').lower() == 'true'
|
||||||
CORS_ORIGIN_WHITELIST = list(filter(None, os.environ.get('CORS_ORIGIN_WHITELIST', 'https://localhost').split(' ')))
|
CORS_ORIGIN_WHITELIST = list(filter(None, environ.get('CORS_ORIGIN_WHITELIST', 'https://localhost').split(' ')))
|
||||||
CORS_ORIGIN_REGEX_WHITELIST = [re.compile(r) for r in list(filter(None, os.environ.get('CORS_ORIGIN_REGEX_WHITELIST', '').split(' ')))]
|
CORS_ORIGIN_REGEX_WHITELIST = [re.compile(r) for r in list(filter(None, environ.get('CORS_ORIGIN_REGEX_WHITELIST', '').split(' ')))]
|
||||||
|
|
||||||
# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal
|
# Set to True to enable server debugging. WARNING: Debugging introduces a substantial performance penalty and may reveal
|
||||||
# sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging
|
# sensitive information about your installation. Only enable debugging while performing testing. Never enable debugging
|
||||||
# on a production system.
|
# on a production system.
|
||||||
DEBUG = os.environ.get('DEBUG', 'False').lower() == 'true'
|
DEBUG = environ.get('DEBUG', 'False').lower() == 'true'
|
||||||
|
|
||||||
# Email settings
|
# Email settings
|
||||||
EMAIL = {
|
EMAIL = {
|
||||||
'SERVER': os.environ.get('EMAIL_SERVER', 'localhost'),
|
'SERVER': environ.get('EMAIL_SERVER', 'localhost'),
|
||||||
'PORT': int(os.environ.get('EMAIL_PORT', 25)),
|
'PORT': int(environ.get('EMAIL_PORT', 25)),
|
||||||
'USERNAME': os.environ.get('EMAIL_USERNAME', ''),
|
'USERNAME': environ.get('EMAIL_USERNAME', ''),
|
||||||
'PASSWORD': os.environ.get('EMAIL_PASSWORD', read_secret('email_password')),
|
'PASSWORD': _read_secret('email_password', environ.get('EMAIL_PASSWORD', '')),
|
||||||
'TIMEOUT': int(os.environ.get('EMAIL_TIMEOUT', 10)), # seconds
|
'USE_SSL': environ.get('EMAIL_USE_SSL', 'False').lower() == 'true',
|
||||||
'FROM_EMAIL': os.environ.get('EMAIL_FROM', ''),
|
'USE_TLS': environ.get('EMAIL_USE_TLS', 'False').lower() == 'true',
|
||||||
'USE_SSL': os.environ.get('EMAIL_USE_SSL', 'False').lower() == 'true',
|
'SSL_CERTFILE': environ.get('EMAIL_SSL_CERTFILE', ''),
|
||||||
'USE_TLS': os.environ.get('EMAIL_USE_TLS', 'False').lower() == 'true',
|
'SSL_KEYFILE': environ.get('EMAIL_SSL_KEYFILE', ''),
|
||||||
'SSL_CERTFILE': os.environ.get('EMAIL_SSL_CERTFILE', ''),
|
'TIMEOUT': int(environ.get('EMAIL_TIMEOUT', 10)), # seconds
|
||||||
'SSL_KEYFILE': os.environ.get('EMAIL_SSL_KEYFILE', ''),
|
'FROM_EMAIL': environ.get('EMAIL_FROM', ''),
|
||||||
}
|
}
|
||||||
|
|
||||||
# Enforcement of unique IP space can be toggled on a per-VRF basis.
|
# Enforcement of unique IP space can be toggled on a per-VRF basis. To enforce unique IP space within the global table
|
||||||
# To enforce unique IP space within the global table (all prefixes and IP addresses not assigned to a VRF),
|
# (all prefixes and IP addresses not assigned to a VRF), set ENFORCE_GLOBAL_UNIQUE to True.
|
||||||
# set ENFORCE_GLOBAL_UNIQUE to True.
|
ENFORCE_GLOBAL_UNIQUE = environ.get('ENFORCE_GLOBAL_UNIQUE', 'False').lower() == 'true'
|
||||||
ENFORCE_GLOBAL_UNIQUE = os.environ.get('ENFORCE_GLOBAL_UNIQUE', 'False').lower() == 'true'
|
|
||||||
|
|
||||||
# Exempt certain models from the enforcement of view permissions. Models listed here will be viewable by all users and
|
# Exempt certain models from the enforcement of view permissions. Models listed here will be viewable by all users and
|
||||||
# by anonymous users. List models in the form `<app>.<model>`. Add '*' to this list to exempt all models.
|
# by anonymous users. List models in the form `<app>.<model>`. Add '*' to this list to exempt all models.
|
||||||
EXEMPT_VIEW_PERMISSIONS = list(filter(None, os.environ.get('EXEMPT_VIEW_PERMISSIONS', '').split(' ')))
|
EXEMPT_VIEW_PERMISSIONS = list(filter(None, environ.get('EXEMPT_VIEW_PERMISSIONS', '').split(' ')))
|
||||||
|
|
||||||
# Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
|
# Enable custom logging. Please see the Django documentation for detailed guidance on configuring custom logs:
|
||||||
# https://docs.djangoproject.com/en/1.11/topics/logging/
|
# https://docs.djangoproject.com/en/stable/topics/logging/
|
||||||
LOGGING = {}
|
LOGGING = {}
|
||||||
|
|
||||||
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
|
# Setting this to True will permit only authenticated users to access any part of NetBox. By default, anonymous users
|
||||||
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
|
# are permitted to access most data in NetBox (excluding secrets) but not make any changes.
|
||||||
LOGIN_REQUIRED = os.environ.get('LOGIN_REQUIRED', 'False').lower() == 'true'
|
LOGIN_REQUIRED = environ.get('LOGIN_REQUIRED', 'False').lower() == 'true'
|
||||||
|
|
||||||
# The length of time (in seconds) for which a user will remain logged into the web UI before being prompted to
|
# The length of time (in seconds) for which a user will remain logged into the web UI before being prompted to
|
||||||
# re-authenticate. (Default: 1209600 [14 days])
|
# re-authenticate. (Default: 1209600 [14 days])
|
||||||
LOGIN_TIMEOUT = os.environ.get('LOGIN_TIMEOUT', None)
|
LOGIN_TIMEOUT = int(environ.get('LOGIN_TIMEOUT', 1209600))
|
||||||
|
|
||||||
# Setting this to True will display a "maintenance mode" banner at the top of every page.
|
# Setting this to True will display a "maintenance mode" banner at the top of every page.
|
||||||
MAINTENANCE_MODE = os.environ.get('MAINTENANCE_MODE', 'False').lower() == 'true'
|
MAINTENANCE_MODE = environ.get('MAINTENANCE_MODE', 'False').lower() == 'true'
|
||||||
|
|
||||||
# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
|
# An API consumer can request an arbitrary number of objects =by appending the "limit" parameter to the URL (e.g.
|
||||||
# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
|
# "?limit=1000"). This setting defines the maximum limit. Setting it to 0 or None will allow an API consumer to request
|
||||||
# all objects by specifying "?limit=0".
|
# all objects by specifying "?limit=0".
|
||||||
MAX_PAGE_SIZE = int(os.environ.get('MAX_PAGE_SIZE', 1000))
|
MAX_PAGE_SIZE = int(environ.get('MAX_PAGE_SIZE', 1000))
|
||||||
|
|
||||||
# The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that
|
# The file path where uploaded media such as image attachments are stored. A trailing slash is not needed. Note that
|
||||||
# the default value of this setting is derived from the installed location.
|
# the default value of this setting is derived from the installed location.
|
||||||
MEDIA_ROOT = os.environ.get('MEDIA_ROOT', os.path.join(BASE_DIR, 'media'))
|
MEDIA_ROOT = environ.get('MEDIA_ROOT', join(_BASE_DIR, 'media'))
|
||||||
|
|
||||||
# Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics'
|
# Expose Prometheus monitoring metrics at the HTTP endpoint '/metrics'
|
||||||
METRICS_ENABLED = os.environ.get('METRICS_ENABLED', 'False').lower() == 'true'
|
METRICS_ENABLED = environ.get('METRICS_ENABLED', 'False').lower() == 'true'
|
||||||
|
|
||||||
# Credentials that NetBox will use to access live devices.
|
# Credentials that NetBox will uses to authenticate to devices when connecting via NAPALM.
|
||||||
NAPALM_USERNAME = os.environ.get('NAPALM_USERNAME', '')
|
NAPALM_USERNAME = environ.get('NAPALM_USERNAME', '')
|
||||||
NAPALM_PASSWORD = os.environ.get('NAPALM_PASSWORD', read_secret('napalm_password'))
|
NAPALM_PASSWORD = _read_secret('napalm_password', environ.get('NAPALM_PASSWORD', ''))
|
||||||
|
|
||||||
# NAPALM timeout (in seconds). (Default: 30)
|
# NAPALM timeout (in seconds). (Default: 30)
|
||||||
NAPALM_TIMEOUT = int(os.environ.get('NAPALM_TIMEOUT', 30))
|
NAPALM_TIMEOUT = int(environ.get('NAPALM_TIMEOUT', 30))
|
||||||
|
|
||||||
# NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
|
# NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
|
||||||
# be provided as a dictionary.
|
# be provided as a dictionary.
|
||||||
NAPALM_ARGS = {}
|
NAPALM_ARGS = {}
|
||||||
|
|
||||||
# Determine how many objects to display per page within a list. (Default: 50)
|
# Determine how many objects to display per page within a list. (Default: 50)
|
||||||
PAGINATE_COUNT = int(os.environ.get('PAGINATE_COUNT', 50))
|
PAGINATE_COUNT = int(environ.get('PAGINATE_COUNT', 50))
|
||||||
|
|
||||||
|
# Enable installed plugins. Add the name of each plugin to the list.
|
||||||
|
PLUGINS = []
|
||||||
|
|
||||||
|
# Plugins configuration settings. These settings are used by various plugins that the user may have installed.
|
||||||
|
# Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
|
||||||
|
PLUGINS_CONFIG = {
|
||||||
|
}
|
||||||
|
|
||||||
# When determining the primary IP address for a device, IPv6 is preferred over IPv4 by default. Set this to True to
|
# When determining the primary IP address for a device, IPv6 is preferred over IPv4 by default. Set this to True to
|
||||||
# prefer IPv4 instead.
|
# prefer IPv4 instead.
|
||||||
PREFER_IPV4 = os.environ.get('PREFER_IPV4', 'False').lower() == 'true'
|
PREFER_IPV4 = environ.get('PREFER_IPV4', 'False').lower() == 'true'
|
||||||
|
|
||||||
# This determines how often the GitHub API is called to check the latest release of NetBox in seconds. Must be at least 1 hour.
|
# Rack elevation size defaults, in pixels. For best results, the ratio of width to height should be roughly 10:1.
|
||||||
RELEASE_CHECK_TIMEOUT = os.environ.get('RELEASE_CHECK_TIMEOUT', 24 * 3600)
|
RACK_ELEVATION_DEFAULT_UNIT_HEIGHT = int(environ.get('RACK_ELEVATION_DEFAULT_UNIT_HEIGHT', 22))
|
||||||
|
RACK_ELEVATION_DEFAULT_UNIT_WIDTH = int(environ.get('RACK_ELEVATION_DEFAULT_UNIT_WIDTH', 220))
|
||||||
|
|
||||||
|
# Remote authentication support
|
||||||
|
REMOTE_AUTH_ENABLED = environ.get('REMOTE_AUTH_ENABLED', 'False').lower() == 'true'
|
||||||
|
REMOTE_AUTH_BACKEND = environ.get('REMOTE_AUTH_BACKEND', 'netbox.authentication.RemoteUserBackend')
|
||||||
|
REMOTE_AUTH_HEADER = environ.get('REMOTE_AUTH_HEADER', 'HTTP_REMOTE_USER')
|
||||||
|
REMOTE_AUTH_AUTO_CREATE_USER = environ.get('REMOTE_AUTH_AUTO_CREATE_USER', 'True').lower() == 'true'
|
||||||
|
REMOTE_AUTH_DEFAULT_GROUPS = list(filter(None, environ.get('REMOTE_AUTH_DEFAULT_GROUPS', '').split(' ')))
|
||||||
|
|
||||||
|
# This determines how often the GitHub API is called to check the latest release of NetBox. Must be at least 1 hour.
|
||||||
|
RELEASE_CHECK_TIMEOUT = int(environ.get('RELEASE_CHECK_TIMEOUT', 24 * 3600))
|
||||||
|
|
||||||
# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the
|
# This repository is used to check whether there is a new release of NetBox available. Set to None to disable the
|
||||||
# version check or use the URL below to check for release in the official NetBox repository.
|
# version check or use the URL below to check for release in the official NetBox repository.
|
||||||
# https://api.github.com/repos/netbox-community/netbox/releases
|
# https://api.github.com/repos/netbox-community/netbox/releases
|
||||||
RELEASE_CHECK_URL = os.environ.get('RELEASE_CHECK_URL', None)
|
RELEASE_CHECK_URL = environ.get('RELEASE_CHECK_URL', None)
|
||||||
|
|
||||||
# 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 = environ.get('REPORTS_ROOT', '/etc/netbox/reports')
|
||||||
|
|
||||||
|
# Maximum execution time for background tasks, in seconds.
|
||||||
|
RQ_DEFAULT_TIMEOUT = int(environ.get('RQ_DEFAULT_TIMEOUT', 300))
|
||||||
|
|
||||||
# The file path where custom scripts will be stored. A trailing slash is not needed. Note that the default value of
|
# The file path where custom scripts 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.
|
||||||
SCRIPTS_ROOT = os.environ.get('SCRIPTS_ROOT', '/etc/netbox/scripts')
|
SCRIPTS_ROOT = environ.get('SCRIPTS_ROOT', '/etc/netbox/scripts')
|
||||||
|
|
||||||
|
# By default, NetBox will store session data in the database. Alternatively, a file path can be specified here to use
|
||||||
|
# local file storage instead. (This can be useful for enabling authentication on a standby instance with read-only
|
||||||
|
# database access.) Note that the user as which NetBox runs must have read and write permissions to this path.
|
||||||
|
SESSION_FILE_PATH = environ.get('SESSIONS_ROOT', None)
|
||||||
|
|
||||||
# Time zone (default: UTC)
|
# Time zone (default: UTC)
|
||||||
TIME_ZONE = os.environ.get('TIME_ZONE', 'UTC')
|
TIME_ZONE = environ.get('TIME_ZONE', 'UTC')
|
||||||
|
|
||||||
# Date/time formatting. See the following link for supported formats:
|
# Date/time formatting. See the following link for supported formats:
|
||||||
# https://docs.djangoproject.com/en/dev/ref/templates/builtins/#date
|
# https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date
|
||||||
DATE_FORMAT = os.environ.get('DATE_FORMAT', 'N j, Y')
|
DATE_FORMAT = environ.get('DATE_FORMAT', 'N j, Y')
|
||||||
SHORT_DATE_FORMAT = os.environ.get('SHORT_DATE_FORMAT', 'Y-m-d')
|
SHORT_DATE_FORMAT = environ.get('SHORT_DATE_FORMAT', 'Y-m-d')
|
||||||
TIME_FORMAT = os.environ.get('TIME_FORMAT', 'g:i a')
|
TIME_FORMAT = environ.get('TIME_FORMAT', 'g:i a')
|
||||||
SHORT_TIME_FORMAT = os.environ.get('SHORT_TIME_FORMAT', 'H:i:s')
|
SHORT_TIME_FORMAT = environ.get('SHORT_TIME_FORMAT', 'H:i:s')
|
||||||
DATETIME_FORMAT = os.environ.get('DATETIME_FORMAT', 'N j, Y g:i a')
|
DATETIME_FORMAT = environ.get('DATETIME_FORMAT', 'N j, Y g:i a')
|
||||||
SHORT_DATETIME_FORMAT = os.environ.get('SHORT_DATETIME_FORMAT', 'Y-m-d H:i')
|
SHORT_DATETIME_FORMAT = environ.get('SHORT_DATETIME_FORMAT', 'Y-m-d H:i')
|
||||||
|
55
configuration/extra.py
Normal file
55
configuration/extra.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
####
|
||||||
|
## This file contains extra configuration options that can't be configured
|
||||||
|
## directly through environment variables.
|
||||||
|
####
|
||||||
|
|
||||||
|
## Specify one or more name and email address tuples representing NetBox administrators. These people will be notified of
|
||||||
|
## application errors (assuming correct email settings are provided).
|
||||||
|
# ADMINS = [
|
||||||
|
# # ['John Doe', 'jdoe@example.com'],
|
||||||
|
# ]
|
||||||
|
|
||||||
|
|
||||||
|
## URL schemes that are allowed within links in NetBox
|
||||||
|
# ALLOWED_URL_SCHEMES = (
|
||||||
|
# 'file', 'ftp', 'ftps', 'http', 'https', 'irc', 'mailto', 'sftp', 'ssh', 'tel', 'telnet', 'tftp', 'vnc', 'xmpp',
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
## NAPALM optional arguments (see http://napalm.readthedocs.io/en/latest/support/#optional-arguments). Arguments must
|
||||||
|
## be provided as a dictionary.
|
||||||
|
# NAPALM_ARGS = {}
|
||||||
|
|
||||||
|
|
||||||
|
## Enable installed plugins. Add the name of each plugin to the list.
|
||||||
|
# from netbox.configuration.configuration import PLUGINS
|
||||||
|
# PLUGINS.append('my_plugin')
|
||||||
|
|
||||||
|
## Plugins configuration settings. These settings are used by various plugins that the user may have installed.
|
||||||
|
## Each key in the dictionary is the name of an installed plugin and its value is a dictionary of settings.
|
||||||
|
# from netbox.configuration.configuration import PLUGINS_CONFIG
|
||||||
|
# PLUGINS_CONFIG['my_plugin'] = {
|
||||||
|
# 'foo': 'bar',
|
||||||
|
# 'buzz': 'bazz'
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
## Remote authentication support
|
||||||
|
# REMOTE_AUTH_DEFAULT_PERMISSIONS = {}
|
||||||
|
|
||||||
|
|
||||||
|
## By default uploaded media is stored on the local filesystem. Using Django-storages is also supported. Provide the
|
||||||
|
## class path of the storage driver in STORAGE_BACKEND and any configuration options in STORAGE_CONFIG. For example:
|
||||||
|
# STORAGE_BACKEND = 'storages.backends.s3boto3.S3Boto3Storage'
|
||||||
|
# STORAGE_CONFIG = {
|
||||||
|
# 'AWS_ACCESS_KEY_ID': 'Key ID',
|
||||||
|
# 'AWS_SECRET_ACCESS_KEY': 'Secret',
|
||||||
|
# 'AWS_STORAGE_BUCKET_NAME': 'netbox',
|
||||||
|
# 'AWS_S3_REGION_NAME': 'eu-west-1',
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
|
## This file can contain arbitrary Python code, e.g.:
|
||||||
|
# from datetime import datetime
|
||||||
|
# now = datetime.now().strftime("%d/%m/%Y %H:%M:%S")
|
||||||
|
# BANNER_TOP = f'<marquee width="200px">This instance started on {now}.</marquee>'
|
@ -1,8 +0,0 @@
|
|||||||
command = '/usr/bin/gunicorn'
|
|
||||||
pythonpath = '/opt/netbox/netbox'
|
|
||||||
bind = '0.0.0.0:8001'
|
|
||||||
workers = 3
|
|
||||||
errorlog = '-'
|
|
||||||
accesslog = '-'
|
|
||||||
capture_output = False
|
|
||||||
loglevel = 'debug'
|
|
@ -1,21 +1,21 @@
|
|||||||
import ldap
|
import ldap
|
||||||
import os
|
|
||||||
|
|
||||||
from django_auth_ldap.config import LDAPSearch
|
from django_auth_ldap.config import LDAPSearch
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
|
from os import environ
|
||||||
|
|
||||||
# Read secret from file
|
# Read secret from file
|
||||||
def read_secret(secret_name):
|
def _read_secret(secret_name, default=None):
|
||||||
try:
|
try:
|
||||||
f = open('/run/secrets/' + secret_name, 'r', encoding='utf-8')
|
f = open('/run/secrets/' + secret_name, 'r', encoding='utf-8')
|
||||||
except EnvironmentError:
|
except EnvironmentError:
|
||||||
return ''
|
return default
|
||||||
else:
|
else:
|
||||||
with f:
|
with f:
|
||||||
return f.readline().strip()
|
return f.readline().strip()
|
||||||
|
|
||||||
# Import and return the group type based on string name
|
# Import and return the group type based on string name
|
||||||
def import_group_type(group_type_name):
|
def _import_group_type(group_type_name):
|
||||||
mod = import_module('django_auth_ldap.config')
|
mod = import_module('django_auth_ldap.config')
|
||||||
try:
|
try:
|
||||||
return getattr(mod, group_type_name)()
|
return getattr(mod, group_type_name)()
|
||||||
@ -23,7 +23,7 @@ def import_group_type(group_type_name):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
# Server URI
|
# Server URI
|
||||||
AUTH_LDAP_SERVER_URI = os.environ.get('AUTH_LDAP_SERVER_URI', '')
|
AUTH_LDAP_SERVER_URI = environ.get('AUTH_LDAP_SERVER_URI', '')
|
||||||
|
|
||||||
# The following may be needed if you are binding to Active Directory.
|
# The following may be needed if you are binding to Active Directory.
|
||||||
AUTH_LDAP_CONNECTION_OPTIONS = {
|
AUTH_LDAP_CONNECTION_OPTIONS = {
|
||||||
@ -31,53 +31,57 @@ AUTH_LDAP_CONNECTION_OPTIONS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Set the DN and password for the NetBox service account.
|
# Set the DN and password for the NetBox service account.
|
||||||
AUTH_LDAP_BIND_DN = os.environ.get('AUTH_LDAP_BIND_DN', '')
|
AUTH_LDAP_BIND_DN = environ.get('AUTH_LDAP_BIND_DN', '')
|
||||||
AUTH_LDAP_BIND_PASSWORD = os.environ.get('AUTH_LDAP_BIND_PASSWORD', read_secret('auth_ldap_bind_password'))
|
AUTH_LDAP_BIND_PASSWORD = _read_secret('auth_ldap_bind_password', environ.get('AUTH_LDAP_BIND_PASSWORD', ''))
|
||||||
|
|
||||||
# Set a string template that describes any user’s distinguished name based on the username.
|
# Set a string template that describes any user’s distinguished name based on the username.
|
||||||
AUTH_LDAP_USER_DN_TEMPLATE = os.environ.get('AUTH_LDAP_USER_DN_TEMPLATE', None)
|
AUTH_LDAP_USER_DN_TEMPLATE = environ.get('AUTH_LDAP_USER_DN_TEMPLATE', None)
|
||||||
|
|
||||||
# Enable STARTTLS for ldap authentication.
|
# Enable STARTTLS for ldap authentication.
|
||||||
AUTH_LDAP_START_TLS = os.environ.get('AUTH_LDAP_START_TLS', 'False').lower() == 'true'
|
AUTH_LDAP_START_TLS = environ.get('AUTH_LDAP_START_TLS', 'False').lower() == 'true'
|
||||||
|
|
||||||
# Include this setting if you want to ignore certificate errors. This might be needed to accept a self-signed cert.
|
# Include this setting if you want to ignore certificate errors. This might be needed to accept a self-signed cert.
|
||||||
# Note that this is a NetBox-specific setting which sets:
|
# Note that this is a NetBox-specific setting which sets:
|
||||||
# ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
# ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
|
||||||
LDAP_IGNORE_CERT_ERRORS = os.environ.get('LDAP_IGNORE_CERT_ERRORS', 'False').lower() == 'true'
|
LDAP_IGNORE_CERT_ERRORS = environ.get('LDAP_IGNORE_CERT_ERRORS', 'False').lower() == 'true'
|
||||||
|
|
||||||
AUTH_LDAP_USER_SEARCH_BASEDN = os.environ.get('AUTH_LDAP_USER_SEARCH_BASEDN', '')
|
AUTH_LDAP_USER_SEARCH_BASEDN = environ.get('AUTH_LDAP_USER_SEARCH_BASEDN', '')
|
||||||
AUTH_LDAP_USER_SEARCH_ATTR = os.environ.get('AUTH_LDAP_USER_SEARCH_ATTR', 'sAMAccountName')
|
AUTH_LDAP_USER_SEARCH_ATTR = environ.get('AUTH_LDAP_USER_SEARCH_ATTR', 'sAMAccountName')
|
||||||
AUTH_LDAP_USER_SEARCH = LDAPSearch(AUTH_LDAP_USER_SEARCH_BASEDN,
|
AUTH_LDAP_USER_SEARCH = LDAPSearch(AUTH_LDAP_USER_SEARCH_BASEDN,
|
||||||
ldap.SCOPE_SUBTREE,
|
ldap.SCOPE_SUBTREE,
|
||||||
"(" + AUTH_LDAP_USER_SEARCH_ATTR + "=%(user)s)")
|
"(" + AUTH_LDAP_USER_SEARCH_ATTR + "=%(user)s)")
|
||||||
|
|
||||||
# This search ought to return all groups to which the user belongs. django_auth_ldap uses this to determine group
|
# This search ought to return all groups to which the user belongs. django_auth_ldap uses this to determine group
|
||||||
# heirarchy.
|
# heirarchy.
|
||||||
AUTH_LDAP_GROUP_SEARCH_BASEDN = os.environ.get('AUTH_LDAP_GROUP_SEARCH_BASEDN', '')
|
AUTH_LDAP_GROUP_SEARCH_BASEDN = environ.get('AUTH_LDAP_GROUP_SEARCH_BASEDN', '')
|
||||||
AUTH_LDAP_GROUP_SEARCH_CLASS = os.environ.get('AUTH_LDAP_GROUP_SEARCH_CLASS', 'group')
|
AUTH_LDAP_GROUP_SEARCH_CLASS = environ.get('AUTH_LDAP_GROUP_SEARCH_CLASS', 'group')
|
||||||
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(AUTH_LDAP_GROUP_SEARCH_BASEDN, ldap.SCOPE_SUBTREE,
|
AUTH_LDAP_GROUP_SEARCH = LDAPSearch(AUTH_LDAP_GROUP_SEARCH_BASEDN, ldap.SCOPE_SUBTREE,
|
||||||
"(objectClass=" + AUTH_LDAP_GROUP_SEARCH_CLASS + ")")
|
"(objectClass=" + AUTH_LDAP_GROUP_SEARCH_CLASS + ")")
|
||||||
AUTH_LDAP_GROUP_TYPE = import_group_type(os.environ.get('AUTH_LDAP_GROUP_TYPE', 'GroupOfNamesType'))
|
AUTH_LDAP_GROUP_TYPE = _import_group_type(environ.get('AUTH_LDAP_GROUP_TYPE', 'GroupOfNamesType'))
|
||||||
|
|
||||||
# Define a group required to login.
|
# Define a group required to login.
|
||||||
AUTH_LDAP_REQUIRE_GROUP = os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', '')
|
AUTH_LDAP_REQUIRE_GROUP = environ.get('AUTH_LDAP_REQUIRE_GROUP_DN')
|
||||||
|
|
||||||
# Define special user types using groups. Exercise great caution when assigning superuser status.
|
# Define special user types using groups. Exercise great caution when assigning superuser status.
|
||||||
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
AUTH_LDAP_USER_FLAGS_BY_GROUP = {}
|
||||||
"is_active": os.environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', ''),
|
|
||||||
"is_staff": os.environ.get('AUTH_LDAP_IS_ADMIN_DN', ''),
|
if AUTH_LDAP_REQUIRE_GROUP is not None:
|
||||||
"is_superuser": os.environ.get('AUTH_LDAP_IS_SUPERUSER_DN', '')
|
AUTH_LDAP_USER_FLAGS_BY_GROUP = {
|
||||||
}
|
"is_active": environ.get('AUTH_LDAP_REQUIRE_GROUP_DN', ''),
|
||||||
|
"is_staff": environ.get('AUTH_LDAP_IS_ADMIN_DN', ''),
|
||||||
|
"is_superuser": environ.get('AUTH_LDAP_IS_SUPERUSER_DN', '')
|
||||||
|
}
|
||||||
|
|
||||||
# For more granular permissions, we can map LDAP groups to Django groups.
|
# For more granular permissions, we can map LDAP groups to Django groups.
|
||||||
AUTH_LDAP_FIND_GROUP_PERMS = os.environ.get('AUTH_LDAP_FIND_GROUP_PERMS', 'True').lower() == 'true'
|
AUTH_LDAP_FIND_GROUP_PERMS = environ.get('AUTH_LDAP_FIND_GROUP_PERMS', 'True').lower() == 'true'
|
||||||
|
AUTH_LDAP_MIRROR_GROUPS = environ.get('AUTH_LDAP_MIRROR_GROUPS', '').lower() == 'true'
|
||||||
|
|
||||||
# Cache groups for one hour to reduce LDAP traffic
|
# Cache groups for one hour to reduce LDAP traffic
|
||||||
AUTH_LDAP_CACHE_TIMEOUT = int(os.environ.get('AUTH_LDAP_CACHE_TIMEOUT', 3600))
|
AUTH_LDAP_CACHE_TIMEOUT = int(environ.get('AUTH_LDAP_CACHE_TIMEOUT', 3600))
|
||||||
|
|
||||||
# Populate the Django user from the LDAP directory.
|
# Populate the Django user from the LDAP directory.
|
||||||
AUTH_LDAP_USER_ATTR_MAP = {
|
AUTH_LDAP_USER_ATTR_MAP = {
|
||||||
"first_name": os.environ.get('AUTH_LDAP_ATTR_FIRSTNAME', 'givenName'),
|
"first_name": environ.get('AUTH_LDAP_ATTR_FIRSTNAME', 'givenName'),
|
||||||
"last_name": os.environ.get('AUTH_LDAP_ATTR_LASTNAME', 'sn'),
|
"last_name": environ.get('AUTH_LDAP_ATTR_LASTNAME', 'sn'),
|
||||||
"email": os.environ.get('AUTH_LDAP_ATTR_MAIL', 'mail')
|
"email": environ.get('AUTH_LDAP_ATTR_MAIL', 'mail')
|
||||||
}
|
}
|
@ -7,6 +7,8 @@ services:
|
|||||||
- redis
|
- redis
|
||||||
- redis-cache
|
- redis-cache
|
||||||
env_file: env/netbox.env
|
env_file: env/netbox.env
|
||||||
|
environment:
|
||||||
|
SKIP_STARTUP_SCRIPTS: ${SKIP_STARTUP_SCRIPTS-false}
|
||||||
user: '101'
|
user: '101'
|
||||||
volumes:
|
volumes:
|
||||||
- ./startup_scripts:/opt/netbox/startup_scripts:z,ro
|
- ./startup_scripts:/opt/netbox/startup_scripts:z,ro
|
||||||
@ -14,40 +16,26 @@ services:
|
|||||||
- ./configuration:/etc/netbox/config:z,ro
|
- ./configuration:/etc/netbox/config:z,ro
|
||||||
- ./reports:/etc/netbox/reports:z,ro
|
- ./reports:/etc/netbox/reports:z,ro
|
||||||
- ./scripts:/etc/netbox/scripts:z,ro
|
- ./scripts:/etc/netbox/scripts:z,ro
|
||||||
- netbox-nginx-config:/etc/netbox-nginx:z
|
|
||||||
- netbox-static-files:/opt/netbox/netbox/static:z
|
|
||||||
- netbox-media-files:/opt/netbox/netbox/media:z
|
- netbox-media-files:/opt/netbox/netbox/media:z
|
||||||
nginx:
|
|
||||||
command: nginx -c /etc/netbox-nginx/nginx.conf
|
|
||||||
image: nginx:1.17-alpine
|
|
||||||
depends_on:
|
|
||||||
- netbox
|
|
||||||
ports:
|
ports:
|
||||||
- 8080
|
- 8080
|
||||||
volumes:
|
|
||||||
- netbox-static-files:/opt/netbox/netbox/static:ro
|
|
||||||
- netbox-nginx-config:/etc/netbox-nginx/:ro
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:11-alpine
|
image: postgres:12-alpine
|
||||||
env_file: env/postgres.env
|
env_file: env/postgres.env
|
||||||
redis:
|
redis:
|
||||||
image: redis:5-alpine
|
image: redis:6-alpine
|
||||||
command:
|
command:
|
||||||
- sh
|
- sh
|
||||||
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
||||||
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
||||||
env_file: env/redis.env
|
env_file: env/redis.env
|
||||||
redis-cache:
|
redis-cache:
|
||||||
image: redis:5-alpine
|
image: redis:6-alpine
|
||||||
command:
|
command:
|
||||||
- sh
|
- sh
|
||||||
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
||||||
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
||||||
env_file: env/redis-cache.env
|
env_file: env/redis-cache.env
|
||||||
volumes:
|
volumes:
|
||||||
netbox-static-files:
|
|
||||||
driver: local
|
|
||||||
netbox-nginx-config:
|
|
||||||
driver: local
|
|
||||||
netbox-media-files:
|
netbox-media-files:
|
||||||
driver: local
|
driver: local
|
||||||
|
@ -15,35 +15,30 @@ services:
|
|||||||
- ./configuration:/etc/netbox/config:z,ro
|
- ./configuration:/etc/netbox/config:z,ro
|
||||||
- ./reports:/etc/netbox/reports:z,ro
|
- ./reports:/etc/netbox/reports:z,ro
|
||||||
- ./scripts:/etc/netbox/scripts:z,ro
|
- ./scripts:/etc/netbox/scripts:z,ro
|
||||||
- netbox-nginx-config:/etc/netbox-nginx:z
|
|
||||||
- netbox-static-files:/opt/netbox/netbox/static:z
|
|
||||||
- netbox-media-files:/opt/netbox/netbox/media:z
|
- netbox-media-files:/opt/netbox/netbox/media:z
|
||||||
|
ports:
|
||||||
|
- "8080"
|
||||||
netbox-worker:
|
netbox-worker:
|
||||||
<<: *netbox
|
<<: *netbox
|
||||||
depends_on:
|
depends_on:
|
||||||
- redis
|
- redis
|
||||||
entrypoint:
|
entrypoint:
|
||||||
- python3
|
- /opt/netbox/venv/bin/python
|
||||||
- /opt/netbox/netbox/manage.py
|
- /opt/netbox/netbox/manage.py
|
||||||
command:
|
command:
|
||||||
- rqworker
|
- rqworker
|
||||||
nginx:
|
ports: []
|
||||||
command: nginx -c /etc/netbox-nginx/nginx.conf
|
|
||||||
image: nginx:1.17-alpine
|
# postgres
|
||||||
depends_on:
|
|
||||||
- netbox
|
|
||||||
ports:
|
|
||||||
- 8080
|
|
||||||
volumes:
|
|
||||||
- netbox-static-files:/opt/netbox/netbox/static:ro
|
|
||||||
- netbox-nginx-config:/etc/netbox-nginx/:ro
|
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:11-alpine
|
image: postgres:12-alpine
|
||||||
env_file: env/postgres.env
|
env_file: env/postgres.env
|
||||||
volumes:
|
volumes:
|
||||||
- netbox-postgres-data:/var/lib/postgresql/data
|
- netbox-postgres-data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
# redis
|
||||||
redis:
|
redis:
|
||||||
image: redis:5-alpine
|
image: redis:6-alpine
|
||||||
command:
|
command:
|
||||||
- sh
|
- sh
|
||||||
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
||||||
@ -52,17 +47,14 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- netbox-redis-data:/data
|
- netbox-redis-data:/data
|
||||||
redis-cache:
|
redis-cache:
|
||||||
image: redis:5-alpine
|
image: redis:6-alpine
|
||||||
command:
|
command:
|
||||||
- sh
|
- sh
|
||||||
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
||||||
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
||||||
env_file: env/redis-cache.env
|
env_file: env/redis-cache.env
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
netbox-static-files:
|
|
||||||
driver: local
|
|
||||||
netbox-nginx-config:
|
|
||||||
driver: local
|
|
||||||
netbox-media-files:
|
netbox-media-files:
|
||||||
driver: local
|
driver: local
|
||||||
netbox-postgres-data:
|
netbox-postgres-data:
|
||||||
|
@ -1,10 +1,80 @@
|
|||||||
|
## Generic Parts
|
||||||
|
# These functions are providing the functionality to load
|
||||||
|
# arbitrary configuration files.
|
||||||
|
#
|
||||||
|
# They can be imported by other code (see `ldap_config.py` for an example).
|
||||||
|
|
||||||
|
from os.path import abspath, isfile
|
||||||
|
from os import scandir
|
||||||
import importlib.util
|
import importlib.util
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
|
||||||
spec = importlib.util.spec_from_file_location('configuration', '/etc/netbox/config/configuration.py')
|
def _filename(f):
|
||||||
|
return f.name
|
||||||
|
|
||||||
|
|
||||||
|
def _import(module_name, path, loaded_configurations):
|
||||||
|
spec = importlib.util.spec_from_file_location('', path)
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
sys.modules['netbox.configuration'] = module
|
sys.modules[module_name] = module
|
||||||
except:
|
|
||||||
raise ImportError('')
|
loaded_configurations.insert(0, module)
|
||||||
|
|
||||||
|
print(f"🧬 loaded config '{path}'")
|
||||||
|
|
||||||
|
|
||||||
|
def read_configurations(config_module, config_dir, main_config):
|
||||||
|
loaded_configurations = []
|
||||||
|
|
||||||
|
main_config_path = abspath(f'{config_dir}/{main_config}.py')
|
||||||
|
if isfile(main_config_path):
|
||||||
|
_import(f'{config_module}.{main_config}', main_config_path, loaded_configurations)
|
||||||
|
else:
|
||||||
|
print(f"⚠️ Main configuration '{main_config_path}' not found.")
|
||||||
|
|
||||||
|
with scandir(config_dir) as it:
|
||||||
|
for f in sorted(it, key=_filename):
|
||||||
|
if not f.is_file():
|
||||||
|
continue
|
||||||
|
|
||||||
|
if f.name.startswith('__'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not f.name.endswith('.py'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
if f.name == f'{config_dir}.py':
|
||||||
|
continue
|
||||||
|
|
||||||
|
module_name = f"{config_module}.{f.name[:-len('.py')]}".replace(".", "_")
|
||||||
|
_import(module_name, f.path, loaded_configurations)
|
||||||
|
|
||||||
|
if len(loaded_configurations) == 0:
|
||||||
|
print(f"‼️ No configuration files found in '{config_dir}'.")
|
||||||
|
raise ImportError(f"No configuration files found in '{config_dir}'.")
|
||||||
|
|
||||||
|
return loaded_configurations
|
||||||
|
|
||||||
|
|
||||||
|
## Specific Parts
|
||||||
|
# This section's code actually loads the various configuration files
|
||||||
|
# into the module with the given name.
|
||||||
|
# It contains the logic to resolve arbitrary configuration options by
|
||||||
|
# levaraging dynamic programming using `__getattr__`.
|
||||||
|
|
||||||
|
|
||||||
|
_loaded_configurations = read_configurations(
|
||||||
|
config_dir = '/etc/netbox/config/',
|
||||||
|
config_module = 'netbox.configuration',
|
||||||
|
main_config = 'configuration')
|
||||||
|
|
||||||
|
|
||||||
|
def __getattr__(name):
|
||||||
|
for config in _loaded_configurations:
|
||||||
|
try:
|
||||||
|
return getattr(config, name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
raise AttributeError
|
||||||
|
@ -7,6 +7,9 @@ set -e
|
|||||||
# Allows Netbox to be run as non-root users
|
# Allows Netbox to be run as non-root users
|
||||||
umask 002
|
umask 002
|
||||||
|
|
||||||
|
# Load correct Python3 env
|
||||||
|
source /opt/netbox/venv/bin/activate
|
||||||
|
|
||||||
# Try to connect to the DB
|
# Try to connect to the DB
|
||||||
DB_WAIT_TIMEOUT=${DB_WAIT_TIMEOUT-3}
|
DB_WAIT_TIMEOUT=${DB_WAIT_TIMEOUT-3}
|
||||||
MAX_DB_WAIT_TIME=${MAX_DB_WAIT_TIME-30}
|
MAX_DB_WAIT_TIME=${MAX_DB_WAIT_TIME-30}
|
||||||
@ -31,20 +34,16 @@ else
|
|||||||
if [ -z ${SUPERUSER_EMAIL+x} ]; then
|
if [ -z ${SUPERUSER_EMAIL+x} ]; then
|
||||||
SUPERUSER_EMAIL='admin@example.com'
|
SUPERUSER_EMAIL='admin@example.com'
|
||||||
fi
|
fi
|
||||||
if [ -z ${SUPERUSER_PASSWORD+x} ]; then
|
|
||||||
if [ -f "/run/secrets/superuser_password" ]; then
|
if [ -f "/run/secrets/superuser_password" ]; then
|
||||||
SUPERUSER_PASSWORD="$(< /run/secrets/superuser_password)"
|
SUPERUSER_PASSWORD="$(< /run/secrets/superuser_password)"
|
||||||
else
|
elif [ -z ${SUPERUSER_PASSWORD+x} ]; then
|
||||||
SUPERUSER_PASSWORD='admin'
|
SUPERUSER_PASSWORD='admin'
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
if [ -z ${SUPERUSER_API_TOKEN+x} ]; then
|
|
||||||
if [ -f "/run/secrets/superuser_api_token" ]; then
|
if [ -f "/run/secrets/superuser_api_token" ]; then
|
||||||
SUPERUSER_API_TOKEN="$(< /run/secrets/superuser_api_token)"
|
SUPERUSER_API_TOKEN="$(< /run/secrets/superuser_api_token)"
|
||||||
else
|
elif [ -z ${SUPERUSER_API_TOKEN+x} ]; then
|
||||||
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
|
SUPERUSER_API_TOKEN='0123456789abcdef0123456789abcdef01234567'
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
./manage.py shell --interface python << END
|
./manage.py shell --interface python << END
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
@ -64,9 +63,6 @@ else
|
|||||||
echo "import runpy; runpy.run_path('../startup_scripts')" | ./manage.py shell --interface python
|
echo "import runpy; runpy.run_path('../startup_scripts')" | ./manage.py shell --interface python
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Copy static files
|
|
||||||
./manage.py collectstatic --no-input
|
|
||||||
|
|
||||||
echo "✅ Initialisation is done."
|
echo "✅ Initialisation is done."
|
||||||
|
|
||||||
# Launch whatever is passed by docker
|
# Launch whatever is passed by docker
|
||||||
|
53
docker/launch-netbox.sh
Executable file
53
docker/launch-netbox.sh
Executable file
@ -0,0 +1,53 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
UNIT_CONFIG="${UNIT_CONFIG-/etc/unit/nginx-unit.json}"
|
||||||
|
UNIT_SOCKET="/opt/unit/unit.sock"
|
||||||
|
|
||||||
|
load_configuration() {
|
||||||
|
MAX_WAIT=10
|
||||||
|
WAIT_COUNT=0
|
||||||
|
while [ ! -S $UNIT_SOCKET ]; do
|
||||||
|
if [ $WAIT_COUNT -ge $MAX_WAIT ]; then
|
||||||
|
echo "⚠️ No control socket found; configuration will not be loaded."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
WAIT_COUNT=$((WAIT_COUNT + 1))
|
||||||
|
echo "⏳ Waiting for control socket to be created... (${WAIT_COUNT}/${MAX_WAIT})"
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
|
||||||
|
# even when the control socket exists, it does not mean unit has finished initialisation
|
||||||
|
# this curl call will get a reply once unit is fully launched
|
||||||
|
curl --silent --output /dev/null --request GET --unix-socket $UNIT_SOCKET http://localhost/
|
||||||
|
|
||||||
|
echo "⚙️ Applying configuration from $UNIT_CONFIG";
|
||||||
|
|
||||||
|
RESP_CODE=$(curl \
|
||||||
|
--silent \
|
||||||
|
--output /dev/null \
|
||||||
|
--write-out '%{http_code}' \
|
||||||
|
--request PUT \
|
||||||
|
--data-binary "@${UNIT_CONFIG}" \
|
||||||
|
--unix-socket $UNIT_SOCKET \
|
||||||
|
http://localhost/config
|
||||||
|
)
|
||||||
|
if [ "$RESP_CODE" != "200" ]; then
|
||||||
|
echo "⚠️ Could no load Unit configuration"
|
||||||
|
kill "$(cat /opt/unit/unit.pid)"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "✅ Unit configuration loaded successfully"
|
||||||
|
}
|
||||||
|
|
||||||
|
load_configuration &
|
||||||
|
|
||||||
|
exec unitd \
|
||||||
|
--no-daemon \
|
||||||
|
--control unix:$UNIT_SOCKET \
|
||||||
|
--pid /opt/unit/unit.pid \
|
||||||
|
--log /dev/stdout \
|
||||||
|
--state /opt/unit/state/ \
|
||||||
|
--tmp /opt/unit/tmp/
|
@ -1,10 +1,21 @@
|
|||||||
import importlib.util
|
from .configuration import read_configurations
|
||||||
import sys
|
|
||||||
|
|
||||||
try:
|
_loaded_configurations = read_configurations(
|
||||||
spec = importlib.util.spec_from_file_location('ldap_config', '/etc/netbox/config/ldap_config.py')
|
config_dir = '/etc/netbox/config/ldap/',
|
||||||
module = importlib.util.module_from_spec(spec)
|
config_module = 'netbox.configuration.ldap',
|
||||||
spec.loader.exec_module(module)
|
main_config = 'ldap_config')
|
||||||
sys.modules['netbox.ldap_config'] = module
|
|
||||||
except:
|
|
||||||
raise ImportError('')
|
def __getattr__(name):
|
||||||
|
for config in _loaded_configurations:
|
||||||
|
try:
|
||||||
|
return getattr(config, name)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
raise AttributeError
|
||||||
|
|
||||||
|
def __dir__():
|
||||||
|
names = []
|
||||||
|
for config in _loaded_configurations:
|
||||||
|
names.extend(config.__dir__())
|
||||||
|
return names
|
||||||
|
40
docker/nginx-unit.json
Normal file
40
docker/nginx-unit.json
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"listeners": {
|
||||||
|
"*:8080": {
|
||||||
|
"pass": "routes"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"routes": [
|
||||||
|
{
|
||||||
|
"match": {
|
||||||
|
"uri": "/static/*"
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"share": "/opt/netbox/netbox"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"action": {
|
||||||
|
"pass": "applications/netbox"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
"applications": {
|
||||||
|
"netbox": {
|
||||||
|
"type": "python 3",
|
||||||
|
"path": "/opt/netbox/netbox/",
|
||||||
|
"module": "netbox.wsgi",
|
||||||
|
"home": "/opt/netbox/venv",
|
||||||
|
"processes": {
|
||||||
|
"max": 4,
|
||||||
|
"spare": 1,
|
||||||
|
"idle_timeout": 120
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
"access_log": "/dev/stdout"
|
||||||
|
}
|
@ -1,35 +0,0 @@
|
|||||||
daemon off;
|
|
||||||
worker_processes 1;
|
|
||||||
|
|
||||||
error_log /dev/stderr info;
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
include /etc/nginx/mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
sendfile on;
|
|
||||||
tcp_nopush on;
|
|
||||||
keepalive_timeout 65;
|
|
||||||
gzip on;
|
|
||||||
server_tokens off;
|
|
||||||
client_max_body_size 10M;
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 8080;
|
|
||||||
access_log off;
|
|
||||||
|
|
||||||
location /static/ {
|
|
||||||
alias /opt/netbox/netbox/static/;
|
|
||||||
}
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://netbox:8001;
|
|
||||||
proxy_set_header X-Forwarded-Host $http_host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
5
env/netbox.env
vendored
5
env/netbox.env
vendored
@ -14,11 +14,12 @@ EMAIL_USE_SSL=false
|
|||||||
EMAIL_USE_TLS=false
|
EMAIL_USE_TLS=false
|
||||||
EMAIL_SSL_CERTFILE=
|
EMAIL_SSL_CERTFILE=
|
||||||
EMAIL_SSL_KEYFILE=
|
EMAIL_SSL_KEYFILE=
|
||||||
|
MAX_PAGE_SIZE=1000
|
||||||
MEDIA_ROOT=/opt/netbox/netbox/media
|
MEDIA_ROOT=/opt/netbox/netbox/media
|
||||||
|
METRICS_ENABLED=false
|
||||||
NAPALM_USERNAME=
|
NAPALM_USERNAME=
|
||||||
NAPALM_PASSWORD=
|
NAPALM_PASSWORD=
|
||||||
NAPALM_TIMEOUT=10
|
NAPALM_TIMEOUT=10
|
||||||
MAX_PAGE_SIZE=1000
|
|
||||||
REDIS_HOST=redis
|
REDIS_HOST=redis
|
||||||
REDIS_PASSWORD=H733Kdjndks81
|
REDIS_PASSWORD=H733Kdjndks81
|
||||||
REDIS_DATABASE=0
|
REDIS_DATABASE=0
|
||||||
@ -27,6 +28,7 @@ REDIS_CACHE_HOST=redis-cache
|
|||||||
REDIS_CACHE_PASSWORD=t4Ph722qJ5QHeQ1qfu36
|
REDIS_CACHE_PASSWORD=t4Ph722qJ5QHeQ1qfu36
|
||||||
REDIS_CACHE_DATABASE=1
|
REDIS_CACHE_DATABASE=1
|
||||||
REDIS_CACHE_SSL=false
|
REDIS_CACHE_SSL=false
|
||||||
|
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases
|
||||||
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
|
SECRET_KEY=r8OwDznj!!dci#P9ghmRfdu1Ysxm0AiPeDCQhKE+N_rClfWNj
|
||||||
SKIP_STARTUP_SCRIPTS=false
|
SKIP_STARTUP_SCRIPTS=false
|
||||||
SKIP_SUPERUSER=false
|
SKIP_SUPERUSER=false
|
||||||
@ -35,4 +37,3 @@ SUPERUSER_EMAIL=admin@example.com
|
|||||||
SUPERUSER_PASSWORD=admin
|
SUPERUSER_PASSWORD=admin
|
||||||
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
|
SUPERUSER_API_TOKEN=0123456789abcdef0123456789abcdef01234567
|
||||||
WEBHOOKS_ENABLED=true
|
WEBHOOKS_ENABLED=true
|
||||||
RELEASE_CHECK_URL=https://api.github.com/repos/netbox-community/netbox/releases
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# - prefix: 10.0.0.0/16
|
# - prefix: 10.0.0.0/16
|
||||||
# rir: RFC1918
|
# rir: RFC1918
|
||||||
|
# tenant: tenant1
|
||||||
# - prefix: fd00:ccdd::/32
|
# - prefix: fd00:ccdd::/32
|
||||||
# rir: RFC4193 ULA
|
# rir: RFC4193 ULA
|
||||||
# - prefix: 2001:db8::/32
|
# - prefix: 2001:db8::/32
|
||||||
|
6
initializers/circuit_types.yml
Normal file
6
initializers/circuit_types.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# - name: VPLS
|
||||||
|
# slug: vpls
|
||||||
|
# - name: MPLS
|
||||||
|
# slug: mpls
|
||||||
|
# - name: Internet
|
||||||
|
# slug: internet
|
7
initializers/circuits.yml
Normal file
7
initializers/circuits.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
# - cid: Circuit_ID-1
|
||||||
|
# provider: Provider1
|
||||||
|
# type: Internet
|
||||||
|
# tenant: tenant1
|
||||||
|
# - cid: Circuit_ID-2
|
||||||
|
# provider: Provider2
|
||||||
|
# type: MPLS
|
4
initializers/cluster_groups.yml
Normal file
4
initializers/cluster_groups.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# - name: Group 1
|
||||||
|
# slug: group-1
|
||||||
|
# - name: Group 2
|
||||||
|
# slug: group-2
|
@ -1,5 +1,7 @@
|
|||||||
# - name: cluster1
|
# - name: cluster1
|
||||||
# type: Hyper-V
|
# type: Hyper-V
|
||||||
|
# group: Group 1
|
||||||
|
# tenant: tenant1
|
||||||
# - name: cluster2
|
# - name: cluster2
|
||||||
# type: Hyper-V
|
# type: Hyper-V
|
||||||
# site: SING 1
|
# site: SING 1
|
||||||
|
@ -43,20 +43,16 @@
|
|||||||
# required: false
|
# required: false
|
||||||
# filter_logic: exact
|
# filter_logic: exact
|
||||||
# weight: 30
|
# weight: 30
|
||||||
|
# default: First Item
|
||||||
# on_objects:
|
# on_objects:
|
||||||
# - dcim.models.Device
|
# - dcim.models.Device
|
||||||
# choices:
|
# choices:
|
||||||
# - value: First Item
|
# - First Item
|
||||||
# weight: 10
|
# - Second Item
|
||||||
# - value: Second Item
|
# - Third Item
|
||||||
# weight: 20
|
# - Fifth Item
|
||||||
# - value: Third Item
|
# - Fourth Item
|
||||||
# weight: 30
|
# select_field_legacy_format:
|
||||||
# - value: Fifth Item
|
|
||||||
# weight: 50
|
|
||||||
# - value: Fourth Item
|
|
||||||
# weight: 40
|
|
||||||
# select_field_auto_weight:
|
|
||||||
# type: select
|
# type: select
|
||||||
# label: Choose between items
|
# label: Choose between items
|
||||||
# required: false
|
# required: false
|
||||||
@ -65,9 +61,9 @@
|
|||||||
# on_objects:
|
# on_objects:
|
||||||
# - dcim.models.Device
|
# - dcim.models.Device
|
||||||
# choices:
|
# choices:
|
||||||
# - value: A
|
# - value: A # this is the deprecated format.
|
||||||
# - value: B
|
# - value: B # we only use it for the tests.
|
||||||
# - value: C
|
# - value: C # please see above for the new format.
|
||||||
# - value: "D like deprecated"
|
# - value: "D like deprecated"
|
||||||
# weight: 999
|
# weight: 999
|
||||||
# - value: E
|
# - value: E
|
||||||
@ -76,7 +72,7 @@
|
|||||||
# label: Yes Or No?
|
# label: Yes Or No?
|
||||||
# required: true
|
# required: true
|
||||||
# filter_logic: loose
|
# filter_logic: loose
|
||||||
# default: "false" # important: but "false" in quotes!
|
# default: "false" # important: put "false" in quotes!
|
||||||
# weight: 90
|
# weight: 90
|
||||||
# on_objects:
|
# on_objects:
|
||||||
# - dcim.models.Device
|
# - dcim.models.Device
|
||||||
|
@ -2,22 +2,22 @@
|
|||||||
# manufacturer: Manufacturer 1
|
# manufacturer: Manufacturer 1
|
||||||
# slug: model-1
|
# slug: model-1
|
||||||
# u_height: 2
|
# u_height: 2
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
# - model: Model 2
|
# - model: Model 2
|
||||||
# manufacturer: Manufacturer 1
|
# manufacturer: Manufacturer 1
|
||||||
# slug: model-2
|
# slug: model-2
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
# - model: Model 3
|
# - model: Model 3
|
||||||
# manufacturer: Manufacturer 1
|
# manufacturer: Manufacturer 1
|
||||||
# slug: model-3
|
# slug: model-3
|
||||||
# is_full_depth: false
|
# is_full_depth: false
|
||||||
# u_height: 0
|
# u_height: 0
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
# - model: Other
|
# - model: Other
|
||||||
# manufacturer: No Name
|
# manufacturer: No Name
|
||||||
# slug: other
|
# slug: other
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
# rack: rack-01
|
# rack: rack-01
|
||||||
# face: front
|
# face: front
|
||||||
# position: 1
|
# position: 1
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
# - name: server02
|
# - name: server02
|
||||||
# device_role: server
|
# device_role: server
|
||||||
@ -29,7 +29,9 @@
|
|||||||
# rack: rack-02
|
# rack: rack-02
|
||||||
# face: front
|
# face: front
|
||||||
# position: 2
|
# position: 2
|
||||||
# custom_fields:
|
# primary_ip4: 10.1.1.2/24
|
||||||
|
# primary_ip6: 2001:db8:a000:1::2/64
|
||||||
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
# - name: server03
|
# - name: server03
|
||||||
# device_role: server
|
# device_role: server
|
||||||
@ -38,5 +40,5 @@
|
|||||||
# rack: rack-03
|
# rack: rack-03
|
||||||
# face: front
|
# face: front
|
||||||
# position: 3
|
# position: 3
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
|
14
initializers/power_feeds.yml
Normal file
14
initializers/power_feeds.yml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# - name: power feed 1
|
||||||
|
# power_panel: power panel AMS 1
|
||||||
|
# voltage: 208
|
||||||
|
# amperage: 50
|
||||||
|
# max_utilization: 80
|
||||||
|
# phase: Single phase
|
||||||
|
# rack: rack-01
|
||||||
|
# - name: power feed 2
|
||||||
|
# power_panel: power panel SING 1
|
||||||
|
# voltage: 208
|
||||||
|
# amperage: 50
|
||||||
|
# max_utilization: 80
|
||||||
|
# phase: Three-phase
|
||||||
|
# rack: rack-03
|
5
initializers/power_panels.yml
Normal file
5
initializers/power_panels.yml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# - name: power panel AMS 1
|
||||||
|
# site: AMS 1
|
||||||
|
# - name: power panel SING 1
|
||||||
|
# site: SING 1
|
||||||
|
# rack_group: cage 101
|
6
initializers/providers.yml
Normal file
6
initializers/providers.yml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# - name: Provider1
|
||||||
|
# slug: provider1
|
||||||
|
# asn: 121
|
||||||
|
# - name: Provider2
|
||||||
|
# slug: provider2
|
||||||
|
# asn: 122
|
@ -20,7 +20,7 @@
|
|||||||
# type: 4-post-cabinet
|
# type: 4-post-cabinet
|
||||||
# width: 19
|
# width: 19
|
||||||
# u_height: 47
|
# u_height: 47
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
# - site: AMS 2
|
# - site: AMS 2
|
||||||
# name: rack-02
|
# name: rack-02
|
||||||
@ -28,7 +28,7 @@
|
|||||||
# type: 4-post-cabinet
|
# type: 4-post-cabinet
|
||||||
# width: 19
|
# width: 19
|
||||||
# u_height: 47
|
# u_height: 47
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
# - site: SING 1
|
# - site: SING 1
|
||||||
# name: rack-03
|
# name: rack-03
|
||||||
@ -37,5 +37,5 @@
|
|||||||
# type: 4-post-cabinet
|
# type: 4-post-cabinet
|
||||||
# width: 19
|
# width: 19
|
||||||
# u_height: 47
|
# u_height: 47
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description
|
||||||
|
3
initializers/route_targets.yml
Normal file
3
initializers/route_targets.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# - name: 65000:1001
|
||||||
|
# tenant: tenant1
|
||||||
|
# - name: 65000:1002
|
4
initializers/secret_roles.yml
Normal file
4
initializers/secret_roles.yml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# - name: Super Secret Passwords
|
||||||
|
# slug: super-secret
|
||||||
|
# - name: SNMP Communities
|
||||||
|
# slug: snmp
|
15
initializers/services.yml
Normal file
15
initializers/services.yml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# - name: DNS
|
||||||
|
# protocol: TCP
|
||||||
|
# ports:
|
||||||
|
# - 53
|
||||||
|
# virtual_machine: virtual machine 1
|
||||||
|
# - name: DNS
|
||||||
|
# protocol: UDP
|
||||||
|
# ports:
|
||||||
|
# - 53
|
||||||
|
# virtual_machine: virtual machine 1
|
||||||
|
# - name: MISC
|
||||||
|
# protocol: UDP
|
||||||
|
# ports:
|
||||||
|
# - 4000
|
||||||
|
# device: server01
|
@ -1,32 +1,32 @@
|
|||||||
# - name: AMS 1
|
# - name: AMS 1
|
||||||
# slug: ams1
|
# slug: ams1
|
||||||
# region: Downtown
|
# region: Downtown
|
||||||
# status: 1
|
# status: active
|
||||||
# facility: Amsterdam 1
|
# facility: Amsterdam 1
|
||||||
# asn: 12345
|
# asn: 12345
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description for AMS1
|
||||||
# - name: AMS 2
|
# - name: AMS 2
|
||||||
# slug: ams2
|
# slug: ams2
|
||||||
# region: Downtown
|
# region: Downtown
|
||||||
# status: 1
|
# status: active
|
||||||
# facility: Amsterdam 2
|
# facility: Amsterdam 2
|
||||||
# asn: 54321
|
# asn: 54321
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description for AMS2
|
||||||
# - name: AMS 3
|
# - name: AMS 3
|
||||||
# slug: ams3
|
# slug: ams3
|
||||||
# region: Suburbs
|
# region: Suburbs
|
||||||
# status: 1
|
# status: active
|
||||||
# facility: Amsterdam 3
|
# facility: Amsterdam 3
|
||||||
# asn: 67890
|
# asn: 67890
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description for AMS3
|
||||||
# - name: SING 1
|
# - name: SING 1
|
||||||
# slug: sing1
|
# slug: sing1
|
||||||
# region: Singapore
|
# region: Singapore
|
||||||
# status: 1
|
# status: active
|
||||||
# facility: Singapore 1
|
# facility: Singapore 1
|
||||||
# asn: 09876
|
# asn: 09876
|
||||||
# custom_fields:
|
# custom_field_data:
|
||||||
# text_field: Description
|
# text_field: Description for SING1
|
||||||
|
12
initializers/tags.yml
Normal file
12
initializers/tags.yml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# - name: Tag 1
|
||||||
|
# slug: tag-1
|
||||||
|
# color: Pink
|
||||||
|
# - name: Tag 2
|
||||||
|
# slug: tag-2
|
||||||
|
# color: Cyan
|
||||||
|
# - name: Tag 3
|
||||||
|
# slug: tag-3
|
||||||
|
# color: Grey
|
||||||
|
# - name: Tag 4
|
||||||
|
# slug: tag-4
|
||||||
|
# color: Teal
|
@ -21,6 +21,8 @@
|
|||||||
# memory: 2048
|
# memory: 2048
|
||||||
# name: virtual machine 2
|
# name: virtual machine 2
|
||||||
# platform: Platform 2
|
# platform: Platform 2
|
||||||
|
# primary_ip4: 10.1.1.10/24
|
||||||
|
# primary_ip6: 2001:db8:a000:1::10/64
|
||||||
# status: active
|
# status: active
|
||||||
# tenant: tenant1
|
# tenant: tenant1
|
||||||
# vcpus: 8
|
# vcpus: 8
|
||||||
|
13
renovate.json
Normal file
13
renovate.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"extends": [
|
||||||
|
"config:base"
|
||||||
|
],
|
||||||
|
"enabled": true,
|
||||||
|
"labels": ["maintenance"],
|
||||||
|
"baseBranches": ["develop"],
|
||||||
|
"pip_requirements": {
|
||||||
|
"fileMatch": [
|
||||||
|
"requirements-container.txt"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
4
requirements-container.txt
Normal file
4
requirements-container.txt
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
napalm==3.2.0
|
||||||
|
ruamel.yaml==0.16.12
|
||||||
|
django-auth-ldap==2.2.0
|
||||||
|
django-storages==1.11.1
|
@ -1,6 +1,6 @@
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from django.contrib.auth.models import Group, User
|
from django.contrib.auth.models import User
|
||||||
from startup_script_utils import load_yaml, set_permissions
|
from startup_script_utils import load_yaml, set_permissions
|
||||||
from users.models import Token
|
from users.models import Token
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from extras.models import CustomField, CustomFieldChoice
|
|
||||||
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from extras.models import CustomField
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
|
||||||
def get_class_for_class_path(class_path):
|
def get_class_for_class_path(class_path):
|
||||||
import importlib
|
import importlib
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
@ -21,34 +21,38 @@ for cf_name, cf_details in customfields.items():
|
|||||||
custom_field, created = CustomField.objects.get_or_create(name = cf_name)
|
custom_field, created = CustomField.objects.get_or_create(name = cf_name)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if cf_details.get('default', 0):
|
if cf_details.get('default', False):
|
||||||
custom_field.default = cf_details['default']
|
custom_field.default = cf_details['default']
|
||||||
|
|
||||||
if cf_details.get('description', 0):
|
if cf_details.get('description', False):
|
||||||
custom_field.description = cf_details['description']
|
custom_field.description = cf_details['description']
|
||||||
|
|
||||||
if cf_details.get('label', 0):
|
if cf_details.get('label', False):
|
||||||
custom_field.label = cf_details['label']
|
custom_field.label = cf_details['label']
|
||||||
|
|
||||||
for object_type in cf_details.get('on_objects', []):
|
for object_type in cf_details.get('on_objects', []):
|
||||||
custom_field.obj_type.add(get_class_for_class_path(object_type))
|
custom_field.content_types.add(get_class_for_class_path(object_type))
|
||||||
|
|
||||||
if cf_details.get('required', 0):
|
if cf_details.get('required', False):
|
||||||
custom_field.required = cf_details['required']
|
custom_field.required = cf_details['required']
|
||||||
|
|
||||||
if cf_details.get('type', 0):
|
if cf_details.get('type', False):
|
||||||
custom_field.type = cf_details['type']
|
custom_field.type = cf_details['type']
|
||||||
|
|
||||||
if cf_details.get('weight', 0):
|
if cf_details.get('weight', -1) >= 0:
|
||||||
custom_field.weight = cf_details['weight']
|
custom_field.weight = cf_details['weight']
|
||||||
|
|
||||||
|
if cf_details.get('choices', False):
|
||||||
|
custom_field.choices = []
|
||||||
|
|
||||||
|
for choice_detail in cf_details.get('choices', []):
|
||||||
|
if isinstance(choice_detail, dict) and 'value' in choice_detail:
|
||||||
|
# legacy mode
|
||||||
|
print(f"⚠️ Please migrate the choice '{choice_detail['value']}' of '{cf_name}' to the new format, as 'weight' is no longer supported!")
|
||||||
|
custom_field.choices.append(choice_detail['value'])
|
||||||
|
else:
|
||||||
|
custom_field.choices.append(choice_detail)
|
||||||
|
|
||||||
custom_field.save()
|
custom_field.save()
|
||||||
|
|
||||||
for idx, choice_details in enumerate(cf_details.get('choices', [])):
|
|
||||||
choice, _ = CustomFieldChoice.objects.get_or_create(
|
|
||||||
field=custom_field,
|
|
||||||
value=choice_details['value'],
|
|
||||||
defaults={'weight': idx * 10}
|
|
||||||
)
|
|
||||||
|
|
||||||
print("🔧 Created custom field", cf_name)
|
print("🔧 Created custom field", cf_name)
|
||||||
|
23
startup_scripts/020_tags.py
Normal file
23
startup_scripts/020_tags.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
from extras.models import Tag
|
||||||
|
from utilities.choices import ColorChoices
|
||||||
|
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
tags = load_yaml('/opt/netbox/initializers/tags.yml')
|
||||||
|
|
||||||
|
if tags is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in tags:
|
||||||
|
if 'color' in params:
|
||||||
|
color = params.pop('color')
|
||||||
|
|
||||||
|
for color_tpl in ColorChoices:
|
||||||
|
if color in color_tpl:
|
||||||
|
params['color'] = color_tpl[0]
|
||||||
|
|
||||||
|
tag, created = Tag.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🎨 Created Tag", tag.name)
|
@ -1,9 +1,9 @@
|
|||||||
from dcim.models import Region, Site
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from tenancy.models import Tenant
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Region, Site
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
sites = load_yaml('/opt/netbox/initializers/sites.yml')
|
sites = load_yaml('/opt/netbox/initializers/sites.yml')
|
||||||
|
|
||||||
if sites is None:
|
if sites is None:
|
||||||
@ -15,7 +15,7 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in sites:
|
for params in sites:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in optional_assocs.items():
|
||||||
if assoc in params:
|
if assoc in params:
|
||||||
@ -27,15 +27,6 @@ for params in sites:
|
|||||||
site, created = Site.objects.get_or_create(**params)
|
site, created = Site.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(site, custom_field_data)
|
||||||
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)
|
print("📍 Created site", site.name)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from dcim.models import DeviceType, Manufacturer, Region
|
|
||||||
from tenancy.models import Tenant
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import DeviceType, Manufacturer, Region
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
device_types = load_yaml('/opt/netbox/initializers/device_types.yml')
|
device_types = load_yaml('/opt/netbox/initializers/device_types.yml')
|
||||||
|
|
||||||
if device_types is None:
|
if device_types is None:
|
||||||
@ -19,7 +19,7 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in device_types:
|
for params in device_types:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -37,15 +37,6 @@ for params in device_types:
|
|||||||
device_type, created = DeviceType.objects.get_or_create(**params)
|
device_type, created = DeviceType.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(device_type, custom_field_data)
|
||||||
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)
|
print("🔡 Created device type", device_type.manufacturer, device_type.model)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from dcim.models import Site, RackRole, Rack, RackGroup
|
|
||||||
from tenancy.models import Tenant
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Site, RackRole, Rack, RackGroup
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
racks = load_yaml('/opt/netbox/initializers/racks.yml')
|
racks = load_yaml('/opt/netbox/initializers/racks.yml')
|
||||||
|
|
||||||
if racks is None:
|
if racks is None:
|
||||||
@ -20,7 +20,7 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in racks:
|
for params in racks:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -38,15 +38,6 @@ for params in racks:
|
|||||||
rack, created = Rack.objects.get_or_create(**params)
|
rack, created = Rack.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(rack, custom_field_data)
|
||||||
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)
|
print("🔳 Created rack", rack.site, rack.name)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from tenancy.models import Tenant, TenantGroup
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant, TenantGroup
|
||||||
|
|
||||||
tenants = load_yaml('/opt/netbox/initializers/tenants.yml')
|
tenants = load_yaml('/opt/netbox/initializers/tenants.yml')
|
||||||
|
|
||||||
if tenants is None:
|
if tenants is None:
|
||||||
@ -13,7 +13,7 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in tenants:
|
for params in tenants:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in optional_assocs.items():
|
||||||
if assoc in params:
|
if assoc in params:
|
||||||
@ -25,15 +25,6 @@ for params in tenants:
|
|||||||
tenant, created = Tenant.objects.get_or_create(**params)
|
tenant, created = Tenant.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(tenant, custom_field_data)
|
||||||
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=tenant,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
tenant.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("👩💻 Created Tenant", tenant.name)
|
print("👩💻 Created Tenant", tenant.name)
|
||||||
|
14
startup_scripts/135_cluster_groups.py
Normal file
14
startup_scripts/135_cluster_groups.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from virtualization.models import ClusterGroup
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
cluster_groups = load_yaml('/opt/netbox/initializers/cluster_groups.yml')
|
||||||
|
|
||||||
|
if cluster_groups is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in cluster_groups:
|
||||||
|
cluster_group, created = ClusterGroup.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🗄️ Created Cluster Group", cluster_group.name)
|
@ -1,9 +1,10 @@
|
|||||||
from dcim.models import Site
|
|
||||||
from virtualization.models import Cluster, ClusterType, ClusterGroup
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Site
|
||||||
|
from startup_script_utils import *
|
||||||
|
from virtualization.models import Cluster, ClusterType, ClusterGroup
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
clusters = load_yaml('/opt/netbox/initializers/clusters.yml')
|
clusters = load_yaml('/opt/netbox/initializers/clusters.yml')
|
||||||
|
|
||||||
if clusters is None:
|
if clusters is None:
|
||||||
@ -15,11 +16,12 @@ required_assocs = {
|
|||||||
|
|
||||||
optional_assocs = {
|
optional_assocs = {
|
||||||
'site': (Site, 'name'),
|
'site': (Site, 'name'),
|
||||||
'group': (ClusterGroup, 'name')
|
'group': (ClusterGroup, 'name'),
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
for params in clusters:
|
for params in clusters:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -37,15 +39,6 @@ for params in clusters:
|
|||||||
cluster, created = Cluster.objects.get_or_create(**params)
|
cluster, created = Cluster.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(cluster, custom_field_data)
|
||||||
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=cluster,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
cluster.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🗄️ Created cluster", cluster.name)
|
print("🗄️ Created cluster", cluster.name)
|
44
startup_scripts/140_clusters.py
Normal file
44
startup_scripts/140_clusters.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Site
|
||||||
|
from startup_script_utils import *
|
||||||
|
from virtualization.models import Cluster, ClusterType, ClusterGroup
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
|
clusters = load_yaml('/opt/netbox/initializers/clusters.yml')
|
||||||
|
|
||||||
|
if clusters is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'type': (ClusterType, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'site': (Site, 'name'),
|
||||||
|
'group': (ClusterGroup, 'name'),
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in clusters:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
cluster, created = Cluster.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(cluster, custom_field_data)
|
||||||
|
|
||||||
|
print("🗄️ Created cluster", cluster.name)
|
@ -1,11 +1,10 @@
|
|||||||
from dcim.models import Site, Rack, DeviceRole, DeviceType, Device, Platform
|
|
||||||
from ipam.models import IPAddress
|
|
||||||
from virtualization.models import Cluster
|
|
||||||
from tenancy.models import Tenant
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Site, Rack, DeviceRole, DeviceType, Device, Platform
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from virtualization.models import Cluster
|
||||||
|
|
||||||
devices = load_yaml('/opt/netbox/initializers/devices.yml')
|
devices = load_yaml('/opt/netbox/initializers/devices.yml')
|
||||||
|
|
||||||
if devices is None:
|
if devices is None:
|
||||||
@ -21,13 +20,15 @@ optional_assocs = {
|
|||||||
'tenant': (Tenant, 'name'),
|
'tenant': (Tenant, 'name'),
|
||||||
'platform': (Platform, 'name'),
|
'platform': (Platform, 'name'),
|
||||||
'rack': (Rack, 'name'),
|
'rack': (Rack, 'name'),
|
||||||
'cluster': (Cluster, 'name'),
|
'cluster': (Cluster, 'name')
|
||||||
'primary_ip4': (IPAddress, 'address'),
|
|
||||||
'primary_ip6': (IPAddress, 'address')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for params in devices:
|
for params in devices:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
# primary ips are handled later in `270_primary_ips.py`
|
||||||
|
params.pop('primary_ip4', None)
|
||||||
|
params.pop('primary_ip6', None)
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -45,15 +46,6 @@ for params in devices:
|
|||||||
device, created = Device.objects.get_or_create(**params)
|
device, created = Device.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(device, custom_field_data)
|
||||||
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)
|
print("🖥️ Created device", device.name)
|
51
startup_scripts/145_devices.py
Normal file
51
startup_scripts/145_devices.py
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Site, Rack, DeviceRole, DeviceType, Device, Platform
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from virtualization.models import Cluster
|
||||||
|
|
||||||
|
devices = load_yaml('/opt/netbox/initializers/devices.yml')
|
||||||
|
|
||||||
|
if devices is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
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')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in devices:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
# primary ips are handled later in `270_primary_ips.py`
|
||||||
|
params.pop('primary_ip4', None)
|
||||||
|
params.pop('primary_ip6', 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, created = Device.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(device, custom_field_data)
|
||||||
|
|
||||||
|
print("🖥️ Created device", device.name)
|
@ -1,11 +1,10 @@
|
|||||||
from ipam.models import Aggregate, RIR
|
|
||||||
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
|
|
||||||
from netaddr import IPNetwork
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from ipam.models import Aggregate, RIR
|
||||||
|
from netaddr import IPNetwork
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml')
|
aggregates = load_yaml('/opt/netbox/initializers/aggregates.yml')
|
||||||
|
|
||||||
if aggregates is None:
|
if aggregates is None:
|
||||||
@ -15,8 +14,13 @@ required_assocs = {
|
|||||||
'rir': (RIR, 'name')
|
'rir': (RIR, 'name')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name'),
|
||||||
|
}
|
||||||
|
|
||||||
for params in aggregates:
|
for params in aggregates:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
params['prefix'] = IPNetwork(params['prefix'])
|
params['prefix'] = IPNetwork(params['prefix'])
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
@ -25,18 +29,16 @@ for params in aggregates:
|
|||||||
|
|
||||||
params[assoc] = model.objects.get(**query)
|
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)
|
||||||
|
|
||||||
aggregate, created = Aggregate.objects.get_or_create(**params)
|
aggregate, created = Aggregate.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(aggregate, custom_field_data)
|
||||||
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=aggregate,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
aggregate.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🗞️ Created Aggregate", aggregate.prefix)
|
print("🗞️ Created Aggregate", aggregate.prefix)
|
||||||
|
14
startup_scripts/165_cluster_groups.py
Normal file
14
startup_scripts/165_cluster_groups.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from virtualization.models import ClusterGroup
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
cluster_groups = load_yaml('/opt/netbox/initializers/cluster_groups.yml')
|
||||||
|
|
||||||
|
if cluster_groups is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in cluster_groups:
|
||||||
|
cluster_group, created = ClusterGroup.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🗄️ Created Cluster Group", cluster_group.name)
|
31
startup_scripts/175_route_targets.py
Normal file
31
startup_scripts/175_route_targets.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from ipam.models import RouteTarget
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
|
route_targets = load_yaml('/opt/netbox/initializers/route_targets.yml')
|
||||||
|
|
||||||
|
if route_targets is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in route_targets:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
route_target, created = RouteTarget.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(route_target, custom_field_data)
|
||||||
|
|
||||||
|
print("🎯 Created Route Target", route_target.name)
|
@ -1,11 +1,9 @@
|
|||||||
from ipam.models import VRF
|
|
||||||
from tenancy.models import Tenant
|
|
||||||
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from ipam.models import VRF
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
vrfs = load_yaml('/opt/netbox/initializers/vrfs.yml')
|
vrfs = load_yaml('/opt/netbox/initializers/vrfs.yml')
|
||||||
|
|
||||||
if vrfs is None:
|
if vrfs is None:
|
||||||
@ -16,7 +14,7 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in vrfs:
|
for params in vrfs:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in optional_assocs.items():
|
||||||
if assoc in params:
|
if assoc in params:
|
||||||
@ -28,15 +26,6 @@ for params in vrfs:
|
|||||||
vrf, created = VRF.objects.get_or_create(**params)
|
vrf, created = VRF.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(vrf, custom_field_data)
|
||||||
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=vrf,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
vrf.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("📦 Created VRF", vrf.name)
|
print("📦 Created VRF", vrf.name)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from ipam.models import VLANGroup
|
from ipam.models import VLANGroup
|
||||||
from extras.models import CustomField, CustomFieldValue
|
from startup_script_utils import *
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
|
||||||
|
|
||||||
vlan_groups = load_yaml('/opt/netbox/initializers/vlan_groups.yml')
|
vlan_groups = load_yaml('/opt/netbox/initializers/vlan_groups.yml')
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in vlan_groups:
|
for params in vlan_groups:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in optional_assocs.items():
|
||||||
if assoc in params:
|
if assoc in params:
|
||||||
@ -26,15 +26,6 @@ for params in vlan_groups:
|
|||||||
vlan_group, created = VLANGroup.objects.get_or_create(**params)
|
vlan_group, created = VLANGroup.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(vlan_group, custom_field_data)
|
||||||
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=vlan_group,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
vlan_group.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🏘️ Created VLAN Group", vlan_group.name)
|
print("🏘️ Created VLAN Group", vlan_group.name)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from ipam.models import VLAN, VLANGroup, Role
|
from ipam.models import VLAN, VLANGroup, Role
|
||||||
|
from startup_script_utils import *
|
||||||
from tenancy.models import Tenant, TenantGroup
|
from tenancy.models import Tenant, TenantGroup
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
|
||||||
|
|
||||||
vlans = load_yaml('/opt/netbox/initializers/vlans.yml')
|
vlans = load_yaml('/opt/netbox/initializers/vlans.yml')
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in vlans:
|
for params in vlans:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in optional_assocs.items():
|
||||||
if assoc in params:
|
if assoc in params:
|
||||||
@ -31,15 +31,6 @@ for params in vlans:
|
|||||||
vlan, created = VLAN.objects.get_or_create(**params)
|
vlan, created = VLAN.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(vlan, custom_field_data)
|
||||||
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=vlan,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
vlan.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🏠 Created VLAN", vlan.name)
|
print("🏠 Created VLAN", vlan.name)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
from dcim.models import Site
|
from dcim.models import Site
|
||||||
from ipam.models import Prefix, VLAN, Role, VRF
|
from ipam.models import Prefix, VLAN, Role, VRF
|
||||||
from tenancy.models import Tenant, TenantGroup
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
from startup_script_utils import load_yaml
|
from startup_script_utils import *
|
||||||
import sys
|
from tenancy.models import Tenant, TenantGroup
|
||||||
|
|
||||||
prefixes = load_yaml('/opt/netbox/initializers/prefixes.yml')
|
prefixes = load_yaml('/opt/netbox/initializers/prefixes.yml')
|
||||||
|
|
||||||
@ -21,7 +21,8 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in prefixes:
|
for params in prefixes:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
params['prefix'] = IPNetwork(params['prefix'])
|
params['prefix'] = IPNetwork(params['prefix'])
|
||||||
|
|
||||||
for assoc, details in optional_assocs.items():
|
for assoc, details in optional_assocs.items():
|
||||||
@ -33,14 +34,6 @@ for params in prefixes:
|
|||||||
prefix, created = Prefix.objects.get_or_create(**params)
|
prefix, created = Prefix.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(prefix, custom_field_data)
|
||||||
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=prefix,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
prefix.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("📌 Created Prefix", prefix.prefix)
|
print("📌 Created Prefix", prefix.prefix)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
from dcim.models import Site, Platform, DeviceRole
|
|
||||||
from virtualization.models import Cluster, VirtualMachine
|
|
||||||
from tenancy.models import Tenant
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Platform, DeviceRole
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from virtualization.models import Cluster, VirtualMachine
|
||||||
|
|
||||||
virtual_machines = load_yaml('/opt/netbox/initializers/virtual_machines.yml')
|
virtual_machines = load_yaml('/opt/netbox/initializers/virtual_machines.yml')
|
||||||
|
|
||||||
if virtual_machines is None:
|
if virtual_machines is None:
|
||||||
@ -21,7 +21,11 @@ optional_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in virtual_machines:
|
for params in virtual_machines:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
# primary ips are handled later in `270_primary_ips.py`
|
||||||
|
params.pop('primary_ip4', None)
|
||||||
|
params.pop('primary_ip6', None)
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -39,15 +43,6 @@ for params in virtual_machines:
|
|||||||
virtual_machine, created = VirtualMachine.objects.get_or_create(**params)
|
virtual_machine, created = VirtualMachine.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(virtual_machine, custom_field_data)
|
||||||
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=virtual_machine,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
virtual_machine.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🖥️ Created virtual machine", virtual_machine.name)
|
print("🖥️ Created virtual machine", virtual_machine.name)
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
from virtualization.models import VirtualMachine, VMInterface
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
from startup_script_utils import *
|
||||||
|
from virtualization.models import VirtualMachine, VMInterface
|
||||||
|
|
||||||
interfaces = load_yaml('/opt/netbox/initializers/virtualization_interfaces.yml')
|
interfaces = load_yaml('/opt/netbox/initializers/virtualization_interfaces.yml')
|
||||||
|
|
||||||
if interfaces is None:
|
if interfaces is None:
|
||||||
@ -13,7 +13,7 @@ required_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in interfaces:
|
for params in interfaces:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -24,15 +24,6 @@ for params in interfaces:
|
|||||||
interface, created = VMInterface.objects.get_or_create(**params)
|
interface, created = VMInterface.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(interface, custom_field_data)
|
||||||
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=interface,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
interface.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🧷 Created interface", interface.name, interface.virtual_machine.name)
|
print("🧷 Created interface", interface.name, interface.virtual_machine.name)
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
from dcim.models import Interface, Device
|
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from startup_script_utils import load_yaml
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
interfaces= load_yaml('/opt/netbox/initializers/dcim_interfaces.yml')
|
from dcim.models import Interface, Device
|
||||||
|
from startup_script_utils import *
|
||||||
|
|
||||||
|
interfaces = load_yaml('/opt/netbox/initializers/dcim_interfaces.yml')
|
||||||
|
|
||||||
if interfaces is None:
|
if interfaces is None:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@ -13,7 +13,7 @@ required_assocs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for params in interfaces:
|
for params in interfaces:
|
||||||
custom_fields = params.pop('custom_fields', None)
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
for assoc, details in required_assocs.items():
|
for assoc, details in required_assocs.items():
|
||||||
model, field = details
|
model, field = details
|
||||||
@ -24,15 +24,6 @@ for params in interfaces:
|
|||||||
interface, created = Interface.objects.get_or_create(**params)
|
interface, created = Interface.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(interface, custom_field_data)
|
||||||
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=interface,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
interface.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🧷 Created interface", interface.name, interface.device.name)
|
print("🧷 Created interface", interface.name, interface.device.name)
|
||||||
|
@ -3,10 +3,9 @@ import sys
|
|||||||
from dcim.models import Device, Interface
|
from dcim.models import Device, Interface
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from extras.models import CustomField, CustomFieldValue
|
|
||||||
from ipam.models import VRF, IPAddress
|
from ipam.models import VRF, IPAddress
|
||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
from startup_script_utils import load_yaml
|
from startup_script_utils import *
|
||||||
from tenancy.models import Tenant
|
from tenancy.models import Tenant
|
||||||
from virtualization.models import VirtualMachine, VMInterface
|
from virtualization.models import VirtualMachine, VMInterface
|
||||||
|
|
||||||
@ -25,9 +24,10 @@ vm_interface_ct = ContentType.objects.filter(Q(app_label='virtualization', model
|
|||||||
interface_ct = ContentType.objects.filter(Q(app_label='dcim', model='interface')).first()
|
interface_ct = ContentType.objects.filter(Q(app_label='dcim', model='interface')).first()
|
||||||
|
|
||||||
for params in ip_addresses:
|
for params in ip_addresses:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
vm = params.pop('virtual_machine', None)
|
vm = params.pop('virtual_machine', None)
|
||||||
device = params.pop('device', None)
|
device = params.pop('device', None)
|
||||||
custom_fields = params.pop('custom_fields', None)
|
|
||||||
params['address'] = IPNetwork(params['address'])
|
params['address'] = IPNetwork(params['address'])
|
||||||
|
|
||||||
if vm and device:
|
if vm and device:
|
||||||
@ -55,15 +55,6 @@ for params in ip_addresses:
|
|||||||
ip_address, created = IPAddress.objects.get_or_create(**params)
|
ip_address, created = IPAddress.objects.get_or_create(**params)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
if custom_fields is not None:
|
set_custom_fields_values(ip_address, custom_field_data)
|
||||||
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=ip_address,
|
|
||||||
value=cf_value
|
|
||||||
)
|
|
||||||
|
|
||||||
ip_address.custom_field_values.add(custom_field_value)
|
|
||||||
|
|
||||||
print("🧬 Created IP Address", ip_address.address)
|
print("🧬 Created IP Address", ip_address.address)
|
||||||
|
44
startup_scripts/270_primary_ips.py
Normal file
44
startup_scripts/270_primary_ips.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
from dcim.models import Device
|
||||||
|
from ipam.models import IPAddress
|
||||||
|
from virtualization.models import VirtualMachine
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def link_primary_ip(assets, asset_model):
|
||||||
|
for params in assets:
|
||||||
|
primary_ip_fields = set(params) & {'primary_ip4', 'primary_ip6'}
|
||||||
|
if not primary_ip_fields:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for assoc, details in optional_assocs.items():
|
||||||
|
if assoc in params:
|
||||||
|
model, field = details
|
||||||
|
query = { field: params.pop(assoc) }
|
||||||
|
|
||||||
|
try:
|
||||||
|
params[assoc] = model.objects.get(**query)
|
||||||
|
except model.DoesNotExist:
|
||||||
|
primary_ip_fields -= {assoc}
|
||||||
|
print(f"⚠️ IP Address '{query[field]}' not found")
|
||||||
|
|
||||||
|
asset = asset_model.objects.get(name=params['name'])
|
||||||
|
for field in primary_ip_fields:
|
||||||
|
if getattr(asset, field) != params[field]:
|
||||||
|
setattr(asset, field, params[field])
|
||||||
|
print(f"🔗 Define primary IP '{params[field].address}' on '{asset.name}'")
|
||||||
|
asset.save()
|
||||||
|
|
||||||
|
devices = load_yaml('/opt/netbox/initializers/devices.yml')
|
||||||
|
virtual_machines = load_yaml('/opt/netbox/initializers/virtual_machines.yml')
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'primary_ip4': (IPAddress, 'address'),
|
||||||
|
'primary_ip6': (IPAddress, 'address')
|
||||||
|
}
|
||||||
|
|
||||||
|
if devices is None and virtual_machines is None:
|
||||||
|
sys.exit()
|
||||||
|
if devices is not None:
|
||||||
|
link_primary_ip(devices, Device)
|
||||||
|
if virtual_machines is not None:
|
||||||
|
link_primary_ip(virtual_machines, VirtualMachine)
|
18
startup_scripts/280_providers.py
Normal file
18
startup_scripts/280_providers.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from circuits.models import Provider
|
||||||
|
from startup_script_utils import *
|
||||||
|
import sys
|
||||||
|
|
||||||
|
providers = load_yaml('/opt/netbox/initializers/providers.yml')
|
||||||
|
|
||||||
|
if providers is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in providers:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
provider, created = Provider.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(provider, custom_field_data)
|
||||||
|
|
||||||
|
print("📡 Created provider", provider.name)
|
18
startup_scripts/290_circuit_types.py
Normal file
18
startup_scripts/290_circuit_types.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from circuits.models import CircuitType
|
||||||
|
from startup_script_utils import *
|
||||||
|
import sys
|
||||||
|
|
||||||
|
circuit_types = load_yaml('/opt/netbox/initializers/circuit_types.yml')
|
||||||
|
|
||||||
|
if circuit_types is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in circuit_types:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
circuit_type, created = CircuitType.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(circuit_type, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Circuit Type", circuit_type.name)
|
41
startup_scripts/300_circuits.py
Normal file
41
startup_scripts/300_circuits.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from circuits.models import Circuit, Provider, CircuitType
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
from startup_script_utils import *
|
||||||
|
import sys
|
||||||
|
|
||||||
|
circuits = load_yaml('/opt/netbox/initializers/circuits.yml')
|
||||||
|
|
||||||
|
if circuits is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'provider': (Provider, 'name'),
|
||||||
|
'type': (CircuitType, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'tenant': (Tenant, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in circuits:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
circuit, created = Circuit.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(circuit, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Circuit", circuit.cid)
|
14
startup_scripts/310_secret_roles.py
Normal file
14
startup_scripts/310_secret_roles.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
from secrets.models import SecretRole
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
secret_roles = load_yaml('/opt/netbox/initializers/secret_roles.yml')
|
||||||
|
|
||||||
|
if secret_roles is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
for params in secret_roles:
|
||||||
|
secret_role, created = SecretRole.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🔑 Created Secret Role", secret_role.name)
|
29
startup_scripts/320_services.py
Normal file
29
startup_scripts/320_services.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from ipam.models import Service
|
||||||
|
from dcim.models import Device
|
||||||
|
from virtualization.models import VirtualMachine
|
||||||
|
from startup_script_utils import load_yaml
|
||||||
|
import sys
|
||||||
|
|
||||||
|
services = load_yaml('/opt/netbox/initializers/services.yml')
|
||||||
|
|
||||||
|
if services is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'device': (Device, 'name'),
|
||||||
|
'virtual_machine': (VirtualMachine, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in services:
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
service, created = Service.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
print("🧰 Created Service", service.name)
|
41
startup_scripts/330_power_panels.py
Normal file
41
startup_scripts/330_power_panels.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Site, RackGroup, PowerPanel
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
|
power_panels = load_yaml('/opt/netbox/initializers/power_panels.yml')
|
||||||
|
|
||||||
|
if power_panels is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'site': (Site, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'rack_group': (RackGroup, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in power_panels:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
power_panel, created = PowerPanel.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(power_panel, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Power Panel", power_panel.site, power_panel.name)
|
41
startup_scripts/340_power_feeds.py
Normal file
41
startup_scripts/340_power_feeds.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from dcim.models import Rack, PowerPanel, PowerFeed
|
||||||
|
from startup_script_utils import *
|
||||||
|
from tenancy.models import Tenant
|
||||||
|
|
||||||
|
power_feeds = load_yaml('/opt/netbox/initializers/power_feeds.yml')
|
||||||
|
|
||||||
|
if power_feeds is None:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
required_assocs = {
|
||||||
|
'power_panel': (PowerPanel, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
optional_assocs = {
|
||||||
|
'rack': (Rack, 'name')
|
||||||
|
}
|
||||||
|
|
||||||
|
for params in power_feeds:
|
||||||
|
custom_field_data = pop_custom_fields(params)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
power_feed, created = PowerFeed.objects.get_or_create(**params)
|
||||||
|
|
||||||
|
if created:
|
||||||
|
set_custom_fields_values(power_feed, custom_field_data)
|
||||||
|
|
||||||
|
print("⚡ Created Power Feed", power_feed.name)
|
@ -9,7 +9,7 @@ this_dir = dirname(abspath(__file__))
|
|||||||
def filename(f):
|
def filename(f):
|
||||||
return f.name
|
return f.name
|
||||||
|
|
||||||
with scandir(dirname(abspath(__file__))) as it:
|
with scandir(this_dir) as it:
|
||||||
for f in sorted(it, key = filename):
|
for f in sorted(it, key = filename):
|
||||||
if not f.is_file():
|
if not f.is_file():
|
||||||
continue
|
continue
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
from .load_yaml import load_yaml
|
from .load_yaml import load_yaml
|
||||||
from .permissions import set_permissions
|
from .permissions import set_permissions
|
||||||
|
from .custom_fields import set_custom_fields_values, pop_custom_fields
|
||||||
|
15
startup_scripts/startup_script_utils/custom_fields.py
Normal file
15
startup_scripts/startup_script_utils/custom_fields.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
def set_custom_fields_values(entity, custom_field_data):
|
||||||
|
if not custom_field_data:
|
||||||
|
return
|
||||||
|
|
||||||
|
entity.custom_field_data = custom_field_data
|
||||||
|
return entity.save()
|
||||||
|
|
||||||
|
def pop_custom_fields(params):
|
||||||
|
if 'custom_field_data' in params:
|
||||||
|
return params.pop('custom_field_data')
|
||||||
|
elif 'custom_fields' in params:
|
||||||
|
print("⚠️ Please rename 'custom_fields' to 'custom_field_data'!")
|
||||||
|
return params.pop('custom_fields')
|
||||||
|
|
||||||
|
return None
|
@ -1,5 +1,6 @@
|
|||||||
from ruamel.yaml import YAML
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
|
||||||
def load_yaml(yaml_file: str):
|
def load_yaml(yaml_file: str):
|
||||||
yf = Path(yaml_file)
|
yf = Path(yaml_file)
|
||||||
|
25
test.sh
25
test.sh
@ -1,12 +1,29 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Runs the original Netbox unit tests and tests whether all initializers work.
|
||||||
|
# Usage:
|
||||||
|
# ./test.sh latest
|
||||||
|
# ./test.sh v2.9.7
|
||||||
|
# ./test.sh develop-2.10
|
||||||
|
# IMAGE='netboxcommunity/netbox:latest' ./test.sh
|
||||||
|
# IMAGE='netboxcommunity/netbox:v2.9.7' ./test.sh
|
||||||
|
# IMAGE='netboxcommunity/netbox:develop-2.10' ./test.sh
|
||||||
|
# export IMAGE='netboxcommunity/netbox:latest'; ./test.sh
|
||||||
|
# export IMAGE='netboxcommunity/netbox:v2.9.7'; ./test.sh
|
||||||
|
# export IMAGE='netboxcommunity/netbox:develop-2.10'; ./test.sh
|
||||||
|
|
||||||
# exit when a command exits with an exit code != 0
|
# exit when a command exits with an exit code != 0
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# version is used by `docker-compose.yml` do determine the tag
|
# IMAGE is used by `docker-compose.yml` do determine the tag
|
||||||
# of the Docker Image that is to be used
|
# of the Docker Image that is to be used
|
||||||
export IMAGE="${IMAGE-netboxcommunity/netbox:latest}"
|
if [ "${1}x" != "x" ]; then
|
||||||
|
# Use the command line argument
|
||||||
|
export IMAGE="netboxcommunity/netbox:${1}"
|
||||||
|
else
|
||||||
|
export IMAGE="${IMAGE-netboxcommunity/netbox:latest}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure that an IMAGE is defined
|
||||||
if [ -z "${IMAGE}" ]; then
|
if [ -z "${IMAGE}" ]; then
|
||||||
echo "⚠️ No image defined"
|
echo "⚠️ No image defined"
|
||||||
|
|
||||||
@ -18,7 +35,7 @@ if [ -z "${IMAGE}" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# The docker compose command to use
|
# The docker compose command to use
|
||||||
doco="docker-compose -f docker-compose.test.yml"
|
doco="docker-compose --file docker-compose.test.yml --project-name netbox_docker_test_${1}"
|
||||||
|
|
||||||
INITIALIZERS_DIR=".initializers"
|
INITIALIZERS_DIR=".initializers"
|
||||||
|
|
||||||
@ -39,7 +56,7 @@ test_setup() {
|
|||||||
|
|
||||||
test_netbox_unit_tests() {
|
test_netbox_unit_tests() {
|
||||||
echo "⏱ Running Netbox Unit Tests"
|
echo "⏱ Running Netbox Unit Tests"
|
||||||
$doco run --rm netbox ./manage.py test
|
SKIP_STARTUP_SCRIPTS=true $doco run --rm netbox ./manage.py test
|
||||||
}
|
}
|
||||||
|
|
||||||
test_initializers() {
|
test_initializers() {
|
||||||
|
Reference in New Issue
Block a user