New page "Client Software Übersicht" in a "Software" group of the netbox-inventory menu (fallback: own Hardware menu). It shows, per tenant or tenant group including subgroups, the software products recorded with netbox-slm, their versions and the clients they are installed on: key figures, charts of the most widespread products and their version distribution, a sortable and searchable product list, a drill-down per product/version with the list of clients, and a CSV export. Without an own selection the global tenant filter applies; the device role filter is pre-set to the configured client roles. Devices with a client role (software_device_roles, default "Clients") get a "Software" tab listing their installations with add, edit and delete actions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
from django.core.cache import cache
|
|
from django.db import OperationalError, ProgrammingError, transaction
|
|
from netbox.plugins import get_plugin_config
|
|
|
|
from .models import UtilitiesSettings
|
|
|
|
SETTINGS_CACHE_KEY = "netbox_utilities.runtime_settings.v2"
|
|
|
|
|
|
def navigation_customization_enabled():
|
|
return bool(get_plugin_config("netbox_utilities", "navigation_customization_enabled"))
|
|
|
|
|
|
def connection_vlans_enabled():
|
|
return bool(get_plugin_config("netbox_utilities", "connection_vlans_enabled"))
|
|
|
|
|
|
def hardware_enabled():
|
|
return bool(get_plugin_config("netbox_utilities", "hardware_enabled"))
|
|
|
|
|
|
def software_enabled():
|
|
from django.apps import apps
|
|
|
|
return bool(get_plugin_config("netbox_utilities", "software_enabled")) and apps.is_installed("netbox_slm")
|
|
|
|
|
|
def switch_ports_enabled():
|
|
return bool(get_plugin_config("netbox_utilities", "switch_ports_enabled"))
|
|
|
|
|
|
def offline_svg_export_enabled():
|
|
return bool(get_plugin_config("netbox_utilities", "offline_svg_export_enabled"))
|
|
|
|
|
|
def tenant_filter_enabled():
|
|
if not get_plugin_config("netbox_utilities", "tenant_filter_enabled"):
|
|
return False
|
|
|
|
return bool(_get_database_settings()["tenant_filter_enabled"])
|
|
|
|
|
|
def tenant_required():
|
|
if not get_plugin_config("netbox_utilities", "tenant_required"):
|
|
return False
|
|
|
|
return bool(_get_database_settings()["tenant_required"])
|
|
|
|
|
|
def _get_database_settings():
|
|
runtime_settings = cache.get(SETTINGS_CACHE_KEY)
|
|
if runtime_settings is None:
|
|
try:
|
|
# The savepoint keeps an outer transaction (e.g. a running migration)
|
|
# usable on PostgreSQL if the settings table does not exist yet.
|
|
with transaction.atomic():
|
|
runtime_settings = (
|
|
UtilitiesSettings.objects.filter(singleton_id=1)
|
|
.values("tenant_filter_enabled", "tenant_required")
|
|
.first()
|
|
)
|
|
except (OperationalError, ProgrammingError):
|
|
# The middleware can be imported before the first plugin migration.
|
|
runtime_settings = None
|
|
runtime_settings = runtime_settings or {
|
|
"tenant_filter_enabled": True,
|
|
"tenant_required": True,
|
|
}
|
|
cache.set(SETTINGS_CACHE_KEY, runtime_settings, timeout=30)
|
|
return runtime_settings
|
|
|
|
|
|
def clear_runtime_settings_cache():
|
|
cache.delete(SETTINGS_CACHE_KEY)
|