Coverage for netbox/plugins/utils.py: 46%
20 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-10 18:35 +0000
1from django.apps import apps
2from django.conf import settings
3from django.core.exceptions import ImproperlyConfigured
5from netbox.registry import registry
7__all__ = (
8 'get_installed_plugins',
9 'get_plugin_config',
10)
13def get_installed_plugins():
14 """
15 Return a dictionary mapping the names of installed plugins to their versions.
16 """
17 plugins = {}
18 for plugin_name in registry['plugins']['installed']: 18 ↛ 19line 18 didn't jump to line 19 because the loop on line 18 never started
19 plugin_name = plugin_name.rsplit('.', 1)[-1]
20 plugin_config = apps.get_app_config(plugin_name)
21 if plugin_config.release_track:
22 plugins[plugin_name] = f'{plugin_config.version}-{plugin_config.release_track}'
23 else:
24 plugins[plugin_name] = plugin_config.version or None
26 return dict(sorted(plugins.items()))
29def get_plugin_config(plugin_name, parameter, default=None):
30 """
31 Return the value of the specified plugin configuration parameter.
33 Args:
34 plugin_name: The name of the plugin
35 parameter: The name of the configuration parameter
36 default: The value to return if the parameter is not defined (default: None)
37 """
38 try:
39 plugin_config = settings.PLUGINS_CONFIG[plugin_name]
40 return plugin_config.get(parameter, default)
41 except KeyError:
42 raise ImproperlyConfigured(f"Plugin {plugin_name} is not registered.")