File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change 1+ # Configuration Parameters
2+
3+ ## ` max_cots `
4+
5+ Default: None
6+
7+ The maximum number of Custom Object Types that may be created.
Original file line number Diff line number Diff line change 4141 TagsMixin ,
4242 get_model_features ,
4343)
44+ from netbox .plugins import get_plugin_config
4445from netbox .registry import registry
4546from netbox .search import SearchIndex
4647from 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 """
You can’t perform that action at this time.
0 commit comments