mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
ipaddressfunction - poc
This commit is contained in:
parent
3307bd200c
commit
3c82920870
@ -94,6 +94,18 @@ class IPAddressRoleChoices(ChoiceSet):
|
||||
(ROLE_CARP, 'CARP', 'green'),
|
||||
)
|
||||
|
||||
class IPAddressFunctionChoices(ChoiceSet):
|
||||
|
||||
FUNC_OOB = 'Out Of Band'
|
||||
# Future planning, depreciate primary_ip
|
||||
# FUNC_PRIMARY_IP = 'Primary IP'
|
||||
|
||||
CHOICES = (
|
||||
(FUNC_OOB, 'Out Of Band', 'gray'),
|
||||
# Future planning, depreciate primary_ip
|
||||
# (FUNC_PRIMARY_IP, 'Primary IP', 'blue'),
|
||||
)
|
||||
|
||||
|
||||
#
|
||||
# FHRP
|
||||
|
@ -48,6 +48,12 @@ IPADDRESS_ROLES_NONUNIQUE = (
|
||||
)
|
||||
|
||||
|
||||
IPADDRESS_FUNCTION_ASSIGNMENT_MODELS = Q(
|
||||
Q(app_label='dcim', model='device') |
|
||||
Q(app_label='dcim', model='virtualdevicecontext') |
|
||||
Q(app_label='virtualization', model='VirtualMachine')
|
||||
)
|
||||
|
||||
#
|
||||
# FHRP groups
|
||||
#
|
||||
|
@ -15,7 +15,7 @@ from ipam.managers import IPAddressManager
|
||||
from ipam.querysets import PrefixQuerySet
|
||||
from ipam.validators import DNSValidator
|
||||
from netbox.config import get_config
|
||||
from netbox.models import OrganizationalModel, PrimaryModel
|
||||
from netbox.models import OrganizationalModel, PrimaryModel, NetBoxModel
|
||||
|
||||
__all__ = (
|
||||
'Aggregate',
|
||||
@ -667,6 +667,53 @@ class IPRange(PrimaryModel):
|
||||
return int(float(child_count) / self.size * 100)
|
||||
|
||||
|
||||
class IPAddressFunction(NetBoxModel):
|
||||
assigned_object_type = models.ForeignKey(
|
||||
to=ContentType,
|
||||
limit_choices_to=IPADDRESS_FUNCTION_ASSIGNMENT_MODELS,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='+'
|
||||
)
|
||||
assigned_object_id = models.PositiveBigIntegerField()
|
||||
assigned_object = GenericForeignKey(
|
||||
ct_field='assigned_object_type',
|
||||
fk_field='assigned_object_id'
|
||||
)
|
||||
assigned_ip = models.ForeignKey(
|
||||
to='ipam.IPAddress',
|
||||
on_delete=models.CASCADE,
|
||||
related_name='+',
|
||||
verbose_name='Assigned IP'
|
||||
)
|
||||
function = models.CharField(
|
||||
max_length=50,
|
||||
choices=IPAddressFunctionChoices,
|
||||
help_text=_('Function to assign to ip')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ('function',)
|
||||
verbose_name = 'IP Address Function'
|
||||
constraints = (
|
||||
models.UniqueConstraint(
|
||||
fields=('assigned_object_type', 'assigned_object_id', 'function'),
|
||||
name='ipam_ipfunction_assigned_object'
|
||||
),
|
||||
models.UniqueConstraint(
|
||||
fields=('assigned_ip'),
|
||||
name='ipam_ipfunction_ip_single_use'
|
||||
),
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
if self.pk is not None:
|
||||
return f'{self.assigned_object_type} - {self.function} - {self.assigned_ip}'
|
||||
return super().__str__()
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse('ipam:ipaddressfunction', args=[self.pk])
|
||||
|
||||
|
||||
class IPAddress(PrimaryModel):
|
||||
"""
|
||||
An IPAddress represents an individual IPv4 or IPv6 address and its mask. The mask length should match what is
|
||||
|
Loading…
Reference in New Issue
Block a user