Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #97: Introduce the exempt_models config parameter #109

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Configuration Parameters

## `exempt_models`

Default: `[]` (empty list)

A list of models provided by other plugins which should be exempt from branching support. (Only models which support change logging need be listed; all other models are ineligible for branching support.)

Models must be specified by app label and model name, as such:

```python
exempt_models = (
'my_plugin.foo',
'my_plugin.bar',
)
```

It is also possible to exclude _all_ models from within a plugin by substituting an asterisk (`*`) for the model name:

```python
exempt_models = (
'my_plugin.*',
)
```

---

## `max_working_branches`

Default: None
Expand Down
24 changes: 18 additions & 6 deletions netbox_branching/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from netbox.plugins import PluginConfig
from netbox.plugins import PluginConfig, get_plugin_config
from netbox.registry import registry


Expand All @@ -22,6 +22,9 @@ class AppConfig(PluginConfig):
# The maximum number of branches which can be provisioned simultaneously
'max_branches': None,

# Models from other plugins which should be excluded from branching support
'exempt_models': [],

# This string is prefixed to the name of each new branch schema during provisioning
'schema_prefix': 'branch_',
}
Expand All @@ -42,11 +45,20 @@ def ready(self):
)

# Record all object types which support branching in the NetBox registry
if 'branching' not in registry['model_features']:
registry['model_features']['branching'] = {
k: v for k, v in registry['model_features']['change_logging'].items()
if k not in constants.EXCLUDED_APPS
}
exempt_models = (
*constants.EXEMPT_MODELS,
*get_plugin_config('netbox_branching', 'exempt_models'),
)
branching_models = {}
for app_label, models in registry['model_features']['change_logging'].items():
# Wildcard exclusion for all models in this app
if f'{app_label}.*' in exempt_models:
continue
branching_models[app_label] = [
model for model in models
if f'{app_label}.{model}' not in exempt_models
]
registry['model_features']['branching'] = branching_models


config = AppConfig
8 changes: 4 additions & 4 deletions netbox_branching/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# URL query parameter name
QUERY_PARAM = '_branch'

# Apps which are explicitly excluded from branching
EXCLUDED_APPS = (
'netbox_branching',
'netbox_changes',
# Models for which branching support is explicitly disabled
EXEMPT_MODELS = (
'netbox_branching.*',
'netbox_changes.*',
)