providers.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. from django.contrib.contenttypes.fields import GenericRelation
  2. from django.db import models
  3. from django.urls import reverse
  4. from netbox.models import PrimaryModel
  5. __all__ = (
  6. 'ProviderNetwork',
  7. 'Provider',
  8. )
  9. class Provider(PrimaryModel):
  10. """
  11. Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
  12. stores information pertinent to the user's relationship with the Provider.
  13. """
  14. name = models.CharField(
  15. max_length=100,
  16. unique=True
  17. )
  18. slug = models.SlugField(
  19. max_length=100,
  20. unique=True
  21. )
  22. asns = models.ManyToManyField(
  23. to='ipam.ASN',
  24. related_name='providers',
  25. blank=True
  26. )
  27. account = models.CharField(
  28. max_length=30,
  29. blank=True,
  30. verbose_name='Account number'
  31. )
  32. # Generic relations
  33. contacts = GenericRelation(
  34. to='tenancy.ContactAssignment'
  35. )
  36. clone_fields = (
  37. 'account',
  38. )
  39. class Meta:
  40. ordering = ['name']
  41. def __str__(self):
  42. return self.name
  43. def get_absolute_url(self):
  44. return reverse('circuits:provider', args=[self.pk])
  45. class ProviderNetwork(PrimaryModel):
  46. """
  47. This represents a provider network which exists outside of NetBox, the details of which are unknown or
  48. unimportant to the user.
  49. """
  50. name = models.CharField(
  51. max_length=100
  52. )
  53. provider = models.ForeignKey(
  54. to='circuits.Provider',
  55. on_delete=models.PROTECT,
  56. related_name='networks'
  57. )
  58. service_id = models.CharField(
  59. max_length=100,
  60. blank=True,
  61. verbose_name='Service ID'
  62. )
  63. class Meta:
  64. ordering = ('provider', 'name')
  65. constraints = (
  66. models.UniqueConstraint(
  67. fields=('provider', 'name'),
  68. name='%(app_label)s_%(class)s_unique_provider_name'
  69. ),
  70. )
  71. def __str__(self):
  72. return self.name
  73. def get_absolute_url(self):
  74. return reverse('circuits:providernetwork', args=[self.pk])