File tree Expand file tree Collapse file tree 3 files changed +25
-1
lines changed
Expand file tree Collapse file tree 3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 1+ # Configuration Parameters
2+
3+ ## ` max_custom_object_types `
4+
5+ Default: 50
6+
7+ The maximum number of Custom Object Types that may be created.
Original file line number Diff line number Diff line change @@ -53,7 +53,10 @@ class CustomObjectsPluginConfig(PluginConfig):
5353 author_email = 'support@netboxlabs.com'
5454 base_url = "custom-objects"
5555 min_version = "4.4.0"
56- default_settings = {}
56+ default_settings = {
57+ # The maximum number of Custom Object Types that may be created
58+ 'max_custom_object_types' : 50 ,
59+ }
5760 required_settings = []
5861 template_extensions = "template_content.template_extensions"
5962
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
@@ -207,6 +208,7 @@ class CustomObjectType(NetBoxModel):
207208 blank = True ,
208209 editable = False
209210 )
211+
210212 class Meta :
211213 verbose_name = "Custom Object Type"
212214 ordering = ("name" ,)
@@ -223,6 +225,18 @@ class Meta:
223225 def __str__ (self ):
224226 return self .display_name
225227
228+ def clean (self ):
229+ super ().clean ()
230+
231+ # Enforce max number of COTs that may be created (max_custom_object_types)
232+ if not self .pk :
233+ max_cots = get_plugin_config ("netbox_custom_objects" , "max_custom_object_types" )
234+ if max_cots and CustomObjectType .objects .count () > max_cots :
235+ raise ValidationError (_ (
236+ f"Maximum number of Custom Object Types ({ max_cots } ) "
237+ "exceeded; adjust max_custom_object_types to raise this limit"
238+ ))
239+
226240 @classmethod
227241 def clear_model_cache (cls , custom_object_type_id = None ):
228242 """
You can’t perform that action at this time.
0 commit comments