Skip to content

Commit

Permalink
Assorted fixes (#25)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
wkoot and mhartung1 authored Sep 14, 2023
1 parent 6c512e0 commit 92a0a79
Show file tree
Hide file tree
Showing 59 changed files with 2,238 additions and 568 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.9"

- name: Install tools
run: pip install .[tools]

- name: Run ruff
run: ruff netbox_slm

- name: Run black
run: black netbox_slm
12 changes: 0 additions & 12 deletions Pipfile

This file was deleted.

192 changes: 0 additions & 192 deletions Pipfile.lock

This file was deleted.

11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Next, follow these instructions (based on the Netbox docker variant
to install the Netbox SLM plugin:

1. Add ``netbox_slm`` to the ``PLUGINS`` list in
``configuration/extra.py``.
2. Create a ``plugin_requirements.txt`` with ``netbox-slm==1.2`` as
``configuration/plugins.py``.
2. Create a ``plugin_requirements.txt`` with ``netbox-slm`` as
contents.
3. Create a ``Dockerfile-SLM`` with contents:

Expand Down Expand Up @@ -65,20 +65,17 @@ And finally, run Netbox with the SLM plugin: ``docker compose up``

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

```
# make sure to update the version in netbox_slm/__init__.py
$ python setup.py sdist
$ python -m build
$ twine upload dist/*
```

On Github.com create a similar tag and version. These steps could be
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)

Expand Down
20 changes: 20 additions & 0 deletions build/lib/netbox_slm/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from extras.plugins import PluginConfig

__version__ = "1.4"


class SLMConfig(PluginConfig):
name = 'netbox_slm'
verbose_name = 'Software Lifecycle Management'
description = 'Software Lifecycle Management Netbox Plugin.'
version = __version__
author = 'ICTU'
author_email = '[email protected]'
base_url = 'slm'
required_settings = []
default_settings = {
'version_info': False
}


config = SLMConfig
7 changes: 7 additions & 0 deletions build/lib/netbox_slm/admin.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file.
73 changes: 73 additions & 0 deletions build/lib/netbox_slm/api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from rest_framework import serializers

from netbox.api.serializers import NetBoxModelSerializer
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense


class SoftwareProductSerializer(NetBoxModelSerializer):
display = serializers.SerializerMethodField()
url = serializers.HyperlinkedIdentityField(
view_name="plugins-api:netbox_slm-api:softwareproduct-detail"
)

class Meta:
model = SoftwareProduct
fields = [
'id', 'display', 'url', 'name',
'tags', 'custom_field_data', 'created', 'last_updated',
]

def get_display(self, 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):
display = serializers.SerializerMethodField()
url = serializers.HyperlinkedIdentityField(
view_name="plugins-api:netbox_slm-api:softwareproductinstallation-detail"
)

class Meta:
model = SoftwareProductInstallation
fields = [
'id', 'display', 'url', 'device', 'virtualmachine', 'software_product', 'version',
'tags', 'custom_field_data', 'created', 'last_updated',
]

def get_display(self, obj):
return f"{obj}"


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',
'start_date', 'expiration_date', 'software_product', 'version', 'installation',
'tags', 'custom_field_data', 'created', 'last_updated',
]

def get_display(self, obj):
return f"{obj}"
17 changes: 17 additions & 0 deletions build/lib/netbox_slm/api/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from netbox.api.routers import NetBoxRouter
from netbox_slm.api.views import (
NetboxSLMRootView,
SoftwareProductViewSet,
SoftwareProductVersionViewSet,
SoftwareProductInstallationViewSet,
SoftwareLicenseViewSet,
)

router = NetBoxRouter()
router.APIRootView = NetboxSLMRootView

router.register("softwareproducts", SoftwareProductViewSet)
router.register("softwareproductversions", SoftwareProductVersionViewSet)
router.register("softwareproductinstallations", SoftwareProductInstallationViewSet)
router.register("softwarelicenses", SoftwareLicenseViewSet)
urlpatterns = router.urls
Loading

0 comments on commit 92a0a79

Please sign in to comment.