Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Configuration Parameters

## `max_custom_object_types`

Default: 50

The maximum number of Custom Object Types that may be created.
5 changes: 4 additions & 1 deletion netbox_custom_objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ class CustomObjectsPluginConfig(PluginConfig):
author_email = 'support@netboxlabs.com'
base_url = "custom-objects"
min_version = "4.4.0"
default_settings = {}
default_settings = {
# The maximum number of Custom Object Types that may be created
'max_custom_object_types': 50,
}
required_settings = []
template_extensions = "template_content.template_extensions"

Expand Down
14 changes: 14 additions & 0 deletions netbox_custom_objects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
TagsMixin,
get_model_features,
)
from netbox.plugins import get_plugin_config
from netbox.registry import registry
from netbox.search import SearchIndex
from utilities import filters
Expand Down Expand Up @@ -198,6 +199,7 @@ class CustomObjectType(PrimaryModel):
blank=True,
editable=False
)

class Meta:
verbose_name = "Custom Object Type"
ordering = ("name",)
Expand All @@ -214,6 +216,18 @@ class Meta:
def __str__(self):
return self.display_name

def clean(self):
super().clean()

# Enforce max number of COTs that may be created (max_custom_object_types)
if not self.pk:
max_cots = get_plugin_config("netbox_custom_objects", "max_custom_object_types")
if max_cots and CustomObjectType.objects.count() > max_cots:
raise ValidationError(_(
f"Maximum number of Custom Object Types ({max_cots}) "
"exceeded; adjust max_custom_object_types to raise this limit"
))

@classmethod
def clear_model_cache(cls, custom_object_type_id=None):
"""
Expand Down