7
7
# from django.urls import reverse
8
8
from django .core .exceptions import ValidationError
9
9
from django .db import models
10
+
11
+ try :
12
+ from nautobot .apps .constants import CHARFIELD_MAX_LENGTH
13
+ except ImportError :
14
+ CHARFIELD_MAX_LENGTH = 255
15
+
10
16
from nautobot .core .models .generics import OrganizationalModel , PrimaryModel
11
17
from nautobot .core .models .querysets import RestrictedQuerySet
12
18
from nautobot .dcim .models import Device , DeviceType , InventoryItem
@@ -45,7 +51,7 @@ class HardwareLCM(PrimaryModel):
45
51
null = True ,
46
52
)
47
53
inventory_item = models .CharField ( # pylint: disable=nb-string-field-blank-null
48
- verbose_name = "Inventory Item Part" , max_length = 255 , blank = True , null = True
54
+ verbose_name = "Inventory Item Part" , max_length = CHARFIELD_MAX_LENGTH , blank = True , null = True
49
55
)
50
56
release_date = models .DateField (null = True , blank = True , verbose_name = "Release Date" )
51
57
end_of_sale = models .DateField (null = True , blank = True , verbose_name = "End of Sale" )
@@ -157,8 +163,8 @@ class SoftwareLCM(PrimaryModel):
157
163
"""Software Life-Cycle Management model."""
158
164
159
165
device_platform = models .ForeignKey (to = "dcim.Platform" , on_delete = models .CASCADE , verbose_name = "Device Platform" )
160
- version = models .CharField (max_length = 50 )
161
- alias = models .CharField (max_length = 50 , blank = True , default = "" )
166
+ version = models .CharField (max_length = CHARFIELD_MAX_LENGTH )
167
+ alias = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True , default = "" )
162
168
release_date = models .DateField (null = True , blank = True , verbose_name = "Release Date" )
163
169
end_of_support = models .DateField (null = True , blank = True , verbose_name = "End of Software Support" )
164
170
documentation_url = models .URLField (blank = True , verbose_name = "Documentation URL" )
@@ -212,7 +218,7 @@ def get_for_object(self, obj):
212
218
class SoftwareImageLCM (PrimaryModel ):
213
219
"""SoftwareImageLCM model."""
214
220
215
- image_file_name = models .CharField (blank = False , max_length = 100 , verbose_name = "Image File Name" )
221
+ image_file_name = models .CharField (blank = False , max_length = CHARFIELD_MAX_LENGTH , verbose_name = "Image File Name" )
216
222
software = models .ForeignKey (
217
223
to = "SoftwareLCM" , on_delete = models .CASCADE , related_name = "software_images" , verbose_name = "Software Version"
218
224
)
@@ -221,7 +227,9 @@ class SoftwareImageLCM(PrimaryModel):
221
227
object_tags = models .ManyToManyField (to = "extras.Tag" , related_name = "+" , blank = True )
222
228
download_url = models .URLField (blank = True , verbose_name = "Download URL" )
223
229
image_file_checksum = models .CharField (blank = True , max_length = 256 , verbose_name = "Image File Checksum" )
224
- hashing_algorithm = models .CharField (default = "" , blank = True , max_length = 32 , verbose_name = "Hashing Algorithm" )
230
+ hashing_algorithm = models .CharField (
231
+ default = "" , blank = True , max_length = CHARFIELD_MAX_LENGTH , verbose_name = "Hashing Algorithm"
232
+ )
225
233
default_image = models .BooleanField (verbose_name = "Default Image" , default = False )
226
234
227
235
class Meta :
@@ -341,7 +349,7 @@ class DeviceSoftwareValidationResult(PrimaryModel):
341
349
)
342
350
is_validated = models .BooleanField (null = True , blank = True )
343
351
last_run = models .DateTimeField (null = True , blank = True )
344
- run_type = models .CharField (max_length = 50 , choices = choices .ReportRunTypeChoices )
352
+ run_type = models .CharField (max_length = CHARFIELD_MAX_LENGTH , choices = choices .ReportRunTypeChoices )
345
353
valid_software = models .ManyToManyField (
346
354
to = "ValidatedSoftwareLCM" , related_name = "device_software_validation_results"
347
355
)
@@ -378,7 +386,7 @@ class InventoryItemSoftwareValidationResult(PrimaryModel):
378
386
)
379
387
is_validated = models .BooleanField (null = True , blank = True )
380
388
last_run = models .DateTimeField (null = True , blank = True )
381
- run_type = models .CharField (max_length = 50 , choices = choices .ReportRunTypeChoices )
389
+ run_type = models .CharField (max_length = CHARFIELD_MAX_LENGTH , choices = choices .ReportRunTypeChoices )
382
390
valid_software = models .ManyToManyField (
383
391
to = "ValidatedSoftwareLCM" , related_name = "inventory_item_software_validation_results"
384
392
)
@@ -421,14 +429,18 @@ class ContractLCM(PrimaryModel):
421
429
blank = True ,
422
430
null = True ,
423
431
)
424
- name = models .CharField (max_length = 100 , unique = True )
425
- number = models .CharField (max_length = 100 , blank = True , default = "" )
432
+ name = models .CharField (max_length = CHARFIELD_MAX_LENGTH , unique = True )
433
+ number = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True , default = "" )
426
434
start = models .DateField (null = True , blank = True , verbose_name = "Contract Start Date" )
427
435
end = models .DateField (null = True , blank = True , verbose_name = "Contract End Date" )
428
436
cost = models .DecimalField (null = True , blank = True , decimal_places = 2 , max_digits = 15 , verbose_name = "Contract Cost" )
429
- support_level = models .CharField (verbose_name = "Support Level" , max_length = 64 , blank = True , default = "" )
437
+ support_level = models .CharField (
438
+ verbose_name = "Support Level" , max_length = CHARFIELD_MAX_LENGTH , blank = True , default = ""
439
+ )
430
440
currency = models .CharField (verbose_name = "Currency" , max_length = 4 , blank = True , default = "" )
431
- contract_type = models .CharField (verbose_name = "Contract Type" , max_length = 32 , blank = True , default = "" )
441
+ contract_type = models .CharField (
442
+ verbose_name = "Contract Type" , max_length = CHARFIELD_MAX_LENGTH , blank = True , default = ""
443
+ )
432
444
devices = models .ManyToManyField (to = "dcim.Device" , related_name = "device_contracts" , blank = True )
433
445
comments = models .TextField (blank = True , default = "" )
434
446
@@ -477,11 +489,11 @@ class ProviderLCM(OrganizationalModel):
477
489
"""ProviderLCM model for app."""
478
490
479
491
# Set model columns
480
- name = models .CharField (max_length = 100 , unique = True )
481
- description = models .CharField (max_length = 200 , blank = True )
482
- physical_address = models .CharField (max_length = 200 , blank = True )
492
+ name = models .CharField (max_length = CHARFIELD_MAX_LENGTH , unique = True )
493
+ description = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True )
494
+ physical_address = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True )
483
495
country = models .CharField (max_length = 3 , blank = True )
484
- phone = models .CharField (max_length = 20 , blank = True )
496
+ phone = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True )
485
497
email = models .EmailField (blank = True , verbose_name = "E-mail" )
486
498
portal_url = models .URLField (blank = True , verbose_name = "Portal URL" )
487
499
comments = models .TextField (blank = True , default = "" )
@@ -515,13 +527,13 @@ def save(self, *args, **kwargs):
515
527
class ContactLCM (PrimaryModel ):
516
528
"""ContactLCM is a model representation of a contact used in Contracts."""
517
529
518
- name = models .CharField (max_length = 80 , null = True )
519
- address = models .CharField (max_length = 200 , blank = True )
520
- phone = models .CharField (max_length = 20 , blank = True )
530
+ name = models .CharField (max_length = CHARFIELD_MAX_LENGTH , null = True )
531
+ address = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True )
532
+ phone = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True )
521
533
email = models .EmailField (blank = True , verbose_name = "Contact E-mail" )
522
534
comments = models .TextField (blank = True , default = "" )
523
535
priority = models .PositiveIntegerField (default = 100 )
524
- type = models .CharField (max_length = 50 , default = choices .PoCTypeChoices .UNASSIGNED )
536
+ type = models .CharField (max_length = CHARFIELD_MAX_LENGTH , default = choices .PoCTypeChoices .UNASSIGNED )
525
537
contract = models .ForeignKey (
526
538
to = "nautobot_device_lifecycle_mgmt.ContractLCM" , on_delete = models .CASCADE , verbose_name = "Contract" , null = True
527
539
)
@@ -566,7 +578,7 @@ def __str__(self):
566
578
class CVELCM (PrimaryModel ):
567
579
"""CVELCM is a model representation of a cve vulnerability record."""
568
580
569
- name = models .CharField (max_length = 16 , blank = False , unique = True )
581
+ name = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = False , unique = True )
570
582
published_date = models .DateField (verbose_name = "Published Date" )
571
583
link = models .URLField ()
572
584
status = StatusField (
@@ -575,9 +587,9 @@ class CVELCM(PrimaryModel):
575
587
on_delete = models .PROTECT ,
576
588
to = "extras.status" ,
577
589
)
578
- description = models .CharField (max_length = 255 , blank = True , default = "" )
590
+ description = models .CharField (max_length = CHARFIELD_MAX_LENGTH , blank = True , default = "" )
579
591
severity = models .CharField (
580
- max_length = 50 , choices = choices .CVESeverityChoices , default = choices .CVESeverityChoices .NONE
592
+ max_length = CHARFIELD_MAX_LENGTH , choices = choices .CVESeverityChoices , default = choices .CVESeverityChoices .NONE
581
593
)
582
594
cvss = models .FloatField (blank = True , null = True , verbose_name = "CVSS Base Score" )
583
595
cvss_v2 = models .FloatField (blank = True , null = True , verbose_name = "CVSSv2 Score" )
0 commit comments