* 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>
182 lines
5.7 KiB
Python
182 lines
5.7 KiB
Python
import django_tables2 as tables
|
|
from django.db.models import Count
|
|
from django_tables2.utils import Accessor
|
|
|
|
from netbox.tables import NetBoxTable, ToggleColumn, columns
|
|
from netbox_slm.models import SoftwareProduct, SoftwareProductVersion, SoftwareProductInstallation, SoftwareLicense
|
|
|
|
|
|
class SoftwareProductTable(NetBoxTable):
|
|
"""Table for displaying SoftwareProduct objects."""
|
|
|
|
pk = ToggleColumn()
|
|
name = tables.LinkColumn()
|
|
manufacturer = tables.Column(accessor=Accessor("manufacturer"), linkify=True)
|
|
installations = tables.Column(accessor="get_installation_count", verbose_name="Installations")
|
|
|
|
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproduct_list")
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = SoftwareProduct
|
|
fields = (
|
|
"pk",
|
|
"name",
|
|
"manufacturer",
|
|
"description",
|
|
"installations",
|
|
"tags",
|
|
)
|
|
default_columns = (
|
|
"pk",
|
|
"name",
|
|
"manufacturer",
|
|
"description",
|
|
"installations",
|
|
"tags",
|
|
)
|
|
sequence = (
|
|
"manufacturer",
|
|
"name",
|
|
"description",
|
|
"installations",
|
|
)
|
|
|
|
def order_installations(self, queryset, is_descending):
|
|
queryset = queryset.annotate(count=Count("softwareproductinstallation__id")).order_by(
|
|
("-" if is_descending else "") + "count"
|
|
)
|
|
return queryset, True
|
|
|
|
|
|
class SoftwareProductVersionTable(NetBoxTable):
|
|
"""Table for displaying SoftwareProductVersion objects."""
|
|
|
|
pk = ToggleColumn()
|
|
name = tables.LinkColumn(verbose_name="Version")
|
|
software_product = tables.Column(accessor=Accessor("software_product"), linkify=True)
|
|
manufacturer = tables.Column(accessor=Accessor("software_product__manufacturer"), linkify=True)
|
|
installations = tables.Column(accessor="get_installation_count", verbose_name="Installations")
|
|
|
|
tags = columns.TagColumn(url_name="plugins:netbox_slm:softwareproductversion_list")
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = SoftwareProductVersion
|
|
fields = (
|
|
"pk",
|
|
"name",
|
|
"software_product",
|
|
"manufacturer",
|
|
"installations",
|
|
"tags",
|
|
)
|
|
default_columns = (
|
|
"pk",
|
|
"name",
|
|
"software_product",
|
|
"manufacturer",
|
|
"installations",
|
|
"tags",
|
|
)
|
|
sequence = (
|
|
"manufacturer",
|
|
"software_product",
|
|
"name",
|
|
"installations",
|
|
)
|
|
|
|
def order_installations(self, queryset, is_descending):
|
|
queryset = queryset.annotate(count=Count("softwareproductinstallation__id")).order_by(
|
|
("-" if is_descending else "") + "count"
|
|
)
|
|
return queryset, True
|
|
|
|
|
|
class SoftwareProductInstallationTable(NetBoxTable):
|
|
"""Table for displaying SoftwareProductInstallation objects."""
|
|
|
|
pk = ToggleColumn()
|
|
name = tables.LinkColumn()
|
|
device = tables.Column(accessor=Accessor("device"), linkify=True)
|
|
virtualmachine = tables.Column(accessor=Accessor("virtualmachine"), linkify=True)
|
|
platform = tables.Column(accessor=Accessor("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(url_name="plugins:netbox_slm:softwareproductinstallation_list")
|
|
|
|
class Meta(NetBoxTable.Meta):
|
|
model = SoftwareProductInstallation
|
|
fields = (
|
|
"pk",
|
|
"name",
|
|
"platform",
|
|
"type",
|
|
"software_product",
|
|
"version",
|
|
"tags",
|
|
)
|
|
default_columns = (
|
|
"pk",
|
|
"platform",
|
|
"type",
|
|
"software_product",
|
|
"version",
|
|
"tags",
|
|
)
|
|
|
|
def order_platform(self, queryset, is_descending):
|
|
queryset = queryset.order_by(("device" if is_descending else "virtualmachine"))
|
|
return queryset, True
|
|
|
|
def order_type(self, queryset, is_descending):
|
|
queryset = queryset.order_by(("device" if is_descending else "virtualmachine"))
|
|
return queryset, True
|
|
|
|
def render_software_product(self, value, **kwargs):
|
|
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(accessor="render_type")
|
|
software_product = tables.Column(accessor=Accessor("software_product"), linkify=True)
|
|
version = tables.Column(accessor=Accessor("version"), linkify=True)
|
|
installation = tables.Column(accessor=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",
|
|
"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}"
|