9 Commits
Author SHA1 Message Date
wkoot 72646a6287 Update PluginMenuItem permissions and remove bulk import/edit (#41)
Closes #37
2024-07-09 23:00:58 +02:00
wkoot 86215f43a6 Prepare for upgrade to NetBox v4.0.6 (#40)
Closes #38
2024-07-09 22:15:58 +02:00
wkoot 230b3b5115 Add new fields to models and upgrade to NetBox v3.7.2 (#36)
Closes #10, #26, #35
2024-02-13 12:11:49 +01:00
wkoot 1411e3a5cb Update MANIFEST.in, so all files are included (#34)
Closes #32
2023-12-08 10:14:23 +01:00
wkoot d082af4a9b Add Installation foreign key to VM Cluster (#29)
Closes #17
2023-10-04 18:23:08 +02:00
wkoot 2501e41b7c Add 'stored_location_url' to SoftwareLicense (#28)
Closes #27
2023-09-22 02:42:02 +02:00
wkootandManuel Hartung aa41f8a402 Assorted fixes (#25)
* Updated imports for Netbox 3.6.1

Closes #21 and #23

* Changed Fieldtypes of Start and Expiration Date

Closes #22

* Bump to NetBox v3.6.1

* Add pyproject.toml and python workflow

---------

Co-authored-by: Manuel Hartung <manuel.hartung@atos.net>
2023-09-15 09:41:36 +02:00
wkoot 6c512e0e9b Add SoftwareLicense (#20) 2023-06-30 15:11:28 +02:00
wkoot 5b96496b46 Replace NetBoxModelCSVForm with NetBoxModelImportForm (#19)
Closes #18
2023-06-06 21:16:13 +02:00
52 changed files with 1572 additions and 877 deletions
+3 -3
View File
@@ -11,14 +11,14 @@ jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Build the Docker image - name: Build the Docker image
run: docker compose build --no-cache run: docker compose build --no-cache
- name: Verify the Docker image - name: Verify the Docker image
# clearcache is provided by Django extras, which is not loaded if netbox-slm cannot be loaded # smoke test by checking if the migrations for app netbox_slm can be displayed
run: docker compose run netbox sh -c "/opt/netbox/venv/bin/python manage.py clearcache" run: docker compose run netbox sh -c "/opt/netbox/venv/bin/python manage.py showmigrations netbox_slm"
- name: Run Django tests with coverage for netbox_slm - name: Run Django tests with coverage for netbox_slm
run: | run: |
+28
View File
@@ -0,0 +1,28 @@
name: Python
on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install tools
run: pip install .[tools]
- name: Run ruff lint
run: ruff check netbox_slm
- name: Run ruff format
run: ruff format netbox_slm
+2
View File
@@ -9,3 +9,5 @@
ci/docker-compose.override.yml ci/docker-compose.override.yml
ci/reports ci/reports
out/production out/production
*.iml
build/
+133
View File
@@ -0,0 +1,133 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the overall
community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or advances of
any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email address,
without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement by
[opening a new issue in this repository's issue tracker][open issue].
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series of
actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or permanent
ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within the
community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.1, available at
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
Community Impact Guidelines were inspired by
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
For answers to common questions about this code of conduct, see the FAQ at
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
[https://www.contributor-covenant.org/translations][translations].
[homepage]: https://www.contributor-covenant.org
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
[Mozilla CoC]: https://github.com/mozilla/diversity
[FAQ]: https://www.contributor-covenant.org/faq
[translations]: https://www.contributor-covenant.org/translations
[open issue]: https://github.com/ICTU/netbox_slm/issues/new
+34
View File
@@ -0,0 +1,34 @@
# NetBox SLM contributing guidelines
## What do I need to know to help?
If you are looking to help to with a code contribution our project uses, you can find inspiration in the [issue list](https://github.com/ICTU/netbox_slm/issues/).
Additionally, review the [README](./README.md) document and [NetBox Plugin Development](https://docs.netbox.dev/en/stable/plugins/development/) docs.
## How do I make a contribution?
Never made an open source contribution before? Wondering how contributions work in the in our project? Here's a quick rundown!
1. Find an issue that you are interested in addressing or a feature that you would like to add.
2. Fork the repository associated with the issue to your local GitHub organization. This means that you will have a copy of the repository under **your-GitHub-username/repository-name**.
3. Clone the repository to your local machine using `git clone https://github.com/github-username/repository-name.git`.
4. Create a new branch for your fix using `git checkout -b branch-name-here`.
5. Make the appropriate changes for the issue you are trying to address or the feature that you want to add.
6. Use git `add insert-paths-of-changed-files-here` to add the file contents of the changed files to the "snapshot" git uses to manage the state of the project, also known as the index.
7. Use `git commit -m "Insert a short message of the changes made here"` to store the contents of the index with a descriptive message.
8. Push the changes to the remote repository using `git push origin branch-name-here`.
9. Submit a pull request to the upstream repository.
10. Title the pull request with a short description of the changes made and the issue or bug number associated with your change. For example, you can title an issue like so "Added more log outputting to resolve #4352".
11. In the description of the pull request, explain the changes that you made, any issues you think exist with the pull request you made, and any questions you have for the maintainer. It's OK if your pull request is not perfect (no pull request is), the reviewer will be able to help you fix any problems and improve it!
12. Wait for the pull request to be reviewed by a maintainer.
13. Make changes to the pull request if the reviewing maintainer recommends them.
14. Celebrate your success after your pull request is merged!
## Where can I go for help?
If you need help, you can ask questions by [opening a new issue in this repository's issue tracker](https://github.com/ICTU/netbox_slm/issues/new).
## What does the Code of Conduct mean for me?
Our [Code of Conduct](./CODE_OF_CONDUCT.md) means that you are responsible for treating everyone on the project with respect and courtesy regardless of their identity.
If you are the victim of any inappropriate behavior or comments as described in our Code of Conduct, we are here for you and will do the best to ensure that the abuser is reprimanded appropriately, per our code.
+7 -4
View File
@@ -1,4 +1,7 @@
include ../LICENSE include LICENSE
include ../README.md include README.md
include ../SECURITY.md include SECURITY.md
recursive-include netbox_slm/templates * graft netbox_slm
prune netbox_slm/tests
global-exclude *.py[cod]
global-exclude __pycache__
-12
View File
@@ -1,12 +0,0 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
[dev-packages]
twine = "3.7.1"
[requires]
python_version = "3.9"
Generated
-192
View File
@@ -1,192 +0,0 @@
{
"_meta": {
"hash": {
"sha256": "f3cebe84c169ba6773cfcfae65b47e5076fa331e445f47a6ec4d13306942deb4"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.9"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {},
"develop": {
"bleach": {
"hashes": [
"sha256:0900d8b37eba61a802ee40ac0061f8c2b5dee29c1927dd1d233e075ebf5a71da",
"sha256:4d2651ab93271d1129ac9cbc679f524565cc8a1b791909c4a51eac4446a15994"
],
"markers": "python_version >= '3.6'",
"version": "==4.1.0"
},
"certifi": {
"hashes": [
"sha256:78884e7c1d4b00ce3cea67b44566851c4343c120abd683433ce934a68ea58872",
"sha256:d62a0163eb4c2344ac042ab2bdf75399a71a2d8c7d47eac2e2ee91b9d6339569"
],
"version": "==2021.10.8"
},
"charset-normalizer": {
"hashes": [
"sha256:876d180e9d7432c5d1dfd4c5d26b72f099d503e8fcc0feb7532c9289be60fcbd",
"sha256:cb957888737fc0bbcd78e3df769addb41fd1ff8cf950dc9e7ad7793f1bf44455"
],
"markers": "python_version >= '3'",
"version": "==2.0.10"
},
"colorama": {
"hashes": [
"sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b",
"sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==0.4.4"
},
"docutils": {
"hashes": [
"sha256:23010f129180089fbcd3bc08cfefccb3b890b0050e1ca00c867036e9d161b98c",
"sha256:679987caf361a7539d76e584cbeddc311e3aee937877c87346f31debc63e9d06"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
"version": "==0.18.1"
},
"idna": {
"hashes": [
"sha256:84d9dd047ffa80596e0f246e2eab0b391788b0503584e8945f2368256d2735ff",
"sha256:9d643ff0a55b762d5cdb124b8eaa99c66322e2157b69160bc32796e824360e6d"
],
"markers": "python_version >= '3'",
"version": "==3.3"
},
"importlib-metadata": {
"hashes": [
"sha256:92a8b58ce734b2a4494878e0ecf7d79ccd7a128b5fc6014c401e0b61f006f0f6",
"sha256:b7cf7d3fef75f1e4c80a96ca660efbd51473d7e8f39b5ab9210febc7809012a4"
],
"markers": "python_version >= '3.7'",
"version": "==4.10.0"
},
"keyring": {
"hashes": [
"sha256:9012508e141a80bd1c0b6778d5c610dd9f8c464d75ac6774248500503f972fb9",
"sha256:b0d28928ac3ec8e42ef4cc227822647a19f1d544f21f96457965dc01cf555261"
],
"markers": "python_version >= '3.7'",
"version": "==23.5.0"
},
"packaging": {
"hashes": [
"sha256:dd47c42927d89ab911e606518907cc2d3a1f38bbd026385970643f9c5b8ecfeb",
"sha256:ef103e05f519cdc783ae24ea4e2e0f508a9c99b2d4969652eed6a2e1ea5bd522"
],
"markers": "python_version >= '3.6'",
"version": "==21.3"
},
"pkginfo": {
"hashes": [
"sha256:542e0d0b6750e2e21c20179803e40ab50598d8066d51097a0e382cba9eb02bff",
"sha256:c24c487c6a7f72c66e816ab1796b96ac6c3d14d49338293d2141664330b55ffc"
],
"version": "==1.8.2"
},
"pygments": {
"hashes": [
"sha256:59b895e326f0fb0d733fd28c6839bd18ad0687ba20efc26d4277fd1d30b971f4",
"sha256:9135c1af61eec0f650cd1ea1ed8ce298e54d56bcd8cc2ef46edd7702c171337c"
],
"markers": "python_version >= '3.5'",
"version": "==2.11.1"
},
"pyparsing": {
"hashes": [
"sha256:04ff808a5b90911829c55c4e26f75fa5ca8a2f5f36aa3a51f68e27033341d3e4",
"sha256:d9bdec0013ef1eb5a84ab39a3b3868911598afa494f5faa038647101504e2b81"
],
"markers": "python_version >= '3.6'",
"version": "==3.0.6"
},
"readme-renderer": {
"hashes": [
"sha256:a50a0f2123a4c1145ac6f420e1a348aafefcc9211c846e3d51df05fe3d865b7d",
"sha256:b512beafa6798260c7d5af3e1b1f097e58bfcd9a575da7c4ddd5e037490a5b85"
],
"markers": "python_version >= '3.6'",
"version": "==32.0"
},
"requests": {
"hashes": [
"sha256:8e5643905bf20a308e25e4c1dd379117c09000bf8a82ebccc462cfb1b34a16b5",
"sha256:f71a09d7feba4a6b64ffd8e9d9bc60f9bf7d7e19fd0e04362acb1cfc2e3d98df"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'",
"version": "==2.27.0"
},
"requests-toolbelt": {
"hashes": [
"sha256:380606e1d10dc85c3bd47bf5a6095f815ec007be7a8b69c878507068df059e6f",
"sha256:968089d4584ad4ad7c171454f0a5c6dac23971e9472521ea3b6d49d610aa6fc0"
],
"version": "==0.9.1"
},
"rfc3986": {
"hashes": [
"sha256:270aaf10d87d0d4e095063c65bf3ddbc6ee3d0b226328ce21e036f946e421835",
"sha256:a86d6e1f5b1dc238b218b012df0aa79409667bb209e58da56d0b94704e712a97"
],
"version": "==1.5.0"
},
"six": {
"hashes": [
"sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
"sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2'",
"version": "==1.16.0"
},
"tqdm": {
"hashes": [
"sha256:8dd278a422499cd6b727e6ae4061c40b48fce8b76d1ccbf5d34fca9b7f925b0c",
"sha256:d359de7217506c9851b7869f3708d8ee53ed70a1b8edbba4dbcb47442592920d"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
"version": "==4.62.3"
},
"twine": {
"hashes": [
"sha256:28460a3db6b4532bde6a5db6755cf2dce6c5020bada8a641bb2c5c7a9b1f35b8",
"sha256:8c120845fc05270f9ee3e9d7ebbed29ea840e41f48cd059e04733f7e1d401345"
],
"index": "pypi",
"version": "==3.7.1"
},
"urllib3": {
"hashes": [
"sha256:4987c65554f7a2dbf30c18fd48778ef124af6fab771a377103da0585e2336ece",
"sha256:c4fdf4019605b6e5423637e01bc9fe4daef873709a7973e195ceba0a62bbc844"
],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"version": "==1.26.7"
},
"webencodings": {
"hashes": [
"sha256:a0af1213f3c2226497a97e2b3aa01a7e4bee4f403f95be16fc9acd2947514a78",
"sha256:b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"
],
"version": "==0.5.1"
},
"zipp": {
"hashes": [
"sha256:9f50f446828eb9d45b267433fd3e9da8d801f614129124863f9c51ebceafb87d",
"sha256:b47250dd24f92b7dd6a0a8fc5244da14608f3ca90a5efcd37a3b1642fac9a375"
],
"markers": "python_version >= '3.7'",
"version": "==3.7.0"
}
}
}
+20 -18
View File
@@ -1,6 +1,6 @@
<h1 align="center">NetBox SLM</h1> # NetBox SLM
<p align="center"><i>Netbox SLM is a plugin for lifecycle management of software components, including versions and installations.</i></p> <p align="center"><i>NetBox SLM is a plugin for lifecycle management of software components, including versions and installations.</i></p>
<div align="center"> <div align="center">
<a href="https://pypi.org/project/netbox_slm/"><img src="https://img.shields.io/pypi/v/netbox_slm" alt="PyPi"/></a> <a href="https://pypi.org/project/netbox_slm/"><img src="https://img.shields.io/pypi/v/netbox_slm" alt="PyPi"/></a>
@@ -15,20 +15,20 @@
## Known Issues ## Known Issues
- WARNING: This plugin is only tested with a single Netbox version at this time. - WARNING: This plugin is only tested with a single NetBox version at this time.
- CSV/Bulk imports for SoftwareProduct, Version and Installation are currently broken (WIP) - CSV/Bulk imports for SoftwareProduct, Version and Installation are currently broken (WIP)
## Installation Guide ## Installation Guide
When using the Docker version of Netbox, first follow the netbox-docker [quickstart](https://github.com/netbox-community/netbox-docker#quickstart) instructions to clone the netbox-docker repo and set up the ``docker-compose.override.yml``. When using the Docker version of NetBox, first follow the netbox-docker [quickstart](https://github.com/netbox-community/netbox-docker#quickstart) instructions to clone the netbox-docker repo and set up the ``docker-compose.override.yml``.
Next, follow these instructions (based on the Netbox docker variant Next, follow these instructions (based on the NetBox docker variant
[instructions](https://github.com/netbox-community/netbox-docker/wiki/Configuration#custom-configuration-files)) [instructions](https://github.com/netbox-community/netbox-docker/wiki/Configuration#custom-configuration-files))
to install the Netbox SLM plugin: to install the NetBox SLM plugin:
1. Add ``netbox_slm`` to the ``PLUGINS`` list in 1. Add ``netbox_slm`` to the ``PLUGINS`` list in
``configuration/extra.py``. ``configuration/plugins.py``.
2. Create a ``plugin_requirements.txt`` with ``netbox-slm==1.2`` as 2. Create a ``plugin_requirements.txt`` with ``netbox-slm`` as
contents. contents.
3. Create a ``Dockerfile-SLM`` with contents: 3. Create a ``Dockerfile-SLM`` with contents:
@@ -59,26 +59,23 @@ to install the Netbox SLM plugin:
Now, build the image: ``docker compose build --no-cache`` Now, build the image: ``docker compose build --no-cache``
And finally, run Netbox with the SLM plugin: ``docker compose up`` And finally, run NetBox with the SLM plugin: ``docker compose up``
## Releasing Guide ## Releasing Guide
To draft a release; To draft a release;
update the setup.py file to reflect the new version, then from the *src* update the `netbox_slm/__init__.py` file to reflect the new version, then from the *src*
directory run directory run
``` ```
# make sure to update the version in netbox_slm/__init__.py $ python -m build
$ python setup.py sdist
$ twine upload dist/* $ twine upload dist/*
``` ```
On Github.com create a similar tag and version. These steps could be On Github.com create a similar tag and version. These steps could be
automated with a github workflow. automated with a github workflow.
n.b. Currently the plugin is configured to use a personal pypi account,
this should be changed.
## Developer Guide (local installation) ## Developer Guide (local installation)
@@ -87,8 +84,8 @@ netbox_slm plugin in developer mode*
### Setup ### Setup
The goal below is to run all Netbox components in Docker and run a local The goal below is to run all NetBox components in Docker and run a local
Netbox Django copy with auto-reload to develop the plugin pointing to NetBox Django copy with auto-reload to develop the plugin pointing to
the Dockerized postgres and redis instances, basically ignoring the the Dockerized postgres and redis instances, basically ignoring the
netbox docker runtime server. netbox docker runtime server.
@@ -119,7 +116,7 @@ netbox docker runtime server.
] ]
``` ```
The Netbox installation above will be used to run Django management The NetBox installation above will be used to run Django management
commands like runserver, makemigrations and migrate, which will be commands like runserver, makemigrations and migrate, which will be
explained in the next steps below; explained in the next steps below;
@@ -131,7 +128,7 @@ explained in the next steps below;
$ ./start-netbox.sh $ ./start-netbox.sh
``` ```
This will start Netbox locally (requires Docker) and forward the redis This will start NetBox locally (requires Docker) and forward the redis
and postgres ports to the localhost (make sure theres no processes and postgres ports to the localhost (make sure theres no processes
using these ports or change the dockerfiles accordingly) using these ports or change the dockerfiles accordingly)
@@ -223,3 +220,8 @@ Now you can run commands from the netbox repository like this;
Visit http://127.0.0.1:8001 in the browser to see the auto reloading Visit http://127.0.0.1:8001 in the browser to see the auto reloading
version of the netbox UI. Port 8000 is taken by the docker ran variant. version of the netbox UI. Port 8000 is taken by the docker ran variant.
## Get in touch
Point of contact for this repository is [Mart Visser](https://github.com/MartVisser), who can be reached by [opening a new issue in this repository's issue tracker](https://github.com/ICTU/netbox_slm/issues/new).
+7 -4
View File
@@ -1,13 +1,16 @@
# Security Policy # NetBox SLM Security Policy
## Current status ## Current status
Netbox SLM is a plugin for Netbox with mostly default configuration. We advise to monitor Netbox security findings and update accordingly. NetBox SLM is a plugin for [NetBox](https://github.com/netbox-community/netbox/) with mostly default configuration.
In order to stay up to date, monitor NetBox security findings and update accordingly.
## Supported Versions ## Supported Versions
Only the latest version of Netbox SLM is currently being supported with security updates. We aim to keep the plugin compatible with the latest Netbox version, but have no incentive to patch older tags at this point. Only the latest version of NetBox SLM is currently being supported with security updates.
The intention is to keep the plugin compatible with the most recent NetBox version(s), there is no incentive to patch older tags.
## Reporting a Vulnerability ## Reporting a Vulnerability
Please report security vulnerabilities by opening a ticket. The aim is to get back to you within 24 hours with a confirmation of the issue and a brief action plan or a request for more information. You can privately [report a vulnerability issue in this repository's issue tracker](https://github.com/ICTU/netbox_slm/security/advisories/new).
The aim is to get back to you within 24 hours, with a confirmation of the issue and a brief action plan or a request for more information.
+5 -4
View File
@@ -1,4 +1,4 @@
ARG PYTHON_VERSION=3.10 ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION}-alpine AS compile-image FROM python:${PYTHON_VERSION}-alpine AS compile-image
WORKDIR /build WORKDIR /build
@@ -7,10 +7,11 @@ ENV PATH="/opt/netbox/venv/bin:$PATH"
COPY ../ /build COPY ../ /build
RUN python setup.py sdist RUN pip install -U .[build]
RUN python -m build
RUN pip install --no-index /build RUN pip install --no-index /build
FROM netboxcommunity/netbox:v3.4.7 FROM netboxcommunity/netbox:v4.0.6
ARG PYTHON_VERSION=3.10 ARG PYTHON_VERSION=3.11
COPY --from=compile-image /opt/netbox/venv/lib/python${PYTHON_VERSION}/site-packages/netbox_slm /opt/netbox/venv/lib/python${PYTHON_VERSION}/site-packages/netbox_slm COPY --from=compile-image /opt/netbox/venv/lib/python${PYTHON_VERSION}/site-packages/netbox_slm /opt/netbox/venv/lib/python${PYTHON_VERSION}/site-packages/netbox_slm
+1 -1
View File
@@ -1,4 +1,4 @@
FROM netboxcommunity/netbox:v3.4.7 FROM netboxcommunity/netbox:v4.0.6
RUN mkdir /ci && chmod go+w /ci RUN mkdir /ci && chmod go+w /ci
COPY ../ci/requirements_ci.txt /ci/ COPY ../ci/requirements_ci.txt /ci/
+1
View File
@@ -129,6 +129,7 @@ CSRF_TRUSTED_ORIGINS = list(filter(None, environ.get('CSRF_TRUSTED_ORIGINS', '')
# 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 = environ.get('DEBUG', 'False').lower() == 'true' DEBUG = environ.get('DEBUG', 'False').lower() == 'true'
DEVELOPER = environ.get('DEVELOPER', 'False').lower() == 'true'
# Email settings # Email settings
EMAIL = { EMAIL = {
+1 -1
View File
@@ -1,6 +1,6 @@
PLUGINS = ['netbox_slm'] PLUGINS = ['netbox_slm']
DEBUG = True DEBUG = True
SECRET_KEY = 'dummy' SECRET_KEY = 'dummydummydummydummydummydummydummydummydummydummy'
DEVELOPER = True DEVELOPER = True
PLUGINS_CONFIG = { PLUGINS_CONFIG = {
'netbox_slm': dict( 'netbox_slm': dict(
+1 -1
View File
@@ -1,4 +1,4 @@
version: '3.7' ---
services: services:
netbox: netbox:
ports: ports:
+2 -2
View File
@@ -1,7 +1,7 @@
version: '3.7' ---
services: services:
netbox: &netbox netbox: &netbox
image: netboxcommunity/netbox:${VERSION-v3.3-2.2.0} image: netboxcommunity/netbox:${VERSION-v4.0.6}
depends_on: depends_on:
- postgres - postgres
- redis - redis
+1 -1
View File
@@ -1,2 +1,2 @@
coverage==7.2.2 coverage==7.5.4
unittest-xml-reporting==3.2.0 unittest-xml-reporting==3.2.0
+11 -11
View File
@@ -1,18 +1,18 @@
from extras.plugins import PluginConfig from netbox.plugins import PluginConfig
__version__ = "1.7.0"
class SLMConfig(PluginConfig): class SLMConfig(PluginConfig):
name = 'netbox_slm' name = "netbox_slm"
verbose_name = 'Software Lifecycle Management' verbose_name = "Software Lifecycle Management"
description = 'Software Lifecycle Management Netbox Plugin.' description = "Software Lifecycle Management Netbox Plugin."
version = '1.3' version = __version__
author = 'ICTU' author = "ICTU"
author_email = 'open-source-projects@ictu.nl' author_email = "open-source-projects@ictu.nl"
base_url = 'slm' base_url = "slm"
required_settings = [] required_settings = []
default_settings = { default_settings = {"version_info": False}
'version_info': False
}
config = SLMConfig config = SLMConfig
+7
View File
@@ -0,0 +1,7 @@
from django.apps import apps
from django.conf import settings
from django.contrib import admin
if settings.DEBUG:
for model in apps.get_app_config("netbox_slm").get_models():
admin.site.register(model)
+97 -27
View File
@@ -1,41 +1,68 @@
from rest_framework import serializers from rest_framework import serializers
from netbox.api.serializers import NetBoxModelSerializer from netbox.api.serializers import NetBoxModelSerializer
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
class SoftwareLicenseSerializer(NetBoxModelSerializer):
display = serializers.SerializerMethodField()
url = serializers.HyperlinkedIdentityField(view_name="plugins-api:netbox_slm-api:softwarelicense-detail")
class Meta:
model = SoftwareLicense
fields = (
"id",
"display",
"url",
"name",
"description",
"type",
"stored_location",
"stored_location_url",
"start_date",
"expiration_date",
"support",
"license_amount",
"software_product",
"version",
"installation",
"tags",
"comments",
"custom_field_data",
"created",
"last_updated",
)
brief_fields = ("id", "display", "url", "name", "description")
def get_display(self, obj):
return f"{obj}"
class SoftwareProductSerializer(NetBoxModelSerializer): class SoftwareProductSerializer(NetBoxModelSerializer):
display = serializers.SerializerMethodField() display = serializers.SerializerMethodField()
url = serializers.HyperlinkedIdentityField( url = serializers.HyperlinkedIdentityField(view_name="plugins-api:netbox_slm-api:softwareproduct-detail")
view_name="plugins-api:netbox_slm-api:softwareproduct-detail"
)
class Meta: class Meta:
model = SoftwareProduct model = SoftwareProduct
fields = [ fields = (
'id', 'display', 'url', 'name', 'tags', 'custom_field_data', 'created', 'last_updated', "id",
] "display",
"url",
"name",
"manufacturer",
"description",
"tags",
"comments",
"custom_field_data",
"created",
"last_updated",
)
brief_fields = ("id", "display", "url", "name", "description")
def get_display(self, obj): def get_display(self, obj):
return f"{obj.manufacturer} - {obj}" return f"{obj.manufacturer} - {obj}"
class SoftwareProductVersionSerializer(NetBoxModelSerializer):
display = serializers.SerializerMethodField()
url = serializers.HyperlinkedIdentityField(
view_name="plugins-api:netbox_slm-api:softwareproductversion-detail"
)
class Meta:
model = SoftwareProductVersion
fields = [
'id', 'display', 'url', 'name', 'software_product', 'tags', 'custom_field_data', 'created', 'last_updated',
]
def get_display(self, obj):
return f"{obj}"
class SoftwareProductInstallationSerializer(NetBoxModelSerializer): class SoftwareProductInstallationSerializer(NetBoxModelSerializer):
display = serializers.SerializerMethodField() display = serializers.SerializerMethodField()
url = serializers.HyperlinkedIdentityField( url = serializers.HyperlinkedIdentityField(
@@ -44,10 +71,53 @@ class SoftwareProductInstallationSerializer(NetBoxModelSerializer):
class Meta: class Meta:
model = SoftwareProductInstallation model = SoftwareProductInstallation
fields = [ fields = (
'id', 'display', 'url', 'device', 'virtualmachine', 'software_product', 'version', 'tags', "id",
'custom_field_data', 'created', 'last_updated', "display",
] "url",
"device",
"virtualmachine",
"cluster",
"software_product",
"version",
"tags",
"comments",
"custom_field_data",
"created",
"last_updated",
)
brief_fields = ("id", "display", "url", "name")
def get_display(self, obj):
return f"{obj}"
class SoftwareProductVersionSerializer(NetBoxModelSerializer):
display = serializers.SerializerMethodField()
url = serializers.HyperlinkedIdentityField(view_name="plugins-api:netbox_slm-api:softwareproductversion-detail")
class Meta:
model = SoftwareProductVersion
fields = (
"id",
"display",
"url",
"name",
"release_date",
"documentation_url",
"end_of_support",
"filename",
"file_checksum",
"file_link",
"release_type",
"software_product",
"tags",
"comments",
"custom_field_data",
"created",
"last_updated",
)
brief_fields = ("id", "display", "url", "name")
def get_display(self, obj): def get_display(self, obj):
return f"{obj}" return f"{obj}"
+2
View File
@@ -4,6 +4,7 @@ from netbox_slm.api.views import (
SoftwareProductViewSet, SoftwareProductViewSet,
SoftwareProductVersionViewSet, SoftwareProductVersionViewSet,
SoftwareProductInstallationViewSet, SoftwareProductInstallationViewSet,
SoftwareLicenseViewSet,
) )
router = NetBoxRouter() router = NetBoxRouter()
@@ -12,4 +13,5 @@ router.APIRootView = NetboxSLMRootView
router.register("softwareproducts", SoftwareProductViewSet) router.register("softwareproducts", SoftwareProductViewSet)
router.register("softwareproductversions", SoftwareProductVersionViewSet) router.register("softwareproductversions", SoftwareProductVersionViewSet)
router.register("softwareproductinstallations", SoftwareProductInstallationViewSet) router.register("softwareproductinstallations", SoftwareProductInstallationViewSet)
router.register("softwarelicenses", SoftwareLicenseViewSet)
urlpatterns = router.urls urlpatterns = router.urls
+15 -3
View File
@@ -2,12 +2,18 @@ from rest_framework.routers import APIRootView
from netbox.api.viewsets import NetBoxModelViewSet from netbox.api.viewsets import NetBoxModelViewSet
from netbox_slm.api.serializers import ( from netbox_slm.api.serializers import (
SoftwareProductSerializer, SoftwareProductVersionSerializer, SoftwareProductInstallationSerializer, SoftwareProductSerializer,
SoftwareProductVersionSerializer,
SoftwareProductInstallationSerializer,
SoftwareLicenseSerializer,
) )
from netbox_slm.filtersets import ( from netbox_slm.filtersets import (
SoftwareProductFilterSet, SoftwareProductVersionFilterSet, SoftwareProductInstallationFilterSet, SoftwareProductFilterSet,
SoftwareProductVersionFilterSet,
SoftwareProductInstallationFilterSet,
SoftwareLicenseFilterSet,
) )
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
class NetboxSLMRootView(APIRootView): class NetboxSLMRootView(APIRootView):
@@ -35,3 +41,9 @@ class SoftwareProductInstallationViewSet(NetBoxModelViewSet):
queryset = SoftwareProductInstallation.objects.all() queryset = SoftwareProductInstallation.objects.all()
serializer_class = SoftwareProductInstallationSerializer serializer_class = SoftwareProductInstallationSerializer
filterset_class = SoftwareProductInstallationFilterSet filterset_class = SoftwareProductInstallationFilterSet
class SoftwareLicenseViewSet(NetBoxModelViewSet):
queryset = SoftwareLicense.objects.all()
serializer_class = SoftwareLicenseSerializer
filterset_class = SoftwareLicenseFilterSet
+43 -11
View File
@@ -1,7 +1,7 @@
from django.db.models import Q from django.db.models import Q
from netbox.filtersets import NetBoxModelFilterSet from netbox.filtersets import NetBoxModelFilterSet
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
class SoftwareProductFilterSet(NetBoxModelFilterSet): class SoftwareProductFilterSet(NetBoxModelFilterSet):
@@ -15,7 +15,12 @@ class SoftwareProductFilterSet(NetBoxModelFilterSet):
"""Perform the filtered search.""" """Perform the filtered search."""
if not value.strip(): if not value.strip():
return queryset return queryset
qs_filter = Q(name__icontains=value) | Q(manufacturer__name__icontains=value) qs_filter = (
Q(name__icontains=value)
| Q(description__icontains=value)
| Q(manufacturer__name__icontains=value)
| Q(comments__icontains=value)
)
return queryset.filter(qs_filter) return queryset.filter(qs_filter)
@@ -24,17 +29,18 @@ class SoftwareProductVersionFilterSet(NetBoxModelFilterSet):
class Meta: class Meta:
model = SoftwareProductVersion model = SoftwareProductVersion
fields = ( fields = ("software_product",)
"software_product",
)
def search(self, queryset, name, value): def search(self, queryset, name, value):
"""Perform the filtered search.""" """Perform the filtered search."""
if not value.strip(): if not value.strip():
return queryset return queryset
qs_filter = Q(name__icontains=value) | \ qs_filter = (
Q(software_product__name__icontains=value) | \ Q(name__icontains=value)
Q(software_product__manufacturer__name__icontains=value) | Q(software_product__name__icontains=value)
| Q(software_product__manufacturer__name__icontains=value)
| Q(comments__icontains=value)
)
return queryset.filter(qs_filter) return queryset.filter(qs_filter)
@@ -43,13 +49,39 @@ class SoftwareProductInstallationFilterSet(NetBoxModelFilterSet):
class Meta: class Meta:
model = SoftwareProductInstallation model = SoftwareProductInstallation
fields = ("software_product",)
def search(self, queryset, name, value):
"""Perform the filtered search."""
if not value.strip():
return queryset
qs_filter = (
Q(software_product__name__icontains=value)
| Q(software_product__manufacturer__name__icontains=value)
| Q(version__name__icontains=value)
| Q(comments__icontains=value)
)
return queryset.filter(qs_filter)
class SoftwareLicenseFilterSet(NetBoxModelFilterSet):
"""Filter capabilities for SoftwareLicense instances."""
class Meta:
model = SoftwareLicense
fields = tuple() fields = tuple()
def search(self, queryset, name, value): def search(self, queryset, name, value):
"""Perform the filtered search.""" """Perform the filtered search."""
if not value.strip(): if not value.strip():
return queryset return queryset
qs_filter = Q(software_product__name__icontains=value) | \ qs_filter = (
Q(software_product__manufacturer__name__icontains=value) | \ Q(name__icontains=value)
Q(version__name__icontains=value) | Q(software_product__name__icontains=value)
| Q(version__name__icontains=value)
| Q(installation__device__name__icontains=value)
| Q(installation__virtualmachine__name__icontains=value)
| Q(installation__cluster__name__icontains=value)
| Q(comments__icontains=value)
)
return queryset.filter(qs_filter) return queryset.filter(qs_filter)
-167
View File
@@ -1,167 +0,0 @@
from django import forms
from django.urls import reverse_lazy
from django.utils.translation import gettext as _
from dcim.models import Manufacturer, Device
from netbox.forms import NetBoxModelForm, NetBoxModelCSVForm, NetBoxModelBulkEditForm, NetBoxModelFilterSetForm
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation
from utilities.forms import DynamicModelChoiceField, APISelect, TagFilterField
from virtualization.models import VirtualMachine
class SoftwareProductForm(NetBoxModelForm):
"""Form for creating a new SoftwareProduct object."""
manufacturer = DynamicModelChoiceField(
queryset=Manufacturer.objects.all(),
required=True,
)
class Meta:
model = SoftwareProduct
fields = ("name", "manufacturer", "description", "tags")
class SoftwareProductFilterForm(NetBoxModelFilterSetForm):
model = SoftwareProduct
fieldsets = (
(None, ('q', 'tag')),
)
tag = TagFilterField(model)
class SoftwareProductCSVForm(NetBoxModelCSVForm):
class Meta:
model = SoftwareProduct
fields = ("name", "manufacturer",)
class SoftwareProductBulkEditForm(NetBoxModelBulkEditForm):
pk = forms.ModelMultipleChoiceField(
queryset=SoftwareProduct.objects.all(),
widget=forms.MultipleHiddenInput(),
)
class Meta:
model = SoftwareProduct
nullable_fields = []
class SoftwareProductVersionForm(NetBoxModelForm):
"""Form for creating a new SoftwareProductVersion object."""
name = forms.CharField(label=_("Version"))
software_product = DynamicModelChoiceField(
queryset=SoftwareProduct.objects.all(),
widget=APISelect(
attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproduct-list")}
),
)
class Meta:
model = SoftwareProductVersion
fields = ("name", "software_product", "tags")
class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm):
model = SoftwareProductVersion
fieldsets = (
(None, ('q', 'tag')),
)
tag = TagFilterField(model)
class SoftwareProductVersionCSVForm(NetBoxModelCSVForm):
class Meta:
model = SoftwareProductVersion
fields = ("name",)
class SoftwareProductVersionBulkEditForm(NetBoxModelBulkEditForm):
pk = forms.ModelMultipleChoiceField(
queryset=SoftwareProduct.objects.all(),
widget=forms.MultipleHiddenInput(),
)
class Meta:
model = SoftwareProductVersion
nullable_fields = []
class SoftwareProductInstallationForm(NetBoxModelForm):
"""Form for creating a new SoftwareProductInstallation object."""
device = DynamicModelChoiceField(
queryset=Device.objects.all(),
required=False,
)
virtualmachine = DynamicModelChoiceField(
queryset=VirtualMachine.objects.all(),
required=False,
)
software_product = DynamicModelChoiceField(
queryset=SoftwareProduct.objects.all(),
required=True,
widget=APISelect(
attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproduct-list")}
),
)
version = DynamicModelChoiceField(
queryset=SoftwareProductVersion.objects.all(),
required=True,
widget=APISelect(
attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproductversion-list")}
),
query_params={
'software_product': '$software_product',
}
)
class Meta:
model = SoftwareProductInstallation
fields = ("device", "virtualmachine", "software_product", "version", "tags")
def clean_version(self):
version = self.cleaned_data['version']
software_product = self.cleaned_data['software_product']
if version not in software_product.softwareproductversion_set.all():
raise forms.ValidationError(_(f"Version `{version}` doesn't exist on {software_product}, make sure you've "
f"selected a compatible version or first select the software product."))
return version
def clean(self):
if not any([self.cleaned_data['device'], self.cleaned_data['virtualmachine']]):
raise forms.ValidationError(_("Installation requires atleast one virtualmachine or device destination."))
return super(SoftwareProductInstallationForm, self).clean()
class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm):
model = SoftwareProductInstallation
fieldsets = (
(None, ('q', 'tag',)),
)
tag = TagFilterField(model)
class SoftwareProductInstallationCSVForm(NetBoxModelCSVForm):
class Meta:
model = SoftwareProductInstallation
fields = tuple()
class SoftwareProductInstallationBulkEditForm(NetBoxModelBulkEditForm):
software_product = DynamicModelChoiceField(
queryset=SoftwareProduct.objects.all(),
required=False
)
version = DynamicModelChoiceField(
queryset=SoftwareProductVersion.objects.all(),
required=False
)
model = SoftwareProductInstallation
fieldsets = (
(None, ('software_product', 'version',)),
)
+4
View File
@@ -0,0 +1,4 @@
from .software_license import SoftwareLicenseForm, SoftwareLicenseFilterForm
from .software_product import SoftwareProductForm, SoftwareProductFilterForm
from .software_product_installation import SoftwareProductInstallationForm, SoftwareProductInstallationFilterForm
from .software_product_version import SoftwareProductVersionForm, SoftwareProductVersionFilterForm
+67
View File
@@ -0,0 +1,67 @@
from django.forms import DateField
from django.urls import reverse_lazy
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField, LaxURLField
from utilities.forms.rendering import FieldSet
from utilities.forms.widgets import APISelect, DatePicker
class SoftwareLicenseForm(NetBoxModelForm):
"""Form for creating a new SoftwareLicense object."""
comments = CommentField()
stored_location_url = LaxURLField(required=False)
software_product = DynamicModelChoiceField(
queryset=SoftwareProduct.objects.all(),
required=True,
widget=APISelect(attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproduct-list")}),
)
version = DynamicModelChoiceField(
queryset=SoftwareProductVersion.objects.all(),
required=False,
widget=APISelect(attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproductversion-list")}),
query_params={
"software_product": "$software_product",
},
)
installation = DynamicModelChoiceField(
queryset=SoftwareProductInstallation.objects.all(),
required=False,
widget=APISelect(
attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproductinstallation-list")}
),
query_params={
"software_product": "$software_product",
},
)
start_date = DateField(required=False, widget=DatePicker())
expiration_date = DateField(required=False, widget=DatePicker())
class Meta:
model = SoftwareLicense
fields = (
"name",
"description",
"type",
"stored_location",
"stored_location_url",
"start_date",
"expiration_date",
"support",
"license_amount",
"software_product",
"version",
"installation",
"tags",
"comments",
)
class SoftwareLicenseFilterForm(NetBoxModelFilterSetForm):
model = SoftwareLicense
fieldsets = (FieldSet(None, ("q", "tag")),)
tag = TagFilterField(model)
+32
View File
@@ -0,0 +1,32 @@
from dcim.models import Manufacturer
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm
from netbox_slm.models import SoftwareProduct
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField
from utilities.forms.rendering import FieldSet
class SoftwareProductForm(NetBoxModelForm):
"""Form for creating a new SoftwareProduct object."""
comments = CommentField()
manufacturer = DynamicModelChoiceField(
queryset=Manufacturer.objects.all(),
required=True,
)
class Meta:
model = SoftwareProduct
fields = (
"name",
"description",
"manufacturer",
"tags",
"comments",
)
class SoftwareProductFilterForm(NetBoxModelFilterSetForm):
model = SoftwareProduct
fieldsets = (FieldSet(None, ("q", "tag")),)
tag = TagFilterField(model)
@@ -0,0 +1,61 @@
from django.forms import ValidationError
from django.urls import reverse_lazy
from dcim.models import Device
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm
from netbox_slm.models import SoftwareProductInstallation, SoftwareProduct, SoftwareProductVersion
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField
from utilities.forms.rendering import FieldSet
from utilities.forms.widgets import APISelect
from virtualization.models import VirtualMachine, Cluster
class SoftwareProductInstallationForm(NetBoxModelForm):
"""Form for creating a new SoftwareProductInstallation object."""
comments = CommentField()
device = DynamicModelChoiceField(queryset=Device.objects.all(), required=False)
virtualmachine = DynamicModelChoiceField(queryset=VirtualMachine.objects.all(), required=False)
cluster = DynamicModelChoiceField(queryset=Cluster.objects.all(), required=False)
software_product = DynamicModelChoiceField(
queryset=SoftwareProduct.objects.all(),
required=True,
widget=APISelect(attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproduct-list")}),
)
version = DynamicModelChoiceField(
queryset=SoftwareProductVersion.objects.all(),
required=True,
widget=APISelect(attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproductversion-list")}),
query_params={
"software_product": "$software_product",
},
)
class Meta:
model = SoftwareProductInstallation
fields = (
"device",
"virtualmachine",
"cluster",
"software_product",
"version",
"tags",
"comments",
)
def clean_version(self):
version = self.cleaned_data["version"]
software_product = self.cleaned_data["software_product"]
if version not in software_product.softwareproductversion_set.all():
raise ValidationError(
f"Version '{version}' doesn't exist on {software_product}, make sure you've "
f"selected a compatible version or first select the software product."
)
return version
class SoftwareProductInstallationFilterForm(NetBoxModelFilterSetForm):
model = SoftwareProductInstallation
fieldsets = (FieldSet(None, ("q", "tag")),)
tag = TagFilterField(model)
@@ -0,0 +1,44 @@
from django.forms import DateField
from django.urls import reverse_lazy
from netbox.forms import NetBoxModelForm, NetBoxModelFilterSetForm
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion
from utilities.forms.fields import CommentField, DynamicModelChoiceField, TagFilterField
from utilities.forms.rendering import FieldSet
from utilities.forms.widgets import APISelect, DatePicker
class SoftwareProductVersionForm(NetBoxModelForm):
"""Form for creating a new SoftwareProductVersion object."""
comments = CommentField()
release_date = DateField(required=False, widget=DatePicker())
end_of_support = DateField(required=False, widget=DatePicker())
software_product = DynamicModelChoiceField(
queryset=SoftwareProduct.objects.all(),
widget=APISelect(attrs={"data-url": reverse_lazy("plugins-api:netbox_slm-api:softwareproduct-list")}),
)
class Meta:
model = SoftwareProductVersion
fields = (
"name",
"release_date",
"documentation_url",
"end_of_support",
"filename",
"file_checksum",
"file_link",
"release_type",
"software_product",
"tags",
"comments",
)
class SoftwareProductVersionFilterForm(NetBoxModelFilterSetForm):
model = SoftwareProductVersion
fieldsets = (FieldSet(None, ("q", "tag")),)
tag = TagFilterField(model)
@@ -0,0 +1,54 @@
# Generated by Django 4.1.8 on 2023-06-27 08:10
from django.db import migrations, models
import django.db.models.deletion
import taggit.managers
import utilities.json
class Migration(migrations.Migration):
dependencies = [
('extras', '0084_staging'),
('netbox_slm', '0004_auto_20220415_0705'),
]
operations = [
migrations.AlterField(
model_name='softwareproduct',
name='custom_field_data',
field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
migrations.AlterField(
model_name='softwareproductinstallation',
name='custom_field_data',
field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
migrations.AlterField(
model_name='softwareproductversion',
name='custom_field_data',
field=models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder),
),
migrations.CreateModel(
name='SoftwareLicense',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False)),
('created', models.DateTimeField(auto_now_add=True, null=True)),
('last_updated', models.DateTimeField(auto_now=True, null=True)),
('custom_field_data', models.JSONField(blank=True, default=dict, encoder=utilities.json.CustomFieldJSONEncoder)),
('name', models.CharField(max_length=128)),
('description', models.CharField(blank=True, max_length=255, null=True)),
('type', models.CharField(max_length=128)),
('stored_location', models.CharField(blank=True, max_length=255, null=True)),
('start_date', models.DateField(blank=True, null=True)),
('expiration_date', models.DateField(blank=True, null=True)),
('installation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='netbox_slm.softwareproductinstallation')),
('software_product', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='netbox_slm.softwareproduct')),
('tags', taggit.managers.TaggableManager(through='extras.TaggedItem', to='extras.Tag')),
('version', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='netbox_slm.softwareproductversion')),
],
options={
'abstract': False,
},
),
]
@@ -0,0 +1,19 @@
# Generated by Django 4.2.5 on 2023-09-22 00:34
from django.db import migrations
import netbox_slm.models
class Migration(migrations.Migration):
dependencies = [
('netbox_slm', '0005_add_software_license'),
]
operations = [
migrations.AddField(
model_name='softwarelicense',
name='stored_location_url',
field=netbox_slm.models.LaxURLField(blank=True, max_length=1024, null=True),
),
]
@@ -0,0 +1,29 @@
# Generated by Django 4.2.5 on 2023-10-04 10:07
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('virtualization', '0036_virtualmachine_config_template'),
('netbox_slm', '0006_softwarelicense_stored_location_url'),
]
operations = [
migrations.AddField(
model_name='softwareproductinstallation',
name='cluster',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='virtualization.cluster'),
),
migrations.AlterField(
model_name='softwarelicense',
name='installation',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='netbox_slm.softwareproductinstallation'),
),
migrations.AddConstraint(
model_name='softwareproductinstallation',
constraint=models.CheckConstraint(check=models.Q(models.Q(('cluster__isnull', True), ('device__isnull', False), ('virtualmachine__isnull', True)), models.Q(('cluster__isnull', True), ('device__isnull', True), ('virtualmachine__isnull', False)), models.Q(('cluster__isnull', False), ('device__isnull', True), ('virtualmachine__isnull', True)), _connector='OR'), name='netbox_slm_softwareproductinstallation_platform', violation_error_message='Installation requires exactly one platform destination.'),
),
]
@@ -0,0 +1,79 @@
# Generated by Django 4.2.9 on 2024-02-07 21:01
from django.db import migrations, models
import netbox_slm.models
class Migration(migrations.Migration):
dependencies = [
('netbox_slm', '0007_softwareproductinstallation_cluster'),
]
operations = [
migrations.AddField(
model_name='softwarelicense',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='softwarelicense',
name='license_amount',
field=models.PositiveIntegerField(blank=True, default=None, null=True),
),
migrations.AddField(
model_name='softwarelicense',
name='support',
field=models.BooleanField(blank=True, default=None, null=True),
),
migrations.AddField(
model_name='softwareproduct',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='softwareproductinstallation',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='comments',
field=models.TextField(blank=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='documentation_url',
field=netbox_slm.models.LaxURLField(blank=True, max_length=1024, null=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='end_of_support',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='file_checksum',
field=models.CharField(blank=True, max_length=128, null=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='file_link',
field=netbox_slm.models.LaxURLField(blank=True, max_length=1024, null=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='filename',
field=models.CharField(blank=True, max_length=64, null=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='release_date',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='softwareproductversion',
name='release_type',
field=models.CharField(default='S', max_length=3),
),
]
+119 -37
View File
@@ -4,17 +4,24 @@ from django.utils import safestring
from netbox.models import NetBoxModel from netbox.models import NetBoxModel
from utilities.querysets import RestrictedQuerySet from utilities.querysets import RestrictedQuerySet
from utilities.validators import EnhancedURLValidator
class LaxURLField(models.URLField):
"""
NetBox Custom Field approach, based on utilities.forms.fields.LaxURLField
Overriding default_validators is needed, as they are always added
"""
default_validators = [EnhancedURLValidator()]
class SoftwareProduct(NetBoxModel): class SoftwareProduct(NetBoxModel):
name = models.CharField(max_length=128) name = models.CharField(max_length=128)
description = models.CharField(max_length=255, null=True, blank=True) comments = models.TextField(blank=True)
manufacturer = models.ForeignKey( description = models.CharField(max_length=255, null=True, blank=True)
to='dcim.Manufacturer', manufacturer = models.ForeignKey(to="dcim.Manufacturer", on_delete=models.PROTECT, null=True, blank=True)
on_delete=models.PROTECT,
null=True, blank=True
)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@@ -26,18 +33,46 @@ class SoftwareProduct(NetBoxModel):
def get_installation_count(self): def get_installation_count(self):
count = SoftwareProductInstallation.objects.filter(software_product_id=self.pk).count() count = SoftwareProductInstallation.objects.filter(software_product_id=self.pk).count()
return safestring.mark_safe("<a href=\"{url}\">{count}</a>".format( return (
safestring.mark_safe(
'<a href="{url}">{count}</a>'.format(
url=reverse_lazy("plugins:netbox_slm:softwareproductinstallation_list") + f"?q={self.name}", url=reverse_lazy("plugins:netbox_slm:softwareproductinstallation_list") + f"?q={self.name}",
count=count count=count,
)) if count else "0" )
)
if count
else "0"
)
class SoftwareReleaseTypes(models.TextChoices):
ALPHA = "A", "Alpha"
BETA = "B", "Beta"
RELEASE_CANDIDATE = "RC", "Release candidate"
STABLE = "S", "Stable release"
class SoftwareProductVersion(NetBoxModel): class SoftwareProductVersion(NetBoxModel):
name = models.CharField(max_length=64)
comments = models.TextField(blank=True)
release_date = models.DateField(null=True, blank=True)
documentation_url = LaxURLField(max_length=1024, null=True, blank=True)
end_of_support = models.DateField(null=True, blank=True)
filename = models.CharField(max_length=64, null=True, blank=True)
file_checksum = models.CharField(max_length=128, null=True, blank=True)
file_link = LaxURLField(max_length=1024, null=True, blank=True)
release_type = models.CharField(
max_length=3,
choices=SoftwareReleaseTypes.choices,
default=SoftwareReleaseTypes.STABLE,
)
software_product = models.ForeignKey( software_product = models.ForeignKey(
to='netbox_slm.SoftwareProduct', to="netbox_slm.SoftwareProduct",
on_delete=models.PROTECT, on_delete=models.PROTECT,
) )
name = models.CharField(max_length=64)
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
@@ -49,44 +84,91 @@ class SoftwareProductVersion(NetBoxModel):
def get_installation_count(self): def get_installation_count(self):
count = SoftwareProductInstallation.objects.filter(version_id=self.pk).count() count = SoftwareProductInstallation.objects.filter(version_id=self.pk).count()
return safestring.mark_safe("<a href=\"{url}\">{count}</a>".format( return (
safestring.mark_safe(
'<a href="{url}">{count}</a>'.format(
url=reverse_lazy("plugins:netbox_slm:softwareproductinstallation_list") + f"?q={self.name}", url=reverse_lazy("plugins:netbox_slm:softwareproductinstallation_list") + f"?q={self.name}",
count=count count=count,
)) if count else "0" )
)
if count
else "0"
)
class SoftwareProductInstallation(NetBoxModel): class SoftwareProductInstallation(NetBoxModel):
device = models.ForeignKey( comments = models.TextField(blank=True)
to='dcim.Device',
on_delete=models.PROTECT, device = models.ForeignKey(to="dcim.Device", on_delete=models.PROTECT, null=True, blank=True)
null=True,
blank=True
)
virtualmachine = models.ForeignKey( virtualmachine = models.ForeignKey(
to='virtualization.VirtualMachine', to="virtualization.VirtualMachine", on_delete=models.PROTECT, null=True, blank=True
on_delete=models.PROTECT,
null=True,
blank=True
) )
software_product = models.ForeignKey( cluster = models.ForeignKey(to="virtualization.Cluster", on_delete=models.PROTECT, null=True, blank=True)
to='netbox_slm.SoftwareProduct', software_product = models.ForeignKey(to="netbox_slm.SoftwareProduct", on_delete=models.PROTECT)
on_delete=models.PROTECT, version = models.ForeignKey(to="netbox_slm.SoftwareProductVersion", on_delete=models.PROTECT)
objects = RestrictedQuerySet.as_manager()
def __str__(self):
return f"{self.pk} ({self.platform})"
class Meta:
constraints = [
models.CheckConstraint(
name="%(app_label)s_%(class)s_platform",
check=(
models.Q(device__isnull=False, virtualmachine__isnull=True, cluster__isnull=True)
| models.Q(device__isnull=True, virtualmachine__isnull=False, cluster__isnull=True)
| models.Q(device__isnull=True, virtualmachine__isnull=True, cluster__isnull=False)
),
violation_error_message="Installation requires exactly one platform destination.",
) )
version = models.ForeignKey( ]
to='netbox_slm.SoftwareProductVersion',
on_delete=models.PROTECT, def get_absolute_url(self):
return reverse("plugins:netbox_slm:softwareproductinstallation", kwargs={"pk": self.pk})
@property
def platform(self):
return self.device or self.virtualmachine or self.cluster
def render_type(self):
if self.device:
return "device"
if self.virtualmachine:
return "virtualmachine"
return "cluster"
class SoftwareLicense(NetBoxModel):
name = models.CharField(max_length=128)
comments = models.TextField(blank=True)
description = models.CharField(max_length=255, null=True, blank=True)
type = models.CharField(max_length=128)
stored_location = models.CharField(max_length=255, null=True, blank=True)
stored_location_url = LaxURLField(max_length=1024, null=True, blank=True)
start_date = models.DateField(null=True, blank=True)
expiration_date = models.DateField(null=True, blank=True)
support = models.BooleanField(default=None, null=True, blank=True)
license_amount = models.PositiveIntegerField(default=None, null=True, blank=True)
software_product = models.ForeignKey(to="netbox_slm.SoftwareProduct", on_delete=models.PROTECT)
version = models.ForeignKey(to="netbox_slm.SoftwareProductVersion", on_delete=models.PROTECT, null=True, blank=True)
installation = models.ForeignKey(
to="netbox_slm.SoftwareProductInstallation", on_delete=models.SET_NULL, null=True, blank=True
) )
objects = RestrictedQuerySet.as_manager() objects = RestrictedQuerySet.as_manager()
def __str__(self): def __str__(self):
return f"{self.pk}" return self.name
def get_absolute_url(self): def get_absolute_url(self):
return reverse("plugins:netbox_slm:softwareproductinstallation", kwargs={"pk": self.pk}) return reverse("plugins:netbox_slm:softwarelicense", kwargs={"pk": self.pk})
def get_platform(self): @property
return self.device or self.virtualmachine def stored_location_txt(self):
if self.stored_location_url and not self.stored_location:
def render_type(self): return "Link"
return 'device' if self.device else 'virtualmachine' return self.stored_location
+23 -32
View File
@@ -1,65 +1,56 @@
from extras.plugins import PluginMenuButton, PluginMenuItem from netbox.plugins import PluginMenuButton, PluginMenuItem
from utilities.choices import ButtonColorChoices
menu_items = ( menu_items = (
PluginMenuItem( PluginMenuItem(
link='plugins:netbox_slm:softwareproduct_list', link="plugins:netbox_slm:softwareproduct_list",
link_text='Software Products', link_text="Software Products",
permissions=["netbox_slm.add_softwareproduct"],
buttons=( buttons=(
PluginMenuButton( PluginMenuButton(
"plugins:netbox_slm:softwareproduct_add", "plugins:netbox_slm:softwareproduct_add",
"Add", "Add",
"mdi mdi-plus-thick", "mdi mdi-plus-thick",
ButtonColorChoices.GREEN,
permissions=["netbox_slm.add_softwareproduct"], permissions=["netbox_slm.add_softwareproduct"],
), ),
PluginMenuButton(
"plugins:netbox_slm:softwareproduct_import",
"Import",
"mdi mdi-upload",
ButtonColorChoices.CYAN,
permissions=["netbox_slm.add_softwareproduct"],
), ),
)
), ),
PluginMenuItem( PluginMenuItem(
link='plugins:netbox_slm:softwareproductversion_list', link="plugins:netbox_slm:softwareproductversion_list",
link_text='Versions', link_text="Versions",
permissions=["netbox_slm.add_softwareproductversion"],
buttons=( buttons=(
PluginMenuButton( PluginMenuButton(
"plugins:netbox_slm:softwareproductversion_add", "plugins:netbox_slm:softwareproductversion_add",
"Add", "Add",
"mdi mdi-plus-thick", "mdi mdi-plus-thick",
ButtonColorChoices.GREEN,
permissions=["netbox_slm.add_softwareproductversion"], permissions=["netbox_slm.add_softwareproductversion"],
), ),
PluginMenuButton(
"plugins:netbox_slm:softwareproductversion_import",
"Import",
"mdi mdi-upload",
ButtonColorChoices.CYAN,
permissions=["netbox_slm.add_softwareproductversion"],
), ),
)
), ),
PluginMenuItem( PluginMenuItem(
link='plugins:netbox_slm:softwareproductinstallation_list', link="plugins:netbox_slm:softwareproductinstallation_list",
link_text='Installations', link_text="Installations",
permissions=["netbox_slm.add_softwareproductinstallation"],
buttons=( buttons=(
PluginMenuButton( PluginMenuButton(
"plugins:netbox_slm:softwareproductinstallation_add", "plugins:netbox_slm:softwareproductinstallation_add",
"Add", "Add",
"mdi mdi-plus-thick", "mdi mdi-plus-thick",
ButtonColorChoices.GREEN,
permissions=["netbox_slm.add_softwareproductinstallation"], permissions=["netbox_slm.add_softwareproductinstallation"],
), ),
),
),
PluginMenuItem(
link="plugins:netbox_slm:softwarelicense_list",
link_text="Licenses",
permissions=["netbox_slm.add_softwarelicense"],
buttons=(
PluginMenuButton( PluginMenuButton(
"plugins:netbox_slm:softwareproductinstallation_import", "plugins:netbox_slm:softwarelicense_add",
"Import", "Add",
"mdi mdi-upload", "mdi mdi-plus-thick",
ButtonColorChoices.CYAN, permissions=["netbox_slm.add_softwarelicense"],
permissions=["netbox_slm.add_softwareproductinstallation"], ),
), ),
)
), ),
) )
+87 -58
View File
@@ -1,9 +1,8 @@
import django_tables2 as tables import django_tables2 as tables
from django.db.models import Count from django.db.models import Count, F, Value
from django_tables2.utils import Accessor
from netbox.tables import NetBoxTable, ToggleColumn, columns from netbox.tables import NetBoxTable, ToggleColumn, columns
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
class SoftwareProductTable(NetBoxTable): class SoftwareProductTable(NetBoxTable):
@@ -11,15 +10,10 @@ class SoftwareProductTable(NetBoxTable):
pk = ToggleColumn() pk = ToggleColumn()
name = tables.LinkColumn() name = tables.LinkColumn()
manufacturer = tables.Column( manufacturer = tables.Column(accessor="manufacturer", linkify=True)
accessor=Accessor('manufacturer'), installations = tables.Column(accessor="get_installation_count")
linkify=True
)
installations = tables.Column(accessor='get_installation_count', verbose_name='Installations')
tags = columns.TagColumn( tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproduct_list")
url_name="plugins:netbox_slm:softwareproduct_list",
)
class Meta(NetBoxTable.Meta): class Meta(NetBoxTable.Meta):
model = SoftwareProduct model = SoftwareProduct
@@ -47,9 +41,9 @@ class SoftwareProductTable(NetBoxTable):
) )
def order_installations(self, queryset, is_descending): def order_installations(self, queryset, is_descending):
queryset = queryset.annotate( queryset = queryset.annotate(count=Count("softwareproductinstallation__id")).order_by(
count=Count('softwareproductinstallation__id') ("-" if is_descending else "") + "count"
).order_by(("-" if is_descending else "") + "count") )
return queryset, True return queryset, True
@@ -57,20 +51,12 @@ class SoftwareProductVersionTable(NetBoxTable):
"""Table for displaying SoftwareProductVersion objects.""" """Table for displaying SoftwareProductVersion objects."""
pk = ToggleColumn() pk = ToggleColumn()
name = tables.LinkColumn(verbose_name='Version') name = tables.LinkColumn()
software_product = tables.Column( software_product = tables.Column(accessor="software_product", linkify=True)
accessor=Accessor('software_product'), manufacturer = tables.Column(accessor="software_product__manufacturer", linkify=True)
linkify=True installations = tables.Column(accessor="get_installation_count")
)
manufacturer = tables.Column(
accessor=Accessor('software_product__manufacturer'),
linkify=True
)
installations = tables.Column(accessor='get_installation_count', verbose_name='Installations')
tags = columns.TagColumn( tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproductversion_list")
url_name="plugins:netbox_slm:softwareproductversion_list",
)
class Meta(NetBoxTable.Meta): class Meta(NetBoxTable.Meta):
model = SoftwareProductVersion model = SoftwareProductVersion
@@ -79,6 +65,9 @@ class SoftwareProductVersionTable(NetBoxTable):
"name", "name",
"software_product", "software_product",
"manufacturer", "manufacturer",
"release_date",
"end_of_support",
"release_type",
"installations", "installations",
"tags", "tags",
) )
@@ -87,6 +76,7 @@ class SoftwareProductVersionTable(NetBoxTable):
"name", "name",
"software_product", "software_product",
"manufacturer", "manufacturer",
"release_date",
"installations", "installations",
"tags", "tags",
) )
@@ -98,9 +88,9 @@ class SoftwareProductVersionTable(NetBoxTable):
) )
def order_installations(self, queryset, is_descending): def order_installations(self, queryset, is_descending):
queryset = queryset.annotate( queryset = queryset.annotate(count=Count("softwareproductinstallation__id")).order_by(
count=Count('softwareproductinstallation__id') ("-" if is_descending else "") + "count"
).order_by(("-" if is_descending else "") + "count") )
return queryset, True return queryset, True
@@ -109,31 +99,16 @@ class SoftwareProductInstallationTable(NetBoxTable):
pk = ToggleColumn() pk = ToggleColumn()
name = tables.LinkColumn() name = tables.LinkColumn()
device = tables.Column(
accessor=Accessor('device'),
linkify=True
)
virtualmachine = tables.Column(
accessor=Accessor('virtualmachine'),
linkify=True
)
platform = tables.Column(
accessor='get_platform',
linkify=True
)
type = tables.Column(accessor='render_type')
software_product = tables.Column(
accessor=Accessor('software_product'),
linkify=True
)
version = tables.Column(
accessor=Accessor('version'),
linkify=True
)
tags = columns.TagColumn( device = tables.Column(accessor="device", linkify=True)
url_name="plugins:netbox_slm:softwareproductinstallation_list", virtualmachine = tables.Column(accessor="virtualmachine", linkify=True)
) cluster = tables.Column(accessor="cluster", linkify=True)
platform = tables.Column(accessor="platform", linkify=True)
type = tables.Column(accessor="render_type")
software_product = tables.Column(accessor="software_product", linkify=True)
version = tables.Column(accessor="version", linkify=True)
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproductinstallation_list")
class Meta(NetBoxTable.Meta): class Meta(NetBoxTable.Meta):
model = SoftwareProductInstallation model = SoftwareProductInstallation
@@ -156,12 +131,66 @@ class SoftwareProductInstallationTable(NetBoxTable):
) )
def order_platform(self, queryset, is_descending): def order_platform(self, queryset, is_descending):
queryset = queryset.order_by(("device" if is_descending else "virtualmachine")) device_annotate = queryset.filter(device__isnull=False).annotate(platform_value=F("device__name"))
return queryset, True vm_annotate = queryset.filter(virtualmachine__isnull=False).annotate(platform_value=F("virtualmachine__name"))
cluster_annotate = queryset.filter(cluster__isnull=False).annotate(platform_value=F("cluster__name"))
queryset_union = device_annotate.union(vm_annotate).union(cluster_annotate)
return queryset_union.order_by(f"{'-' if is_descending else ''}platform_value"), True
def order_type(self, queryset, is_descending): def order_type(self, queryset, is_descending):
queryset = queryset.order_by(("device" if is_descending else "virtualmachine")) device_annotate = queryset.filter(device__isnull=False).annotate(render_type=Value("device"))
return queryset, True vm_annotate = queryset.filter(virtualmachine__isnull=False).annotate(render_type=Value("virtualmachine"))
cluster_annotate = queryset.filter(cluster__isnull=False).annotate(render_type=Value("cluster"))
queryset_union = device_annotate.union(vm_annotate).union(cluster_annotate)
return queryset_union.order_by(f"{'-' if is_descending else ''}render_type"), True
def render_software_product(self, value, **kwargs): def render_software_product(self, value, **kwargs):
return f"{kwargs['record'].software_product.manufacturer.name} - {value}" return f"{kwargs['record'].software_product.manufacturer.name} - {value}"
class SoftwareLicenseTable(NetBoxTable):
"""Table for displaying SoftwareLicense objects."""
pk = ToggleColumn()
name = tables.LinkColumn()
type = tables.Column()
stored_location = tables.Column(accessor="stored_location_txt", linkify=lambda record: record.stored_location_url)
software_product = tables.Column(accessor="software_product", linkify=True)
version = tables.Column(accessor="version", linkify=True)
installation = tables.Column(accessor="installation", linkify=True)
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwarelicense_list")
class Meta(NetBoxTable.Meta):
model = SoftwareLicense
fields = (
"pk",
"name",
"description",
"type",
"stored_location",
"start_date",
"expiration_date",
"software_product",
"version",
"installation",
"support",
"license_amount",
"tags",
)
default_columns = (
"pk",
"name",
"expiration_date",
"software_product",
"installation",
"tags",
)
def render_software_product(self, value, **kwargs):
return f"{kwargs['record'].software_product.manufacturer.name} - {value}"
def render_installation(self, **kwargs):
return f"{kwargs['record'].installation.platform}"
@@ -0,0 +1,76 @@
{% extends 'generic/object.html' %}
{% load buttons %}
{% load static %}
{% load helpers %}
{% load plugins %}
{% block content %}
<div class="row my-3">
<div class="col col-md-6">
<div class="card">
<h5 class="card-header">
Software License
</h5>
<table class="table table-hover attr-table">
<tr>
<th scope="row">Name</th>
<td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description }}</td>
</tr>
<tr>
<th scope="row">Type</th>
<td>{{ object.type }}</td>
</tr>
<tr>
<th scope="row">Stored location</th>
{% if object.stored_location_url %}
<td><a href="{{ object.stored_location_url }}">{{ object.stored_location_txt }}</a></td>
{% else %}
<td>{{ object.stored_location_txt }}</td>
{% endif %}
</tr>
<tr>
<th scope="row">Start date</th>
<td>{{ object.start_date }}</td>
</tr>
<tr>
<th scope="row">Expiration date</th>
<td>{{ object.expiration_date }}</td>
</tr>
<tr>
<th scope="row">Software Product</th>
<td>{{ object.software_product }}</td>
</tr>
<tr>
<th scope="row">Version</th>
<td>{{ object.version }}</td>
</tr>
<tr>
<th scope="row">Support</th>
<td>{{ object.support }}</td>
</tr>
<tr>
<th scope="row">License amount</th>
<td>{{ object.license_amount }}</td>
</tr>
<tr>
<th scope="row">Installation</th>
<td>{{ object.installation }}</td>
</tr>
</table>
</div>
{% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/tags.html' %}
{% include 'inc/panels/comments.html' %}
{% plugin_left_page object %}
</div>
</div>
<div class="row">
<div class="col col-md-12">
{% plugin_full_width_page object %}
</div>
</div>
{% endblock %}
@@ -11,11 +11,18 @@
<h5 class="card-header"> <h5 class="card-header">
Software Product Software Product
</h5> </h5>
<div class="card-body">
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
<tr> <tr>
<th scope="row">Name</th> <th scope="row">Name</th>
<td>{{ object }}</td> <td>{{ object.name }}</td>
</tr>
<tr>
<th scope="row">Description</th>
<td>{{ object.description }}</td>
</tr>
<tr>
<th scope="row">Manufacturer</th>
<td>{{ object.manufacturer }}</td>
</tr> </tr>
<tr> <tr>
<th scope="row">Versions</th> <th scope="row">Versions</th>
@@ -31,10 +38,9 @@
</tr> </tr>
</table> </table>
</div> </div>
</div>
{% include 'inc/panels/custom_fields.html' %} {% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/tags.html' %} {% include 'inc/panels/tags.html' %}
{# {% include 'inc/panels/comments.html' %}#} {% include 'inc/panels/comments.html' %}
{% plugin_left_page object %} {% plugin_left_page object %}
</div> </div>
</div> </div>
@@ -11,18 +11,22 @@
<h5 class="card-header"> <h5 class="card-header">
Software Product Installation Software Product Installation
</h5> </h5>
<div class="card-body">
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
{% if object.device %} {% if object.device %}
<tr> <tr>
<th scope="row">Device</th> <th scope="row">Device</th>
<td>{{ object.device }}</td> <td>{{ object.device }}</td>
</tr> </tr>
{% else %} {% elif object.virtualmachine %}
<tr> <tr>
<th scope="row">Virtualmachine</th> <th scope="row">Virtualmachine</th>
<td>{{ object.virtualmachine }}</td> <td>{{ object.virtualmachine }}</td>
</tr> </tr>
{% else %}
<tr>
<th scope="row">Cluster</th>
<td>{{ object.cluster }}</td>
</tr>
{% endif %} {% endif %}
<tr> <tr>
<th scope="row">Software Product</th> <th scope="row">Software Product</th>
@@ -34,10 +38,9 @@
</tr> </tr>
</table> </table>
</div> </div>
</div>
{% include 'inc/panels/custom_fields.html' %} {% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/tags.html' %} {% include 'inc/panels/tags.html' %}
{# {% include 'inc/panels/comments.html' %}#} {% include 'inc/panels/comments.html' %}
{% plugin_left_page object %} {% plugin_left_page object %}
</div> </div>
</div> </div>
@@ -11,24 +11,52 @@
<h5 class="card-header"> <h5 class="card-header">
Software Product Version Software Product Version
</h5> </h5>
<div class="card-body">
<table class="table table-hover attr-table"> <table class="table table-hover attr-table">
<tr> <tr>
<th scope="row">Name</th> <th scope="row">Name</th>
<td>{{ object.name }}</td> <td>{{ object.name }}</td>
</tr> </tr>
<tr>
<th scope="row">Release date</th>
<td>{{ object.release_date }}</td>
</tr>
<tr>
<th scope="row">Documentation url</th>
{% if object.documentation_url %}
<td><a href="{{ object.documentation_url }}">{{ object.documentation_url }}</a></td>
{% else %}
<td>{{ object.documentation_url }}</td>
{% endif %}
</tr>
<tr>
<th scope="row">End of support</th>
<td>{{ object.end_of_support }}</td>
</tr>
<tr>
<th scope="row">Filename</th>
{% if object.file_link %}
<td><a href="{{ object.file_link }}">{{ object.filename }}</a></td>
{% else %}
<td>{{ object.filename }}</td>
{% endif %}
</tr>
<tr>
<th scope="row">File checksum</th>
<td>{{ object.file_checksum }}</td>
</tr>
<tr>
<th scope="row">Release type</th>
<td>{{ object.get_release_type_display }}</td>
</tr>
<tr> <tr>
<th scope="row">Installations</th> <th scope="row">Installations</th>
<td> <td>{{ object.get_installation_count }}</td>
{{ object.get_installation_count }}
</td>
</tr> </tr>
</table> </table>
</div> </div>
</div>
{% include 'inc/panels/custom_fields.html' %} {% include 'inc/panels/custom_fields.html' %}
{% include 'inc/panels/tags.html' %} {% include 'inc/panels/tags.html' %}
{# {% include 'inc/panels/comments.html' %}#} {% include 'inc/panels/comments.html' %}
{% plugin_left_page object %} {% plugin_left_page object %}
</div> </div>
</div> </div>
+45 -4
View File
@@ -1,30 +1,52 @@
from django.test import TestCase from django.test import TestCase
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation from dcim.models import Device, DeviceRole, DeviceType, Manufacturer, Site
from virtualization.models import Cluster, ClusterType, VirtualMachine
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
class ModelTestCase(TestCase): class ModelTestCase(TestCase):
def setUp(self): def setUp(self):
self.p_name = "test product" self.p_name = "test product"
self.v_name = "test version" self.v_name = "test version"
self.l_name = "test license"
manufacturer = Manufacturer.objects.create(name="test manufacturer")
device_type = DeviceType.objects.create(model="test device type", manufacturer=manufacturer)
device_role = DeviceRole.objects.create(name="test device role")
site = Site.objects.create(name="test site")
self.device = Device.objects.create(name="test device", device_type=device_type, role=device_role, site=site)
self.vm = VirtualMachine.objects.create(name="test VM")
cluster_type = ClusterType.objects.create(name="test cluster type")
self.cluster = Cluster.objects.create(name="test cluster", type=cluster_type)
self.test_url = "https://github.com/ICTU/netbox_slm"
self.software_product = SoftwareProduct.objects.create(name=self.p_name) self.software_product = SoftwareProduct.objects.create(name=self.p_name)
self.software_product_version = SoftwareProductVersion.objects.create( self.software_product_version = SoftwareProductVersion.objects.create(
name=self.v_name, software_product=self.software_product name=self.v_name, software_product=self.software_product
) )
self.software_product_installation = SoftwareProductInstallation.objects.create( self.software_product_installation = SoftwareProductInstallation.objects.create(
software_product=self.software_product, version=self.software_product_version virtualmachine=self.vm, software_product=self.software_product, version=self.software_product_version
)
self.software_license = SoftwareLicense.objects.create(
name=self.l_name,
software_product=self.software_product,
version=self.software_product_version,
installation=self.software_product_installation,
stored_location_url=self.test_url,
) )
def test_model_name(self): def test_model_name(self):
self.assertEqual(self.p_name, str(self.software_product)) self.assertEqual(self.p_name, str(self.software_product))
self.assertEqual(self.v_name, str(self.software_product_version)) self.assertEqual(self.v_name, str(self.software_product_version))
self.assertTrue(str(self.software_product_installation).isnumeric()) # should be PK self.assertTrue(str(self.software_product_installation)[0].isdigit()) # starts with PK
self.assertEqual(self.l_name, str(self.software_license))
def test_absolute_url(self): def test_absolute_url(self):
self.assertEqual("/plugins/slm/software-products/1/", self.software_product.get_absolute_url()) self.assertEqual("/plugins/slm/software-products/1/", self.software_product.get_absolute_url())
self.assertEqual("/plugins/slm/versions/1/", self.software_product_version.get_absolute_url()) self.assertEqual("/plugins/slm/versions/1/", self.software_product_version.get_absolute_url())
self.assertEqual("/plugins/slm/installations/1/", self.software_product_installation.get_absolute_url()) self.assertEqual("/plugins/slm/installations/1/", self.software_product_installation.get_absolute_url())
self.assertEqual("/plugins/slm/licenses/1/", self.software_license.get_absolute_url())
def test_get_installation_count(self): def test_get_installation_count(self):
installation_ss = '<a href="/plugins/slm/installations/?q={}">1</a>' installation_ss = '<a href="/plugins/slm/installations/?q={}">1</a>'
@@ -33,4 +55,23 @@ class ModelTestCase(TestCase):
def test_product_installation_methods(self): def test_product_installation_methods(self):
self.assertEqual("virtualmachine", self.software_product_installation.render_type()) self.assertEqual("virtualmachine", self.software_product_installation.render_type())
self.assertIsNone(self.software_product_installation.get_platform()) self.assertEqual(self.vm, self.software_product_installation.platform)
self.software_product_installation.virtualmachine = None
self.software_product_installation.device = self.device
self.software_product_installation.save()
self.assertEqual("device", self.software_product_installation.render_type())
self.assertEqual(self.device, self.software_product_installation.platform)
self.software_product_installation.device = None
self.software_product_installation.cluster = self.cluster
self.software_product_installation.save()
self.assertEqual("cluster", self.software_product_installation.render_type())
self.assertEqual(self.cluster, self.software_product_installation.platform)
def test_software_license_stored_location_txt(self):
self.assertEqual("Link", self.software_license.stored_location_txt)
self.software_license.stored_location = "GitHub"
self.software_license.save()
self.assertEqual("GitHub", self.software_license.stored_location_txt)
+67 -39
View File
@@ -2,19 +2,19 @@ from django.urls import path
from netbox.views.generic import ObjectChangeLogView from netbox.views.generic import ObjectChangeLogView
from netbox_slm import views from netbox_slm import views
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
urlpatterns = [ urlpatterns = [
# Software Products # SoftwareProduct
path("software-products/", views.SoftwareProductListView.as_view(), name='softwareproduct_list'), path("software-products/", views.SoftwareProductListView.as_view(), name="softwareproduct_list"),
path("software-products/add/", views.SoftwareProductEditView.as_view(), name='softwareproduct_add'), path("software-products/add/", views.SoftwareProductEditView.as_view(), name="softwareproduct_add"),
path("software-products/import/", views.SoftwareProductBulkImportView.as_view(), name="softwareproduct_import"), path(
path("software-products/edit/", views.SoftwareProductBulkEditView.as_view(), name="softwareproduct_bulk_edit"), "software-products/delete/", views.SoftwareProductBulkDeleteView.as_view(), name="softwareproduct_bulk_delete"
path("software-products/delete/", views.SoftwareProductBulkDeleteView.as_view(), ),
name="softwareproduct_bulk_delete"),
path("software-products/<int:pk>/", views.SoftwareProductView.as_view(), name="softwareproduct"), path("software-products/<int:pk>/", views.SoftwareProductView.as_view(), name="softwareproduct"),
path("software-products/<int:pk>/delete/", views.SoftwareProductDeleteView.as_view(), path(
name="softwareproduct_delete"), "software-products/<int:pk>/delete/", views.SoftwareProductDeleteView.as_view(), name="softwareproduct_delete"
),
path("software-products/<int:pk>/edit/", views.SoftwareProductEditView.as_view(), name="softwareproduct_edit"), path("software-products/<int:pk>/edit/", views.SoftwareProductEditView.as_view(), name="softwareproduct_edit"),
path( path(
"software-products/<int:pk>/changelog/", "software-products/<int:pk>/changelog/",
@@ -22,18 +22,20 @@ urlpatterns = [
name="softwareproduct_changelog", name="softwareproduct_changelog",
kwargs={"model": SoftwareProduct}, kwargs={"model": SoftwareProduct},
), ),
# SoftwareProductVersion
# Software Product Versions path("versions/", views.SoftwareProductVersionListView.as_view(), name="softwareproductversion_list"),
path("versions/", views.SoftwareProductVersionListView.as_view(), name='softwareproductversion_list'), path("versions/add/", views.SoftwareProductVersionEditView.as_view(), name="softwareproductversion_add"),
path("versions/add/", views.SoftwareProductVersionEditView.as_view(), name='softwareproductversion_add'), path(
path("versions/import/", views.SoftwareProductVersionBulkImportView.as_view(), "versions/delete/",
name="softwareproductversion_import"), views.SoftwareProductVersionBulkDeleteView.as_view(),
path("versions/edit/", views.SoftwareProductVersionBulkEditView.as_view(), name="softwareproductversion_bulk_edit"), name="softwareproductversion_bulk_delete",
path("versions/delete/", views.SoftwareProductVersionBulkDeleteView.as_view(), ),
name="softwareproductversion_bulk_delete"),
path("versions/<int:pk>/", views.SoftwareProductVersionView.as_view(), name="softwareproductversion"), path("versions/<int:pk>/", views.SoftwareProductVersionView.as_view(), name="softwareproductversion"),
path("versions/<int:pk>/delete/", views.SoftwareProductVersionDeleteView.as_view(), path(
name="softwareproductversion_delete"), "versions/<int:pk>/delete/",
views.SoftwareProductVersionDeleteView.as_view(),
name="softwareproductversion_delete",
),
path("versions/<int:pk>/edit/", views.SoftwareProductVersionEditView.as_view(), name="softwareproductversion_edit"), path("versions/<int:pk>/edit/", views.SoftwareProductVersionEditView.as_view(), name="softwareproductversion_edit"),
path( path(
"versions/<int:pk>/changelog/", "versions/<int:pk>/changelog/",
@@ -41,28 +43,54 @@ urlpatterns = [
name="softwareproductversion_changelog", name="softwareproductversion_changelog",
kwargs={"model": SoftwareProductVersion}, kwargs={"model": SoftwareProductVersion},
), ),
# SoftwareProductInstallation
# Software Product Versions path(
path("installations/", views.SoftwareProductInstallationListView.as_view(), "installations/",
name='softwareproductinstallation_list'), views.SoftwareProductInstallationListView.as_view(),
path("installations/add/", views.SoftwareProductInstallationEditView.as_view(), name="softwareproductinstallation_list",
name='softwareproductinstallation_add'), ),
path("installations/import/", views.SoftwareProductInstallationBulkImportView.as_view(), path(
name="softwareproductinstallation_import"), "installations/add/",
path("installations/edit/", views.SoftwareProductInstallationBulkEditView.as_view(), views.SoftwareProductInstallationEditView.as_view(),
name="softwareproductinstallation_bulk_edit"), name="softwareproductinstallation_add",
path("installations/delete/", views.SoftwareProductInstallationBulkDeleteView.as_view(), ),
name="softwareproductinstallation_bulk_delete"), path(
path("installations/<int:pk>/", views.SoftwareProductInstallationView.as_view(), "installations/delete/",
name="softwareproductinstallation"), views.SoftwareProductInstallationBulkDeleteView.as_view(),
path("installations/<int:pk>/delete/", views.SoftwareProductInstallationDeleteView.as_view(), name="softwareproductinstallation_bulk_delete",
name="softwareproductinstallation_delete"), ),
path("installations/<int:pk>/edit/", views.SoftwareProductInstallationEditView.as_view(), path(
name="softwareproductinstallation_edit"), "installations/<int:pk>/",
views.SoftwareProductInstallationView.as_view(),
name="softwareproductinstallation",
),
path(
"installations/<int:pk>/delete/",
views.SoftwareProductInstallationDeleteView.as_view(),
name="softwareproductinstallation_delete",
),
path(
"installations/<int:pk>/edit/",
views.SoftwareProductInstallationEditView.as_view(),
name="softwareproductinstallation_edit",
),
path( path(
"installations/<int:pk>/changelog/", "installations/<int:pk>/changelog/",
ObjectChangeLogView.as_view(), ObjectChangeLogView.as_view(),
name="softwareproductinstallation_changelog", name="softwareproductinstallation_changelog",
kwargs={"model": SoftwareProductInstallation}, kwargs={"model": SoftwareProductInstallation},
), ),
# SoftwareLicense
path("licenses/", views.SoftwareLicenseListView.as_view(), name="softwarelicense_list"),
path("licenses/add/", views.SoftwareLicenseEditView.as_view(), name="softwarelicense_add"),
path("licenses/delete/", views.SoftwareLicenseBulkDeleteView.as_view(), name="softwarelicense_bulk_delete"),
path("licenses/<int:pk>/", views.SoftwareLicenseView.as_view(), name="softwarelicense"),
path("licenses/<int:pk>/delete/", views.SoftwareLicenseDeleteView.as_view(), name="softwarelicense_delete"),
path("licenses/<int:pk>/edit/", views.SoftwareLicenseEditView.as_view(), name="softwarelicense_edit"),
path(
"licenses/<int:pk>/changelog/",
ObjectChangeLogView.as_view(),
name="softwarelicense_changelog",
kwargs={"model": SoftwareLicense},
),
] ]
-150
View File
@@ -1,150 +0,0 @@
from netbox.views import generic
from netbox_slm import filtersets, forms, tables
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation
class SoftwareProductListView(generic.ObjectListView):
"""View for listing all existing SoftwareProducts."""
queryset = SoftwareProduct.objects.all()
filterset = filtersets.SoftwareProductFilterSet
filterset_form = forms.SoftwareProductFilterForm
table = tables.SoftwareProductTable
class SoftwareProductView(generic.ObjectView):
"""Display SoftwareProduct details"""
queryset = SoftwareProduct.objects.all()
def get_extra_context(self, request, instance):
versions = instance.softwareproductversion_set.all()
return {"versions": versions}
class SoftwareProductEditView(generic.ObjectEditView):
"""View for editing and creating a SoftwareProduct instance."""
queryset = SoftwareProduct.objects.all()
form = forms.SoftwareProductForm
class SoftwareProductDeleteView(generic.ObjectDeleteView):
"""View for deleting a SoftwareProduct instance"""
queryset = SoftwareProduct.objects.all()
class SoftwareProductBulkImportView(generic.BulkImportView):
queryset = SoftwareProduct.objects.all()
model_form = forms.SoftwareProductCSVForm
table = tables.SoftwareProductTable
class SoftwareProductBulkEditView(generic.BulkEditView):
queryset = SoftwareProduct.objects.all()
filterset = filtersets.SoftwareProductFilterSet
filterset_form = forms.SoftwareProductFilterForm
table = tables.SoftwareProductTable
form = forms.SoftwareProductBulkEditForm
class SoftwareProductBulkDeleteView(generic.BulkDeleteView):
queryset = SoftwareProduct.objects.all()
table = tables.SoftwareProductTable
class SoftwareProductVersionListView(generic.ObjectListView):
"""View for listing all existing SoftwareProductVersions."""
queryset = SoftwareProductVersion.objects.all()
filterset = filtersets.SoftwareProductVersionFilterSet
filterset_form = forms.SoftwareProductVersionFilterForm
table = tables.SoftwareProductVersionTable
class SoftwareProductVersionView(generic.ObjectView):
"""Display SoftwareProductVersion details"""
queryset = SoftwareProductVersion.objects.all()
def get_extra_context(self, request, instance):
installation_count = instance.get_installation_count()
return {"installations": installation_count}
class SoftwareProductVersionEditView(generic.ObjectEditView):
"""View for editing and creating a SoftwareProductVersion instance."""
queryset = SoftwareProductVersion.objects.all()
form = forms.SoftwareProductVersionForm
class SoftwareProductVersionDeleteView(generic.ObjectDeleteView):
"""View for deleting a SoftwareProductVersion instance"""
queryset = SoftwareProductVersion.objects.all()
class SoftwareProductVersionBulkImportView(generic.BulkImportView):
queryset = SoftwareProductVersion.objects.all()
model_form = forms.SoftwareProductVersionCSVForm
table = tables.SoftwareProductVersionTable
class SoftwareProductVersionBulkEditView(generic.BulkEditView):
queryset = SoftwareProductVersion.objects.all()
filterset = filtersets.SoftwareProductVersionFilterSet
table = tables.SoftwareProductVersionTable
form = forms.SoftwareProductVersionBulkEditForm
class SoftwareProductVersionBulkDeleteView(generic.BulkDeleteView):
queryset = SoftwareProductVersion.objects.all()
table = tables.SoftwareProductVersionTable
class SoftwareProductInstallationListView(generic.ObjectListView):
"""View for listing all existing SoftwareProductInstallations."""
queryset = SoftwareProductInstallation.objects.all()
filterset = filtersets.SoftwareProductInstallationFilterSet
filterset_form = forms.SoftwareProductInstallationFilterForm
table = tables.SoftwareProductInstallationTable
class SoftwareProductInstallationView(generic.ObjectView):
"""Display SoftwareProductInstallation details"""
queryset = SoftwareProductInstallation.objects.all()
class SoftwareProductInstallationEditView(generic.ObjectEditView):
"""View for editing and creating a SoftwareProductInstallation instance."""
queryset = SoftwareProductInstallation.objects.all()
form = forms.SoftwareProductInstallationForm
class SoftwareProductInstallationDeleteView(generic.ObjectDeleteView):
"""View for deleting a SoftwareProductInstallation instance"""
queryset = SoftwareProductInstallation.objects.all()
class SoftwareProductInstallationBulkImportView(generic.BulkImportView):
queryset = SoftwareProductInstallation.objects.all()
model_form = forms.SoftwareProductInstallationCSVForm
table = tables.SoftwareProductInstallationTable
class SoftwareProductInstallationBulkEditView(generic.BulkEditView):
queryset = SoftwareProductInstallation.objects.all()
filterset = filtersets.SoftwareProductInstallationFilterSet
table = tables.SoftwareProductInstallationTable
form = forms.SoftwareProductInstallationBulkEditForm
class SoftwareProductInstallationBulkDeleteView(generic.BulkDeleteView):
queryset = SoftwareProductInstallation.objects.all()
table = tables.SoftwareProductInstallationTable
+28
View File
@@ -0,0 +1,28 @@
from .software_license import (
SoftwareLicenseListView,
SoftwareLicenseView,
SoftwareLicenseEditView,
SoftwareLicenseDeleteView,
SoftwareLicenseBulkDeleteView,
)
from .software_product import (
SoftwareProductListView,
SoftwareProductView,
SoftwareProductEditView,
SoftwareProductDeleteView,
SoftwareProductBulkDeleteView,
)
from .software_product_installation import (
SoftwareProductInstallationListView,
SoftwareProductInstallationView,
SoftwareProductInstallationEditView,
SoftwareProductInstallationDeleteView,
SoftwareProductInstallationBulkDeleteView,
)
from .software_product_version import (
SoftwareProductVersionListView,
SoftwareProductVersionView,
SoftwareProductVersionEditView,
SoftwareProductVersionDeleteView,
SoftwareProductVersionBulkDeleteView,
)
+36
View File
@@ -0,0 +1,36 @@
from netbox.views import generic
from netbox_slm import filtersets, forms, tables
from netbox_slm.models import SoftwareLicense
class SoftwareLicenseListView(generic.ObjectListView):
"""View for listing all existing SoftwareLicenses."""
queryset = SoftwareLicense.objects.all()
filterset = filtersets.SoftwareLicenseFilterSet
filterset_form = forms.SoftwareLicenseFilterForm
table = tables.SoftwareLicenseTable
class SoftwareLicenseView(generic.ObjectView):
"""Display SoftwareLicense details"""
queryset = SoftwareLicense.objects.all()
class SoftwareLicenseEditView(generic.ObjectEditView):
"""View for editing and creating a SoftwareLicense instance."""
queryset = SoftwareLicense.objects.all()
form = forms.SoftwareLicenseForm
class SoftwareLicenseDeleteView(generic.ObjectDeleteView):
"""View for deleting a SoftwareLicense instance"""
queryset = SoftwareLicense.objects.all()
class SoftwareLicenseBulkDeleteView(generic.BulkDeleteView):
queryset = SoftwareLicense.objects.all()
table = tables.SoftwareLicenseTable
+40
View File
@@ -0,0 +1,40 @@
from netbox.views import generic
from netbox_slm import filtersets, forms, tables
from netbox_slm.models import SoftwareProduct
class SoftwareProductListView(generic.ObjectListView):
"""View for listing all existing SoftwareProducts."""
queryset = SoftwareProduct.objects.all()
filterset = filtersets.SoftwareProductFilterSet
filterset_form = forms.SoftwareProductFilterForm
table = tables.SoftwareProductTable
class SoftwareProductView(generic.ObjectView):
"""Display SoftwareProduct details"""
queryset = SoftwareProduct.objects.all()
def get_extra_context(self, request, instance):
versions = instance.softwareproductversion_set.all()
return {"versions": versions}
class SoftwareProductEditView(generic.ObjectEditView):
"""View for editing and creating a SoftwareProduct instance."""
queryset = SoftwareProduct.objects.all()
form = forms.SoftwareProductForm
class SoftwareProductDeleteView(generic.ObjectDeleteView):
"""View for deleting a SoftwareProduct instance"""
queryset = SoftwareProduct.objects.all()
class SoftwareProductBulkDeleteView(generic.BulkDeleteView):
queryset = SoftwareProduct.objects.all()
table = tables.SoftwareProductTable
@@ -0,0 +1,36 @@
from netbox.views import generic
from netbox_slm import filtersets, forms, tables
from netbox_slm.models import SoftwareProductInstallation
class SoftwareProductInstallationListView(generic.ObjectListView):
"""View for listing all existing SoftwareProductInstallations."""
queryset = SoftwareProductInstallation.objects.all()
filterset = filtersets.SoftwareProductInstallationFilterSet
filterset_form = forms.SoftwareProductInstallationFilterForm
table = tables.SoftwareProductInstallationTable
class SoftwareProductInstallationView(generic.ObjectView):
"""Display SoftwareProductInstallation details"""
queryset = SoftwareProductInstallation.objects.all()
class SoftwareProductInstallationEditView(generic.ObjectEditView):
"""View for editing and creating a SoftwareProductInstallation instance."""
queryset = SoftwareProductInstallation.objects.all()
form = forms.SoftwareProductInstallationForm
class SoftwareProductInstallationDeleteView(generic.ObjectDeleteView):
"""View for deleting a SoftwareProductInstallation instance"""
queryset = SoftwareProductInstallation.objects.all()
class SoftwareProductInstallationBulkDeleteView(generic.BulkDeleteView):
queryset = SoftwareProductInstallation.objects.all()
table = tables.SoftwareProductInstallationTable
@@ -0,0 +1,40 @@
from netbox.views import generic
from netbox_slm import filtersets, forms, tables
from netbox_slm.models import SoftwareProductVersion
class SoftwareProductVersionListView(generic.ObjectListView):
"""View for listing all existing SoftwareProductVersions."""
queryset = SoftwareProductVersion.objects.all()
filterset = filtersets.SoftwareProductVersionFilterSet
filterset_form = forms.SoftwareProductVersionFilterForm
table = tables.SoftwareProductVersionTable
class SoftwareProductVersionView(generic.ObjectView):
"""Display SoftwareProductVersion details"""
queryset = SoftwareProductVersion.objects.all()
def get_extra_context(self, request, instance):
installation_count = instance.get_installation_count()
return {"installations": installation_count}
class SoftwareProductVersionEditView(generic.ObjectEditView):
"""View for editing and creating a SoftwareProductVersion instance."""
queryset = SoftwareProductVersion.objects.all()
form = forms.SoftwareProductVersionForm
class SoftwareProductVersionDeleteView(generic.ObjectDeleteView):
"""View for deleting a SoftwareProductVersion instance"""
queryset = SoftwareProductVersion.objects.all()
class SoftwareProductVersionBulkDeleteView(generic.BulkDeleteView):
queryset = SoftwareProductVersion.objects.all()
table = tables.SoftwareProductVersionTable
+62
View File
@@ -0,0 +1,62 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
[project]
name = "netbox-slm"
dynamic = ["version"]
description = "Software Lifecycle Management Netbox Plugin"
readme = "README.md"
requires-python = ">=3.11"
license = { text = "Apache-2.0" }
authors = [
{name = "ICTU", email = "open-source-projects@ictu.nl"},
]
classifiers = [
"Environment :: Web Environment",
"Framework :: Django",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: Dynamic Content",
]
dependencies = []
[project.optional-dependencies]
build = [
"build == 1.2.1",
"setuptools == 70.3.0",
"twine == 5.1.1",
]
tools = [
"ruff == 0.5.1",
]
[tool.setuptools.dynamic]
version = {attr = "netbox_slm.__version__"}
[tool.setuptools.packages.find]
include = ["netbox_slm"]
[tool.ruff]
line-length = 120
target-version = "py311"
src = ["netbox_slm"]
[tool.ruff.lint.per-file-ignores]
"__init__.py" = [
"D104", # https://beta.ruff.rs/docs/rules/#pydocstyle-d - don't require doc strings in __init__.py files
"F401", # https://beta.ruff.rs/docs/rules/#pyflakes-f - don't complain about unused imports in __init__.py files
]
"netbox_slm/migrations/*.py" = [
"E501", # https://beta.ruff.rs/docs/rules/line-too-long/ - don't check on Django generated migration files
]
[tool.ruff.format]
exclude = ["netbox_slm/migrations/*.py"]
-26
View File
@@ -1,26 +0,0 @@
[metadata]
name = netbox-slm
version = 1.3
description = Software Lifecycle Management Netbox Plugin.
author = ICTU
author_email = open-source-projects@ictu.nl
license = Apache 2.0
classifiers =
Environment :: Web Environment
Framework :: Django
Intended Audience :: Developers
License :: OSI Approved :: Apache Software License
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Topic :: Internet :: WWW/HTTP
Topic :: Internet :: WWW/HTTP :: Dynamic Content
[options]
include_package_data = true
packages = find:
python_requires = >=3.9
-3
View File
@@ -1,3 +0,0 @@
from setuptools import setup
setup()
+2 -2
View File
@@ -2,11 +2,11 @@
sonar.organization=ictu sonar.organization=ictu
sonar.projectKey=ICTU_netbox_slm sonar.projectKey=ICTU_netbox_slm
sonar.projectName=netbox-slm sonar.projectName=netbox-slm
sonar.projectVersion=1.3 sonar.projectVersion=1.4
# Path is relative to the sonar-project.properties file # Path is relative to the sonar-project.properties file
sonar.sources=netbox_slm sonar.sources=netbox_slm
sonar.python.version=3.9 sonar.python.version=3.9, 3.10, 3.11
# Unit tests # Unit tests
sonar.python.xunit.reportPath=ci/reports/junit.xml sonar.python.xunit.reportPath=ci/reports/junit.xml