mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Split circuits models into submodules
This commit is contained in:
2
netbox/circuits/models/__init__.py
Normal file
2
netbox/circuits/models/__init__.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
from .circuits import *
|
||||||
|
from .providers import *
|
@ -3,131 +3,19 @@ from django.core.exceptions import ValidationError
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from dcim.fields import ASNField
|
from circuits.choices import *
|
||||||
from dcim.models import LinkTermination, PathEndpoint
|
from dcim.models import LinkTermination
|
||||||
from extras.models import ObjectChange
|
|
||||||
from extras.utils import extras_features
|
from extras.utils import extras_features
|
||||||
from netbox.models import BigIDModel, ChangeLoggedModel, OrganizationalModel, PrimaryModel
|
from netbox.models import ChangeLoggedModel, OrganizationalModel, PrimaryModel
|
||||||
from utilities.querysets import RestrictedQuerySet
|
from utilities.querysets import RestrictedQuerySet
|
||||||
from .choices import *
|
|
||||||
|
|
||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'Circuit',
|
'Circuit',
|
||||||
'CircuitTermination',
|
'CircuitTermination',
|
||||||
'CircuitType',
|
'CircuitType',
|
||||||
'ProviderNetwork',
|
|
||||||
'Provider',
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
|
||||||
class Provider(PrimaryModel):
|
|
||||||
"""
|
|
||||||
Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
|
|
||||||
stores information pertinent to the user's relationship with the Provider.
|
|
||||||
"""
|
|
||||||
name = models.CharField(
|
|
||||||
max_length=100,
|
|
||||||
unique=True
|
|
||||||
)
|
|
||||||
slug = models.SlugField(
|
|
||||||
max_length=100,
|
|
||||||
unique=True
|
|
||||||
)
|
|
||||||
asn = ASNField(
|
|
||||||
blank=True,
|
|
||||||
null=True,
|
|
||||||
verbose_name='ASN',
|
|
||||||
help_text='32-bit autonomous system number'
|
|
||||||
)
|
|
||||||
account = models.CharField(
|
|
||||||
max_length=30,
|
|
||||||
blank=True,
|
|
||||||
verbose_name='Account number'
|
|
||||||
)
|
|
||||||
portal_url = models.URLField(
|
|
||||||
blank=True,
|
|
||||||
verbose_name='Portal URL'
|
|
||||||
)
|
|
||||||
noc_contact = models.TextField(
|
|
||||||
blank=True,
|
|
||||||
verbose_name='NOC contact'
|
|
||||||
)
|
|
||||||
admin_contact = models.TextField(
|
|
||||||
blank=True,
|
|
||||||
verbose_name='Admin contact'
|
|
||||||
)
|
|
||||||
comments = models.TextField(
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generic relations
|
|
||||||
contacts = GenericRelation(
|
|
||||||
to='tenancy.ContactAssignment'
|
|
||||||
)
|
|
||||||
|
|
||||||
objects = RestrictedQuerySet.as_manager()
|
|
||||||
|
|
||||||
clone_fields = [
|
|
||||||
'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact',
|
|
||||||
]
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ['name']
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return reverse('circuits:provider', args=[self.pk])
|
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Provider networks
|
|
||||||
#
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
|
||||||
class ProviderNetwork(PrimaryModel):
|
|
||||||
"""
|
|
||||||
This represents a provider network which exists outside of NetBox, the details of which are unknown or
|
|
||||||
unimportant to the user.
|
|
||||||
"""
|
|
||||||
name = models.CharField(
|
|
||||||
max_length=100
|
|
||||||
)
|
|
||||||
provider = models.ForeignKey(
|
|
||||||
to='circuits.Provider',
|
|
||||||
on_delete=models.PROTECT,
|
|
||||||
related_name='networks'
|
|
||||||
)
|
|
||||||
description = models.CharField(
|
|
||||||
max_length=200,
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
comments = models.TextField(
|
|
||||||
blank=True
|
|
||||||
)
|
|
||||||
|
|
||||||
objects = RestrictedQuerySet.as_manager()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ('provider', 'name')
|
|
||||||
constraints = (
|
|
||||||
models.UniqueConstraint(
|
|
||||||
fields=('provider', 'name'),
|
|
||||||
name='circuits_providernetwork_provider_name'
|
|
||||||
),
|
|
||||||
)
|
|
||||||
unique_together = ('provider', 'name')
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
|
||||||
return reverse('circuits:providernetwork', args=[self.pk])
|
|
||||||
|
|
||||||
|
|
||||||
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
class CircuitType(OrganizationalModel):
|
class CircuitType(OrganizationalModel):
|
||||||
"""
|
"""
|
||||||
@ -275,7 +163,7 @@ class CircuitTermination(ChangeLoggedModel, LinkTermination):
|
|||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
provider_network = models.ForeignKey(
|
provider_network = models.ForeignKey(
|
||||||
to=ProviderNetwork,
|
to='circuits.ProviderNetwork',
|
||||||
on_delete=models.PROTECT,
|
on_delete=models.PROTECT,
|
||||||
related_name='circuit_terminations',
|
related_name='circuit_terminations',
|
||||||
blank=True,
|
blank=True,
|
116
netbox/circuits/models/providers.py
Normal file
116
netbox/circuits/models/providers.py
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
|
from django.db import models
|
||||||
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from dcim.fields import ASNField
|
||||||
|
from extras.utils import extras_features
|
||||||
|
from netbox.models import PrimaryModel
|
||||||
|
from utilities.querysets import RestrictedQuerySet
|
||||||
|
|
||||||
|
__all__ = (
|
||||||
|
'ProviderNetwork',
|
||||||
|
'Provider',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
|
class Provider(PrimaryModel):
|
||||||
|
"""
|
||||||
|
Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
|
||||||
|
stores information pertinent to the user's relationship with the Provider.
|
||||||
|
"""
|
||||||
|
name = models.CharField(
|
||||||
|
max_length=100,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
slug = models.SlugField(
|
||||||
|
max_length=100,
|
||||||
|
unique=True
|
||||||
|
)
|
||||||
|
asn = ASNField(
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
verbose_name='ASN',
|
||||||
|
help_text='32-bit autonomous system number'
|
||||||
|
)
|
||||||
|
account = models.CharField(
|
||||||
|
max_length=30,
|
||||||
|
blank=True,
|
||||||
|
verbose_name='Account number'
|
||||||
|
)
|
||||||
|
portal_url = models.URLField(
|
||||||
|
blank=True,
|
||||||
|
verbose_name='Portal URL'
|
||||||
|
)
|
||||||
|
noc_contact = models.TextField(
|
||||||
|
blank=True,
|
||||||
|
verbose_name='NOC contact'
|
||||||
|
)
|
||||||
|
admin_contact = models.TextField(
|
||||||
|
blank=True,
|
||||||
|
verbose_name='Admin contact'
|
||||||
|
)
|
||||||
|
comments = models.TextField(
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Generic relations
|
||||||
|
contacts = GenericRelation(
|
||||||
|
to='tenancy.ContactAssignment'
|
||||||
|
)
|
||||||
|
|
||||||
|
objects = RestrictedQuerySet.as_manager()
|
||||||
|
|
||||||
|
clone_fields = [
|
||||||
|
'asn', 'account', 'portal_url', 'noc_contact', 'admin_contact',
|
||||||
|
]
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ['name']
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('circuits:provider', args=[self.pk])
|
||||||
|
|
||||||
|
|
||||||
|
@extras_features('custom_fields', 'custom_links', 'export_templates', 'tags', 'webhooks')
|
||||||
|
class ProviderNetwork(PrimaryModel):
|
||||||
|
"""
|
||||||
|
This represents a provider network which exists outside of NetBox, the details of which are unknown or
|
||||||
|
unimportant to the user.
|
||||||
|
"""
|
||||||
|
name = models.CharField(
|
||||||
|
max_length=100
|
||||||
|
)
|
||||||
|
provider = models.ForeignKey(
|
||||||
|
to='circuits.Provider',
|
||||||
|
on_delete=models.PROTECT,
|
||||||
|
related_name='networks'
|
||||||
|
)
|
||||||
|
description = models.CharField(
|
||||||
|
max_length=200,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
comments = models.TextField(
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
|
||||||
|
objects = RestrictedQuerySet.as_manager()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ('provider', 'name')
|
||||||
|
constraints = (
|
||||||
|
models.UniqueConstraint(
|
||||||
|
fields=('provider', 'name'),
|
||||||
|
name='circuits_providernetwork_provider_name'
|
||||||
|
),
|
||||||
|
)
|
||||||
|
unique_together = ('provider', 'name')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
def get_absolute_url(self):
|
||||||
|
return reverse('circuits:providernetwork', args=[self.pk])
|
Reference in New Issue
Block a user