Skip to content

Commit fddd431

Browse files
committed
Add handling for max_cots config option (and configuration.md)
1 parent 358dc93 commit fddd431

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

docs/configuration.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Configuration Parameters
2+
3+
## `max_cots`
4+
5+
Default: None
6+
7+
The maximum number of Custom Object Types that may be created.

netbox_custom_objects/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
TagsMixin,
4242
get_model_features,
4343
)
44+
from netbox.plugins import get_plugin_config
4445
from netbox.registry import registry
4546
from netbox.search import SearchIndex
4647
from utilities import filters
@@ -198,6 +199,7 @@ class CustomObjectType(PrimaryModel):
198199
blank=True,
199200
editable=False
200201
)
202+
201203
class Meta:
202204
verbose_name = "Custom Object Type"
203205
ordering = ("name",)
@@ -214,6 +216,15 @@ class Meta:
214216
def __str__(self):
215217
return self.display_name
216218

219+
def clean(self):
220+
super().clean()
221+
222+
# Enforce max number of COTs that may be created (max_cots)
223+
if not self.pk:
224+
max_cots = get_plugin_config("netbox_custom_objects", "max_cots")
225+
if max_cots and CustomObjectType.objects.count() > max_cots:
226+
raise ValidationError(_(f"Maximum number of Custom Object Types ({max_cots}) exceeded"))
227+
217228
@classmethod
218229
def clear_model_cache(cls, custom_object_type_id=None):
219230
"""

0 commit comments

Comments
 (0)