Skip to content

VSCode Breakpoints and Create auto Netbox User for developer and Chapter for Debeloper #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 76 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
26ec863
Create launch.json
LHBL2003 Jul 15, 2024
ca3582b
Create tasks.json
LHBL2003 Jul 15, 2024
2c851da
Debugging with breakpoint in VSCode and automatic creation of Django …
LHBL2003 Jul 15, 2024
8abcc80
Update launch.json
LHBL2003 Jul 15, 2024
2712fc1
COMPOSE_FILE_DEBUG missing for vscode debug
LHBL2003 Jul 15, 2024
66224e0
Message texts improved
LHBL2003 Jul 15, 2024
16e59ad
Message texts improved
LHBL2003 Jul 15, 2024
f430082
Update README.md
LHBL2003 Aug 5, 2024
5046d23
First functional version without documentation.
LHBL2003 Aug 13, 2024
ffba5b4
Support font_weight
LHBL2003 Aug 13, 2024
c717888
Creation of documentation for the new label configuration.
LHBL2003 Aug 15, 2024
c4fb29b
Important information about the web browser setting and the printer.
LHBL2003 Aug 15, 2024
eebcea3
Recommended for Logo added.
LHBL2003 Aug 16, 2024
4374a8e
Forgotten clean-up
LHBL2003 Aug 16, 2024
553fbf4
If no Module Configuration, then use the Global Configuration. This w…
LHBL2003 Aug 16, 2024
090b128
Error correction
LHBL2003 Aug 19, 2024
76351c2
Supports the alignment of text in the text area (horizontal and verti…
LHBL2003 Aug 19, 2024
2c24e79
Correction of beauty error in Github display
LHBL2003 Aug 19, 2024
8034c4d
Support of the Netbox “Dark Mode” by adding the parameter Font-Colors…
LHBL2003 Aug 22, 2024
6eaff88
Recently, “RUN pip install setuptools” has been requested.
LHBL2003 Sep 30, 2024
074e88f
Documentation moved to a separate MarkDown file to improve the view i…
LHBL2003 Sep 30, 2024
ff9a480
Support of the “font-size” parameter for text-only labels.
LHBL2003 Oct 1, 2024
6fa70ab
Example 11 - Cable Label vertical writing.
LHBL2003 Oct 1, 2024
49123e0
Example added. Cable label with code 128
LHBL2003 Oct 25, 2024
9af8a3a
Update README.md
cruse1977 Oct 31, 2024
dc76748
Update setup.py
cruse1977 Oct 31, 2024
faa6eee
Update setup.py
cruse1977 Nov 17, 2024
c8ef163
Update README.md
cruse1977 Nov 17, 2024
69dfb59
Update version.py
cruse1977 Nov 17, 2024
3152999
Update setup.py
cruse1977 Nov 17, 2024
aeb79c7
fixes #75 - replace pkg_resources(deprecated) with importlib
cruse1977 Nov 17, 2024
894d332
Update setup.py
cruse1977 Nov 17, 2024
ae558f9
Update version.py
cruse1977 Nov 17, 2024
f7ebd62
refactor conditional importlib for python < 3.12
cruse1977 Nov 17, 2024
6f2475e
initial
cruse1977 Nov 17, 2024
7d032f4
Update README.md
cruse1977 Nov 17, 2024
bd11b48
update version to v0.0.15
cruse1977 Nov 17, 2024
1ad436d
Merge pull request #88 from netbox-community/feat/v0.0.15
cruse1977 Nov 17, 2024
f2086d9
Updated for NetBox v4.2.x
cruse1977 Jan 11, 2025
76f2f2c
Merge pull request #91 from netbox-community/feat/prepare-for-4-2
cruse1977 Jan 11, 2025
7ca1da5
Use new Netbox version identifier. Fixes netbox-community#93
kj7ice Feb 25, 2025
3cbe35d
Merge pull request #96 from kj7ice/master
cruse1977 Feb 25, 2025
b3a33be
Update README.md
cruse1977 Feb 25, 2025
37563a4
Update version.py
cruse1977 Feb 25, 2025
ddec5aa
Initial 4.3 commit
cruse1977 Apr 28, 2025
e464db6
example 10 and setuptools
LHBL2003 May 2, 2025
74b7125
Merge pull request #103 from cruse1977/master
cruse1977 May 3, 2025
17c8421
Initial fixes for NetBox 4.3
cruse1977 May 3, 2025
7b2d3ff
Minor documentation corrections
cruse1977 May 3, 2025
b606eda
merge resolutions
cruse1977 May 3, 2025
330073d
further merge resolutions
cruse1977 May 3, 2025
f78f70d
further merge resolutions
cruse1977 May 3, 2025
4da00e7
whitespace removal
cruse1977 May 3, 2025
8519c0e
Merge branch 'LHBL-merge' into HTML-Label-Design
cruse1977 May 3, 2025
18f7f83
Merge pull request #105 from cruse1977/HTML-Label-Design
cruse1977 May 3, 2025
d83143d
documentation tweaks
cruse1977 May 3, 2025
25f1140
documentation tweaks
cruse1977 May 3, 2025
c81508d
Add Module support
cruse1977 May 3, 2025
70b0b9f
Update README with full model list
cruse1977 May 3, 2025
e2cbbb7
- The debug vscode always used Netbox V4.1.11 instead of the specifie…
LHBL2003 May 3, 2025
d858a7d
Update Dockerfile
cruse1977 May 4, 2025
9632fac
Update Makefile
cruse1977 May 4, 2025
a143445
Update Dockerfile
cruse1977 May 4, 2025
1a79cc0
chore: Add Tome to CODEOWNERS
cruse1977 May 4, 2025
5fbf828
- Optics: Logo for label templates made transparent to avoid white bo…
LHBL2003 May 5, 2025
95022c1
Documentation: Fixed broken link and added more.
LHBL2003 May 5, 2025
a247640
Example 10 unfortunately had 2 title parameters, so the heading was n…
LHBL2003 May 5, 2025
31b43ce
Improvement of the logo / image description.
LHBL2003 May 6, 2025
43d17ca
Merge pull request #107 from LHBL2003/LHBL-merge
cruse1977 May 13, 2025
8bc1cfa
Tidy documentation
cruse1977 May 25, 2025
128beb2
Merge pull request #109 from netbox-community/LHBL-merge
cruse1977 May 25, 2025
1c5890a
Release - 0.18 - 4.3.x
cruse1977 May 25, 2025
1584427
Merge pull request #110 from netbox-community/4-3-release
cruse1977 May 25, 2025
e17111b
Update README.md
harryajc Jun 4, 2025
7e88bfd
Merge pull request #111 from harryajc/patch-1
cruse1977 Jun 4, 2025
ca62181
Merge branch 'VSCode-Breakpoints-AND-Auto-Netbox-User-AND-Dev-Docu' i…
LHBL2003 Jun 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE

# Part of Setup.py and therefore important for plugin installation.
# README.md
4 changes: 2 additions & 2 deletions .github/workflows/pub-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Set up Python 3.7
- name: Set up Python 3.12
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.12
- name: Install pypa/build
run: >-
python -m
Expand Down
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Is required for debugging Docker-Compose in VSCode.
{
"configurations": [
{

"name": "Docker: Python - Django",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},

"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/source"
}
],

"django": true,

"justMyCode": true,
}
]
}
19 changes: 19 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Is required for debugging Docker-Compose in VSCode.
{
"version": "2.0.0",
"tasks": [
{
"label": "docker-run: debug",
"type": "docker-compose",
"dockerCompose": {
"up": {
"detached": true,
"build": true
},
"files": [
"${workspaceFolder}/develop/docker-compose.yml",
]
}
}
]
}
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @k01ek @cruse1977 @natm
* @k01ek @cruse1977 @cvitan
30 changes: 27 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,46 +1,70 @@
# General: The Makefile is used for plugin development is used to simplify the execution of command sequences.
# Recommended VSCode plugin: Makefile-Tools (extension ID: ms-vscode.makefile-tools)
# To trigger a Makefile command (target), the following line must be written in the terminal window of VSCode, for example:
# make cbuild

# Parameter
PYTHON_VER?=3.12
NETBOX_VER?=v4.0.2
NETBOX_VER?=v4.3.1

NAME=netbox-qrcode

COMPOSE_FILE=./develop/docker-compose.yml
COMPOSE_FILE_DEBUG=./develop/docker-compose-debug.yml
BUILD_NAME=netbox_qrcode
VERFILE=./netbox_qrcode/version.py


# Build Docker with the specific Python and Netbox version
cbuild:
docker-compose -f ${COMPOSE_FILE} \
-p ${BUILD_NAME} build \
--build-arg netbox_ver=${NETBOX_VER} \
--build-arg python_ver=${PYTHON_VER}

debug:
# Start Docker with terminal window output
debug: cbuild
@echo "Starting Netbox .. "
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} up

# Start Docker with terminal window output.
# Brakepoints in e.g. Python files are supported in VSCode. Changes in Python and HTML are applied after saving.
debug-vscode: cbuild
@echo "Starting Netbox debug for VSCode.. "
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} -f ${COMPOSE_FILE_DEBUG} up
# --build

# Start Docker without connecting to the terminal window. (Runs independently of the terminal window.).
start:
@echo "Starting Netbox in detached mode.. "
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} up -d

# Stop Docker Container
stop:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} down

# Stop Docker and remove containers
destroy:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} down
docker volume rm -f ${BUILD_NAME}_pgdata_netbox_qrcode

# Calls the Netbox shell. Exit with exit()
# NetBox includes a Python shell within which objects can be directly queried, created, modified, and deleted.
nbshell:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} run netbox python manage.py nbshell

# Calls the Python shell. Exit with exit()
shell:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} run netbox python manage.py shell

# To create the Django Superuser to be able to log on to Netbox Web.
adduser:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} run netbox python manage.py createsuperuser

# Django collectstatic
collectstatic:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} run netbox python manage.py collectstatic

# Migrate the Netbox system depending on the Django model
migrations:
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} up -d postgres
docker-compose -f ${COMPOSE_FILE} -p ${BUILD_NAME} \
Expand Down
131 changes: 62 additions & 69 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Netbox QR Code Plugin

[Netbox](https://github.com/netbox-community/netbox) plugin for generate QR codes for objects: Rack, Device, Cable.
[Netbox](https://github.com/netbox-community/netbox) plugin for generate QR codes for objects: Device, Module, Cable, Powerfeed, Powerpanel, Location

This plugin depends on [qrcode](https://github.com/lincolnloop/python-qrcode) and [Pillow](https://github.com/python-pillow/Pillow) python library

Expand All @@ -10,10 +10,14 @@ This plugin depends on [qrcode](https://github.com/lincolnloop/python-qrcode) an

## Compatibility

| Plugin Version | NetBox Version | Tested on |
| ------------- |:-------------| :-----:|
| 0.0.11 | >= 3.7.0 | 3.7.x |
| 0.0.13 | >= 4.0.2 | v4.0.2 |
| Plugin Version | NetBox Version | Tested on |
| ------------- |:-------------| :-----------:|
| 0.0.11 | 3.7.x | 3.7.x |
| 0.0.14 | 4.0.x | 4.0.11 |
| 0.0.15 | 4.1.x | 4.1.6 |
| 0.0.17 | 4.2.x | 4.2.4 |
| 0.0.18 | 4.3.x | 4.3.1 |


## Installation

Expand All @@ -36,80 +40,72 @@ Restart NetBox and add `netbox-qrcode` to your local_requirements.txt

## Configuration

The following options are available:
### Label Design

* `with_text`: Boolean (default True). Text label will be added to QR code image if enabled.
* `text_template`: [Jinja2](https://jinja.palletsprojects.com/) template with {{ obj }} as context for device, rack, etc., using it ignores `text_fields` and `custom_text`.
Extensive label customisation is possible, it's also possible to include different labels for each object type, for example 2 labels for the Device view.

Example to output name and site in two lines with caption (See also screenshots below):
```
'text_template': 'Name: {{ obj.name }}\nSite: {{ obj.site }}',
```
* `text_fields`: List of String (default ['name']). Text fields of an object that will be added as text label to QR image. It's possible to use custom field values.
* `font`: String (default TahomaBold) Font name for text label ( Some font include in package, see fonts dir).
* `text_location`: Where to render the text, relative to the QR code. Valid values are `"right"` (default), `"left"`", `"up"`, and `"down"`.
* `custom_text`: String or None (default None) additional text label to QR code image (will be added after text_fields).
* `qr_version`: Integer (default 1) parameter is an integer from 1 to 40 that controls the size of
the QR Code (the smallest, version 1, is a 21x21 matrix).
* `qr_error_correction`: Integer (default 0), controls the error correction used for the
QR Code. The following values are available:
For advice on configuration please see the two links below:

1 - About 7% or less errors can be corrected.
0 - About 15% or less errors can be corrected.
2 - About 30% or less errors can be corrected.
3 - About 25% or less errors can be corrected.
- [General Configuration >>](docs/README_Subpages/README_Configuration.md)
- [Configuration Examples >>](docs/README_Subpages/README_Configuration_ExampleLabelConf.md)

* `qr_box_size`: Integer (default 6), controls how many pixels each "box" of the QR code
is.
* `qr_border`: Integer (default 4), controls how many boxes thick the border should be
(the default is 4, which is the minimum according to the specs).
![Cable QR Code](/docs/img/Configuration_Label_Example_10.png)

### Per object options

Per object options override default options. Per object options dictionary can contains any of default options inside.
### Printing

#### Setting the label printer

If the print does not look like the preview in the Netbox, first try to get a perfect print using Word. As many printer settings also have an influence on the print result. Borderless printing is possible if the printer (e.g. thermal transfer printer) supports this.

![ShowImage](/docs/img/Configuration_Printer_WordPreview.png)


Here is an example of what needs to be considered to print borderless from a Word document. [Go to: Example Zebra ZM400 300dpi label printer and a label 56x32mm. >>](/docs/img/Configuration_Printer_ZM400.png)


#### Setting Browser Print Settings

When you press the “Print” button, there are some print properties that are added by the browser. However, these interfere with the print result. They should therefore be deactivated.

##### Firefox:

| Parameter | Value |
| --------------------------------------------- | --------------------------- |
| Orientation | Portrait |
| Paper size | User defined |
| Margins | none |
| Scale | Fit to page width or 100% |
| Options --> Print headers and footers | disable |
| Options --> Print backgrounds | disable |

##### Chrome:
Chrome can alter settings between printing and the print preview, therefore the below settings are recomended

| Parameter | Value |
| --------------------------------------------- | --------------------------- |
| Layout | Portrait |
| Paper size | empty !!! |
| Pages per sheet | 1 |
| Margins | none |
| Scale | Default or 100% |
| Options --> PBackground grafics | disable |

![Image](/docs/img/Configuration_Browser_Print_Settings.png)


* `device`: Dict or None (default {'text_fields': ['name', 'serial']}), set None to disble QR code
* `rack`: Dict or None (default {'text_fields': ['name']}) , set None to disble QR code
* `cable`: Dict or None ( defaul {'text_fields': ['_termination_a_device', 'termination_a', '_termination_b_device', 'termination_b',]}), set None to disble QR code

Configuration example:
```
PLUGINS_CONFIG = {
'netbox_qrcode': {
'with_text': True,
'text_fields': ['name', 'serial'],
'font': 'ArialMT',
'font_size': 12, # If the value is 0 or the line does not exist, then the text is automatically adjusted
'custom_text': 'Property of SomeCompany\ntel.8.800333554-CALL',
'text_location': 'up',
'qr_version': 1,
'qr_error_correction': 0,
'qr_box_size': 4,
'qr_border': 4,
# per object options
'cable': None, # disable QR code for Cable object
'rack': {
'text_fields': [
'site',
'name',
'facility_id',
'tenant',
'cf.cf_name'
]
},
'device': {
'qr_box_size': 6,
'custom_text': None,
}
}
}
```

## Contributing
Developing tools for this project based on [ntc-netbox-plugin-onboarding](https://github.com/networktocode/ntc-netbox-plugin-onboarding) repo.

Issues and pull requests are welcomed.

## Development

You would like to help with the development of the plugin. Here you can find further information such as how to set up debugging in vscode and much more.

- [Go to Development >>](docs/README_Subpages/README_Development.md)

## Screenshots

Device QR code with text label
Expand All @@ -120,6 +116,3 @@ Rack QR code

Cable QR code
![Cable QR Code](docs/img/qrcode_cable.png)

Device QR code via Jinja2 "text_template" Parameter (Multiline and labeled)
![Cable QR Code](docs/img/qrcode_text_template.png)
6 changes: 4 additions & 2 deletions develop/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
ARG python_ver=3.12
FROM python:${python_ver}

ARG netbox_ver=master
ARG netbox_ver=main
ENV PYTHONUNBUFFERED 1

RUN mkdir -p /opt

RUN pip install --upgrade pip
RUN pip install setuptools


# -------------------------------------------------------------------------------------
# Install NetBox
Expand All @@ -23,6 +25,6 @@ WORKDIR /source
COPY . /source

#RUN pip install -r requirements.txt
RUN python setup.py develop
RUN python -m pip install -e .

WORKDIR /opt/netbox/netbox/
Binary file added develop/Netbox_Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading