From 59995a8719870acd476cd76d06713726052275c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Sat, 27 Feb 2021 14:43:19 +0100 Subject: [PATCH 01/21] Add release script --- release.sh | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100755 release.sh diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..46b0893 --- /dev/null +++ b/release.sh @@ -0,0 +1,189 @@ +#!/bin/bash + +DEFAULT_REPO="cimnine/netbox-docker" +# DEFAULT_REPO=netbox-community/netbox-docker +REPO="${REPO-${DEFAULT_REPO}}" + +echomoji() { + EMOJI=${1} + TEXT=${2} + shift 2 + if [ -z "$DISABLE_EMOJI" ]; then + echo "${EMOJI}" "${@}" + else + echo "${TEXT}" "${@}" + fi +} + +echo_nok() { + echomoji "❌" "!" "${@}" +} +echo_ok() { + echomoji "✅" "-" "${@}" +} +echo_hint() { + echomoji "👉" ">" "${@}" +} + +# check errors shall exit with code 1 + +check_clean_repo() { + changes=$(git status --porcelain 2>/dev/null) + if [ ${?} ] && [ -n "$changes" ]; then + echo_nok "There are git changes pending:" + echo "$changes" + echo_hint "Please clean the repository before continueing: git stash --include-untracked" + exit 1 + fi + echo_ok "Repository has no pending changes." +} + +check_branch() { + expected_branch="${1}" + actual_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) + if [ ${?} ] && [ "${actual_branch}" != "${expected_branch}" ]; then + echo_nok "Current branch should be '${expected_branch}', but is '${actual_branch}'." + echo_hint "Please change to the '${expected_branch}' branch: git checkout ${expected_branch}" + exit 1 + fi + echo_ok "The current branch is '${actual_branch}'." +} + +check_upstream() { + expected_upstream_branch="origin/${1}" + actual_upstream_branch=$(git rev-parse --abbrev-ref '@{upstream}' 2>/dev/null) + if [ ${?} ] && [ "${actual_upstream_branch}" != "${expected_upstream_branch}" ]; then + echo_nok "Current upstream branch should be '${expected_upstream_branch}', but is '${actual_upstream_branch}'." + echo_hint "Please set '${expected_upstream_branch}' as the upstream branch: git branch --set-upstream-to=${expected_upstream_branch}" + exit 1 + fi + echo_ok "The current upstream branch is '${actual_upstream_branch}'." +} + +check_origin() { + expected_origin="git@github.com:${REPO}.git" + actual_origin=$(git remote get-url origin 2>/dev/null) + if [ ${?} ] && [ "${actual_origin}" != "${expected_origin}" ]; then + echo_nok "The url of origin is '${actual_origin}', but '${expected_origin}' is expected." + echo_hint "Please set '${expected_origin}' as the url for origin: git origin set-url '${expected_origin}'" + exit 1 + fi + echo_ok "The current origin url is '${actual_origin}'." +} + +check_latest() { + git fetch --tags origin + + local_head_commit=$(git rev-parse HEAD 2>/dev/null) + remote_head_commit=$(git rev-parse FETCH_HEAD 2>/dev/null) + if [ "${local_head_commit}" != "${remote_head_commit}" ]; then + echo_nok "HEAD is at '${local_head_commit}', but FETCH_HEAD is at '${remote_head_commit}'." + echo_hint "Please ensure that you have pushed and pulled all the latest chanegs: git pull --prune --rebase origin; git push origin" + exit 1 + fi + echo_ok "HEAD and FETCH_HEAD both point to '${local_head_commit}'." +} + +check_tag() { + local tag + + tag=$(/dev/null >/dev/null; then + echo_nok "The tag '${tag}' already points to '$(git rev-parse "${tag}" 2>/dev/null)'." + echo_hint "Please ensure that the 'VERSION' file has been updated before trying to release: echo X.Y.Z > VERSION" + exit 1 + fi + echo_ok "The tag '${tag}' does not exist yet." +} + +check_develop() { + echomoji 📋 "?" "Checking 'develop' branch" + + check_branch develop + check_upstream develop + check_clean_repo + check_latest +} + +check_release() { + echomoji 📋 "?" "Checking 'release' branch" + + check_upstream release + check_clean_repo + check_latest +} + +# git errors shall exit with code 2 + +git_switch() { + echomoji 🔀 "≈" "Switching to '${1}' branch…" + if ! git checkout "${1}" >/dev/null; then + echo_nok "It was not possible to switch to the branch '${1}'." + exit 2 + fi + echo_ok "The branch is now '${1}'." +} + +git_tag() { + echomoji 🏷 "X" "Tagging version '${1}'…" + if ! git tag "${1}"; then + echo_nok "The tag '${1}' was not created because of an error." + exit 2 + fi + echo_ok "The tag '$( Date: Mon, 1 Mar 2021 08:27:24 +0100 Subject: [PATCH 02/21] Fix DEFAULT_REPO in release.sh --- release.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/release.sh b/release.sh index 46b0893..5294799 100755 --- a/release.sh +++ b/release.sh @@ -1,7 +1,6 @@ #!/bin/bash -DEFAULT_REPO="cimnine/netbox-docker" -# DEFAULT_REPO=netbox-community/netbox-docker +DEFAULT_REPO=netbox-community/netbox-docker REPO="${REPO-${DEFAULT_REPO}}" echomoji() { From 0125ab4849b3605f382d6381b61d904eee20e5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Thu, 4 Mar 2021 09:59:05 +0100 Subject: [PATCH 03/21] New Slack and wording improvements in templates --- .github/ISSUE_TEMPLATE/bug_report.md | 55 +++++++++++++++-------- .github/ISSUE_TEMPLATE/config.yml | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 46 ++++++++++++------- README.md | 14 +++--- 4 files changed, 77 insertions(+), 40 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index e11e37f..f386e8c 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,6 +1,6 @@ --- name: Bug report -about: Create a report to help us improve +about: Create a report about a malfunction of the Docker setup title: '' labels: '' assignees: '' @@ -9,39 +9,49 @@ assignees: '' ## Current Behavior -... + + ## Expected Behavior -... + + ## Debug Information - + + The output of `docker-compose version`: `XXXXX` The output of `docker version`: `XXXXX` The output of `git rev-parse HEAD`: `XXXXX` @@ -59,7 +69,16 @@ The output of `docker inspect netboxcommunity/netbox:latest --format "{{json .Co The output of `docker-compose logs netbox`: + +```text +LOG LOG LOG +``` + +The output of `cat docker-compose.override.yml`: + ```text diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index fe9f090..a584cc2 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -5,7 +5,7 @@ contact_links: about: The Github Discussions are the right place to ask questions about how to use or do certain things with NetBox Docker. - name: Chat - url: http://slack.networktocode.com/ + url: https://join.slack.com/t/netdev-community/shared_invite/zt-mtts8g0n-Sm6Wutn62q_M4OdsaIycrQ about: 'Usually the quickest way to seek help with small issues is to join our #netbox-docker Slack channel.' - name: Community Wiki diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index c9acfcf..38bba42 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -9,39 +9,52 @@ assignees: '' ## Desired Behavior -... + + ## Contrast to Current Behavior -... + + ## Changes Required -... + + ## Discussion: Benefits and Drawbacks @@ -51,4 +64,5 @@ Please make your case here: - What are the drawbacks of this change? Is it backwards-compatible? - Anything else that you think is relevant to the discussion of this feature/change request. --> -... + + diff --git a/README.md b/README.md index 8458fea..fa0c9bd 100644 --- a/README.md +++ b/README.md @@ -11,15 +11,17 @@ 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? -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 [our Slack][netbox-docker-slack] and ask for help in the [`#netbox-docker`][netbox-docker-slack-channel] channel. [github-stargazers]: https://github.com/netbox-community/netbox-docker/stargazers [github-release]: https://github.com/netbox-community/netbox-docker/releases [netbox-docker-microbadger]: https://microbadger.com/images/netboxcommunity/netbox [netbox-dockerhub]: https://hub.docker.com/r/netboxcommunity/netbox/ [netbox-docker-github]: https://github.com/netbox-community/netbox-docker/ -[ntc-slack]: http://slack.networktocode.com/ -[netbox-docker-slack]: https://slack.com/app_redirect?channel=netbox-docker&team=T09LQ7E9E +[netbox-docker-slack]: https://join.slack.com/t/netdev-community/shared_invite/zt-mtts8g0n-Sm6Wutn62q_M4OdsaIycrQ +[netbox-docker-slack-channel]: https://netdev-community.slack.com/archives/C01P0GEVBU7 +[netbox-slack-channel]: https://netdev-community.slack.com/archives/C01P0FRSXRV [netbox-docker-license]: https://github.com/netbox-community/netbox-docker/blob/release/LICENSE [netbox-quayio]: https://quay.io/repository/netboxcommunity/netbox @@ -84,10 +86,12 @@ It covers advanced topics such as using files for secrets, deployment to Kuberne ## Getting Help -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], +Feel free to ask questions in our [Github Community][netbox-community] +or [join our Slack][netbox-docker-slack] and ask [in our channel `#netbox-docker`][netbox-docker-slack-channel], 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][netbox-slack-channel] on the same Slack instance very helpful. [netbox-community]: https://github.com/netbox-community/netbox-docker/discussions From 53d593de2589d522b0b16910d6de933808014d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Thu, 4 Mar 2021 12:07:21 +0100 Subject: [PATCH 04/21] Preparation for 1.1.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6d7de6e..9084fa2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.2 +1.1.0 From ff1eed3cf0586b2595f4c4fae4375862d3912b87 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 5 Mar 2021 09:58:42 +0000 Subject: [PATCH 05/21] Update dependency ruamel.yaml to v0.16.13 --- requirements-container.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-container.txt b/requirements-container.txt index 5d2d344..05af225 100644 --- a/requirements-container.txt +++ b/requirements-container.txt @@ -1,4 +1,4 @@ napalm==3.2.0 -ruamel.yaml==0.16.12 +ruamel.yaml==0.16.13 django-auth-ldap==2.3.0 django-storages[azure,boto3,dropbox,google,libcloud,sftp]==1.11.1 From edb61f3d9007d281cf5e68d1ec21b14955b4c311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ma=CC=88der?= Date: Thu, 11 Mar 2021 18:10:09 +0100 Subject: [PATCH 06/21] Sponsor Message --- README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fa0c9bd..6cfdd95 100644 --- a/README.md +++ b/README.md @@ -134,8 +134,7 @@ It runs NetBox's own unit tests and ensures that all initializers work: IMAGE=netboxcommunity/netbox:latest ./test.sh ``` -## About +## Support -This repository is currently maintained and funded by [nxt][nxt]. - -[nxt]: https://nxt.engineering/en/ +This repository is currently maintained by the community. +Please consider sponsoring the maintainers of this project. From ce6fe5cb83691eeb28c094031279287c43d62211 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Fri, 26 Mar 2021 11:37:33 +0000 Subject: [PATCH 07/21] Update dependency ruamel.yaml to v0.17.0 --- requirements-container.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-container.txt b/requirements-container.txt index 05af225..f1d4c26 100644 --- a/requirements-container.txt +++ b/requirements-container.txt @@ -1,4 +1,4 @@ napalm==3.2.0 -ruamel.yaml==0.16.13 +ruamel.yaml==0.17.0 django-auth-ldap==2.3.0 django-storages[azure,boto3,dropbox,google,libcloud,sftp]==1.11.1 From cca79b5dbdfa6497957557cd897a31388cd4f0fd Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Mon, 29 Mar 2021 17:03:30 +0000 Subject: [PATCH 08/21] Update dependency ruamel.yaml to v0.17.2 --- requirements-container.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-container.txt b/requirements-container.txt index f1d4c26..f925cb6 100644 --- a/requirements-container.txt +++ b/requirements-container.txt @@ -1,4 +1,4 @@ napalm==3.2.0 -ruamel.yaml==0.17.0 +ruamel.yaml==0.17.2 django-auth-ldap==2.3.0 django-storages[azure,boto3,dropbox,google,libcloud,sftp]==1.11.1 From a2e33c166db166f2c9ff4f9d3c33c71b60fc164b Mon Sep 17 00:00:00 2001 From: Marcus Crane Date: Thu, 1 Apr 2021 18:48:13 +1300 Subject: [PATCH 09/21] Fix link name reference if content type is invalid Currently, the name of a custom link is referenced as if it is an object attribute which causes a break due to it actually being a dictionary. This minor change means that the startup script won't *ahem* fail upon failing :) Signed-Off-by: Marcus Crane --- startup_scripts/280_custom_links.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/startup_scripts/280_custom_links.py b/startup_scripts/280_custom_links.py index 459ede3..b611763 100644 --- a/startup_scripts/280_custom_links.py +++ b/startup_scripts/280_custom_links.py @@ -23,7 +23,7 @@ for link in custom_links: if link["content_type_id"] is None: print( "⚠️ Unable to create Custom Link '{0}': The content_type '{1}' is unknown".format( - link.name, content_type + link.get('name'), content_type ) ) continue From 594408643525e1bdaa5e74e5f18959d9890ca2e3 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 7 Apr 2021 09:15:21 +0200 Subject: [PATCH 10/21] Rack groups have been renamed to locations --- initializers/{rack_groups.yml => locations.yml} | 0 initializers/power_panels.yml | 2 +- initializers/racks.yml | 2 +- startup_scripts/{075_rack_groups.py => 075_locations.py} | 8 ++++---- startup_scripts/080_racks.py | 4 ++-- startup_scripts/330_power_panels.py | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) rename initializers/{rack_groups.yml => locations.yml} (100%) rename startup_scripts/{075_rack_groups.py => 075_locations.py} (60%) diff --git a/initializers/rack_groups.yml b/initializers/locations.yml similarity index 100% rename from initializers/rack_groups.yml rename to initializers/locations.yml diff --git a/initializers/power_panels.yml b/initializers/power_panels.yml index 1205851..a670ba7 100644 --- a/initializers/power_panels.yml +++ b/initializers/power_panels.yml @@ -2,4 +2,4 @@ # site: AMS 1 # - name: power panel SING 1 # site: SING 1 -# rack_group: cage 101 +# location: cage 101 diff --git a/initializers/racks.yml b/initializers/racks.yml index 379553d..9071e19 100644 --- a/initializers/racks.yml +++ b/initializers/racks.yml @@ -32,7 +32,7 @@ # text_field: Description # - site: SING 1 # name: rack-03 -# group: cage 101 +# location: cage 101 # role: Role 3 # type: 4-post-cabinet # width: 19 diff --git a/startup_scripts/075_rack_groups.py b/startup_scripts/075_locations.py similarity index 60% rename from startup_scripts/075_rack_groups.py rename to startup_scripts/075_locations.py index 3974b56..d8a2c5a 100644 --- a/startup_scripts/075_rack_groups.py +++ b/startup_scripts/075_locations.py @@ -1,9 +1,9 @@ import sys -from dcim.models import RackGroup, Site +from dcim.models import Location, Site from startup_script_utils import load_yaml -rack_groups = load_yaml("/opt/netbox/initializers/rack_groups.yml") +rack_groups = load_yaml("/opt/netbox/initializers/locations.yml") if rack_groups is None: sys.exit() @@ -17,7 +17,7 @@ for params in rack_groups: query = {field: params.pop(assoc)} params[assoc] = model.objects.get(**query) - rack_group, created = RackGroup.objects.get_or_create(**params) + location, created = Location.objects.get_or_create(**params) if created: - print("🎨 Created rack group", rack_group.name) + print("🎨 Created location", location.name) diff --git a/startup_scripts/080_racks.py b/startup_scripts/080_racks.py index 087b3f9..eb9bcf9 100644 --- a/startup_scripts/080_racks.py +++ b/startup_scripts/080_racks.py @@ -1,6 +1,6 @@ import sys -from dcim.models import Rack, RackGroup, RackRole, Site +from dcim.models import Rack, Location, RackRole, Site from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values from tenancy.models import Tenant @@ -14,7 +14,7 @@ required_assocs = {"site": (Site, "name")} optional_assocs = { "role": (RackRole, "name"), "tenant": (Tenant, "name"), - "group": (RackGroup, "name"), + "location": (Location, "name"), } for params in racks: diff --git a/startup_scripts/330_power_panels.py b/startup_scripts/330_power_panels.py index bfde18f..370a7b6 100644 --- a/startup_scripts/330_power_panels.py +++ b/startup_scripts/330_power_panels.py @@ -1,6 +1,6 @@ import sys -from dcim.models import PowerPanel, RackGroup, Site +from dcim.models import PowerPanel, Location, Site from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values power_panels = load_yaml("/opt/netbox/initializers/power_panels.yml") @@ -10,7 +10,7 @@ if power_panels is None: required_assocs = {"site": (Site, "name")} -optional_assocs = {"rack_group": (RackGroup, "name")} +optional_assocs = {"location": (Location, "name")} for params in power_panels: custom_field_data = pop_custom_fields(params) From 45824ba4f31b1e77ff149a7d3ead84b6bf3a7117 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 7 Apr 2021 09:57:59 +0200 Subject: [PATCH 11/21] Devices can be added to locations --- initializers/devices.yml | 9 ++++++ startup_scripts/140_devices.py | 3 +- startup_scripts/145_devices.py | 51 ---------------------------------- 3 files changed, 11 insertions(+), 52 deletions(-) delete mode 100644 startup_scripts/145_devices.py diff --git a/initializers/devices.yml b/initializers/devices.yml index 0de0504..8324c36 100644 --- a/initializers/devices.yml +++ b/initializers/devices.yml @@ -42,3 +42,12 @@ # position: 3 # custom_field_data: # text_field: Description +# - name: server04 +# device_role: server +# device_type: Other +# site: SING 1 +# location: cage 101 +# face: front +# position: 3 +# custom_field_data: +# text_field: Description diff --git a/startup_scripts/140_devices.py b/startup_scripts/140_devices.py index 597db0c..3e26c41 100644 --- a/startup_scripts/140_devices.py +++ b/startup_scripts/140_devices.py @@ -1,6 +1,6 @@ import sys -from dcim.models import Device, DeviceRole, DeviceType, Platform, Rack, Site +from dcim.models import Device, DeviceRole, DeviceType, Platform, Rack, Site, Location from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values from tenancy.models import Tenant from virtualization.models import Cluster @@ -21,6 +21,7 @@ optional_assocs = { "platform": (Platform, "name"), "rack": (Rack, "name"), "cluster": (Cluster, "name"), + "location": (Location, "name"), } for params in devices: diff --git a/startup_scripts/145_devices.py b/startup_scripts/145_devices.py deleted file mode 100644 index 597db0c..0000000 --- a/startup_scripts/145_devices.py +++ /dev/null @@ -1,51 +0,0 @@ -import sys - -from dcim.models import Device, DeviceRole, DeviceType, Platform, Rack, Site -from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values -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) From b18e4aaf92b00edfc032acf7fdad1a8009c982ec Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 7 Apr 2021 10:57:14 +0200 Subject: [PATCH 12/21] Fix super-linter on PRs See: https://github.com/github/super-linter#example-connecting-github-action-workflow --- .github/workflows/push.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 43c6482..3ea6214 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -14,6 +14,9 @@ jobs: name: Checks syntax of our code steps: - uses: actions/checkout@v2 + with: + # Full git history is needed to get a proper list of changed files within `super-linter` + fetch-depth: 0 - uses: actions/setup-python@v2 - name: Lint Code Base uses: github/super-linter@v3 From 1c4b6741ac0fe2abd4c2656fcdeb26c2d39b285f Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 7 Apr 2021 11:01:01 +0200 Subject: [PATCH 13/21] Fixed isort issues --- startup_scripts/080_racks.py | 2 +- startup_scripts/140_devices.py | 2 +- startup_scripts/330_power_panels.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/startup_scripts/080_racks.py b/startup_scripts/080_racks.py index eb9bcf9..b2cfc80 100644 --- a/startup_scripts/080_racks.py +++ b/startup_scripts/080_racks.py @@ -1,6 +1,6 @@ import sys -from dcim.models import Rack, Location, RackRole, Site +from dcim.models import Location, Rack, RackRole, Site from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values from tenancy.models import Tenant diff --git a/startup_scripts/140_devices.py b/startup_scripts/140_devices.py index 3e26c41..423b7c9 100644 --- a/startup_scripts/140_devices.py +++ b/startup_scripts/140_devices.py @@ -1,6 +1,6 @@ import sys -from dcim.models import Device, DeviceRole, DeviceType, Platform, Rack, Site, Location +from dcim.models import Device, DeviceRole, DeviceType, Location, Platform, Rack, Site from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values from tenancy.models import Tenant from virtualization.models import Cluster diff --git a/startup_scripts/330_power_panels.py b/startup_scripts/330_power_panels.py index 370a7b6..8542435 100644 --- a/startup_scripts/330_power_panels.py +++ b/startup_scripts/330_power_panels.py @@ -1,6 +1,6 @@ import sys -from dcim.models import PowerPanel, Location, Site +from dcim.models import Location, PowerPanel, Site from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values power_panels = load_yaml("/opt/netbox/initializers/power_panels.yml") From 9874cef369ba91e26e09b4151b704e20c22480c2 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 7 Apr 2021 15:18:33 +0200 Subject: [PATCH 14/21] VLAN Groups can be scoped to multiple types --- initializers/vlan_groups.yml | 22 ++++++++++++++++++++-- startup_scripts/200_vlan_groups.py | 18 +++++++++++++----- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/initializers/vlan_groups.yml b/initializers/vlan_groups.yml index 3e0bb00..a40fd0a 100644 --- a/initializers/vlan_groups.yml +++ b/initializers/vlan_groups.yml @@ -1,6 +1,24 @@ # - name: VLAN group 1 -# site: AMS 1 +# scope_type: "dcim.region" +# scope: Amsterdam # slug: vlan-group-1 # - name: VLAN group 2 -# site: AMS 1 +# scope_type: "dcim.site" +# scope: AMS 1 # slug: vlan-group-2 +# - name: VLAN group 3 +# scope_type: "dcim.location" +# scope: cage 101 +# slug: vlan-group-3 +# - name: VLAN group 4 +# scope_type: "dcim.rack" +# scope: rack-01 +# slug: vlan-group-4 +# - name: VLAN group 5 +# scope_type: "virtualization.cluster" +# scope: cluster1 +# slug: vlan-group-5 +# - name: VLAN group 6 +# scope_type: "virtualization.clustergroup" +# scope: Group 1 +# slug: vlan-group-6 diff --git a/startup_scripts/200_vlan_groups.py b/startup_scripts/200_vlan_groups.py index 7b72b2d..6dda214 100644 --- a/startup_scripts/200_vlan_groups.py +++ b/startup_scripts/200_vlan_groups.py @@ -1,6 +1,6 @@ import sys -from dcim.models import Site +from django.contrib.contenttypes.models import ContentType from ipam.models import VLANGroup from startup_script_utils import load_yaml, pop_custom_fields, set_custom_fields_values @@ -9,7 +9,7 @@ vlan_groups = load_yaml("/opt/netbox/initializers/vlan_groups.yml") if vlan_groups is None: sys.exit() -optional_assocs = {"site": (Site, "name")} +optional_assocs = {"scope": (None, "name")} for params in vlan_groups: custom_field_data = pop_custom_fields(params) @@ -18,9 +18,17 @@ for params in vlan_groups: if assoc in params: model, field = details query = {field: params.pop(assoc)} - - params[assoc] = model.objects.get(**query) - + # Get model from Contenttype + scope_type = params.pop("scope_type", None) + if not scope_type: + print("scope_type is missing from VLAN Group") + continue + app_label, model = str(scope_type).split(".") + ct = ContentType.objects.get(app_label=app_label, model=model) + if not ct: + print(f"ContentType for app_label = '{app_label}' and model = '{model}' not found") + continue + params["scope_id"] = ct.model_class().objects.get(**query).id vlan_group, created = VLANGroup.objects.get_or_create(**params) if created: From 3673196c16fcbebd0b6b46a61887422ff435d9c8 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Wed, 7 Apr 2021 15:19:14 +0200 Subject: [PATCH 15/21] Fields in Custom links have been renamed --- initializers/custom_links.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/initializers/custom_links.yml b/initializers/custom_links.yml index f1b275c..eb733ca 100644 --- a/initializers/custom_links.yml +++ b/initializers/custom_links.yml @@ -10,12 +10,12 @@ ## Examples: # - name: link_to_repo -# text: 'Link to Netbox Docker' -# url: 'https://github.com/netbox-community/netbox-docker' +# link_text: 'Link to Netbox Docker' +# link_url: 'https://github.com/netbox-community/netbox-docker' # new_window: False # content_type: device # - name: link_to_localhost -# text: 'Link to localhost' -# url: 'http://localhost' +# link_text: 'Link to localhost' +# link_url: 'http://localhost' # new_window: True # content_type: device From a572d5f5de110c561f5d4758ec0c7703d4d352af Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Wed, 7 Apr 2021 20:52:56 +0000 Subject: [PATCH 16/21] Update dependency ruamel.yaml to v0.17.4 --- requirements-container.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-container.txt b/requirements-container.txt index f925cb6..a4b538a 100644 --- a/requirements-container.txt +++ b/requirements-container.txt @@ -1,4 +1,4 @@ napalm==3.2.0 -ruamel.yaml==0.17.2 +ruamel.yaml==0.17.4 django-auth-ldap==2.3.0 django-storages[azure,boto3,dropbox,google,libcloud,sftp]==1.11.1 From f637de88f06e6ac5bc754a33899afc30eb24f088 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Tue, 13 Apr 2021 14:31:05 +0200 Subject: [PATCH 17/21] Improved error logging --- initializers/vlan_groups.yml | 12 ++++++------ startup_scripts/200_vlan_groups.py | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/initializers/vlan_groups.yml b/initializers/vlan_groups.yml index a40fd0a..facd34f 100644 --- a/initializers/vlan_groups.yml +++ b/initializers/vlan_groups.yml @@ -1,24 +1,24 @@ # - name: VLAN group 1 -# scope_type: "dcim.region" +# scope_type: dcim.region # scope: Amsterdam # slug: vlan-group-1 # - name: VLAN group 2 -# scope_type: "dcim.site" +# scope_type: dcim.site # scope: AMS 1 # slug: vlan-group-2 # - name: VLAN group 3 -# scope_type: "dcim.location" +# scope_type: dcim.location # scope: cage 101 # slug: vlan-group-3 # - name: VLAN group 4 -# scope_type: "dcim.rack" +# scope_type: dcim.rack # scope: rack-01 # slug: vlan-group-4 # - name: VLAN group 5 -# scope_type: "virtualization.cluster" +# scope_type: virtualization.cluster # scope: cluster1 # slug: vlan-group-5 # - name: VLAN group 6 -# scope_type: "virtualization.clustergroup" +# scope_type: virtualization.clustergroup # scope: Group 1 # slug: vlan-group-6 diff --git a/startup_scripts/200_vlan_groups.py b/startup_scripts/200_vlan_groups.py index 6dda214..eb61023 100644 --- a/startup_scripts/200_vlan_groups.py +++ b/startup_scripts/200_vlan_groups.py @@ -21,12 +21,15 @@ for params in vlan_groups: # Get model from Contenttype scope_type = params.pop("scope_type", None) if not scope_type: - print("scope_type is missing from VLAN Group") + print(f"VLAN Group '{params['name']}': scope_type is missing from VLAN Group") continue app_label, model = str(scope_type).split(".") - ct = ContentType.objects.get(app_label=app_label, model=model) + ct = ContentType.objects.filter(app_label=app_label, model=model).first() if not ct: - print(f"ContentType for app_label = '{app_label}' and model = '{model}' not found") + print( + f"VLAN Group '{params['name']}': ContentType for " + + "app_label = '{app_label}' and model = '{model}' not found" + ) continue params["scope_id"] = ct.model_class().objects.get(**query).id vlan_group, created = VLANGroup.objects.get_or_create(**params) From 752f592e5894b8116cdcfac592bef52add674f8f Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Tue, 13 Apr 2021 15:50:23 +0200 Subject: [PATCH 18/21] Fixed Python f-string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Christian Mäder --- startup_scripts/200_vlan_groups.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/startup_scripts/200_vlan_groups.py b/startup_scripts/200_vlan_groups.py index eb61023..2a4a33d 100644 --- a/startup_scripts/200_vlan_groups.py +++ b/startup_scripts/200_vlan_groups.py @@ -28,7 +28,7 @@ for params in vlan_groups: if not ct: print( f"VLAN Group '{params['name']}': ContentType for " - + "app_label = '{app_label}' and model = '{model}' not found" + + f"app_label = '{app_label}' and model = '{model}' not found" ) continue params["scope_id"] = ct.model_class().objects.get(**query).id From 6e7d5a6f5907136d0e234c05356beb90e042a123 Mon Sep 17 00:00:00 2001 From: Erick Turnquist Date: Thu, 15 Apr 2021 12:18:00 -0400 Subject: [PATCH 19/21] Fix quoting of exec argument in the entrypoint script --- docker/docker-entrypoint.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index c795d6a..c39453d 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -68,6 +68,4 @@ echo "✅ Initialisation is done." # Launch whatever is passed by docker # (i.e. the RUN instruction in the Dockerfile) -# -# shellcheck disable=SC2068 -exec $@ +exec "$@" From d5c92e9a7d6b762dc7f35b2009a14814b9b2df40 Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Fri, 16 Apr 2021 20:27:33 +0200 Subject: [PATCH 20/21] Preparation for 1.2.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 9084fa2..26aaba0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.0 +1.2.0 From a89d2e035c90a542e523e0f967794f9c036f9a9d Mon Sep 17 00:00:00 2001 From: Tobias Genannt Date: Sat, 17 Apr 2021 10:16:40 +0200 Subject: [PATCH 21/21] Don't publish Netbox on random port --- docker-compose.override.yml.example | 5 +++++ docker-compose.yml | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 docker-compose.override.yml.example diff --git a/docker-compose.override.yml.example b/docker-compose.override.yml.example new file mode 100644 index 0000000..f08d6c0 --- /dev/null +++ b/docker-compose.override.yml.example @@ -0,0 +1,5 @@ +version: '3.4' +services: + netbox: + ports: + - 8000:8080 diff --git a/docker-compose.yml b/docker-compose.yml index 4b0fda3..7bec177 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,8 +16,6 @@ services: - ./reports:/etc/netbox/reports:z,ro - ./scripts:/etc/netbox/scripts:z,ro - netbox-media-files:/opt/netbox/netbox/media:z - ports: - - "8080" netbox-worker: <<: *netbox depends_on: