Skip to content

Commit

Permalink
13764 Add contacts to IP views
Browse files Browse the repository at this point in the history
  • Loading branch information
arthanson authored and jeremystretch committed May 21, 2024
1 parent 233b902 commit 17799df
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 5 additions & 4 deletions netbox/ipam/models/ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ipam.validators import DNSValidator
from netbox.config import get_config
from netbox.models import OrganizationalModel, PrimaryModel
from netbox.models.features import ContactsMixin

__all__ = (
'Aggregate',
Expand Down Expand Up @@ -74,7 +75,7 @@ def get_absolute_url(self):
return reverse('ipam:rir', args=[self.pk])


class Aggregate(GetAvailablePrefixesMixin, PrimaryModel):
class Aggregate(ContactsMixin, GetAvailablePrefixesMixin, PrimaryModel):
"""
An aggregate exists at the root level of the IP address space hierarchy in NetBox. Aggregates are used to organize
the hierarchy and track the overall utilization of available address space. Each Aggregate is assigned to a RIR.
Expand Down Expand Up @@ -206,7 +207,7 @@ def get_absolute_url(self):
return reverse('ipam:role', args=[self.pk])


class Prefix(GetAvailablePrefixesMixin, PrimaryModel):
class Prefix(ContactsMixin, GetAvailablePrefixesMixin, PrimaryModel):
"""
A Prefix represents an IPv4 or IPv6 network, including mask length. Prefixes can optionally be assigned to Sites and
VRFs. A Prefix must be assigned a status and may optionally be assigned a used-define Role. A Prefix can also be
Expand Down Expand Up @@ -486,7 +487,7 @@ def get_utilization(self):
return min(utilization, 100)


class IPRange(PrimaryModel):
class IPRange(ContactsMixin, PrimaryModel):
"""
A range of IP addresses, defined by start and end addresses.
"""
Expand Down Expand Up @@ -695,7 +696,7 @@ def utilization(self):
return min(float(child_count) / self.size * 100, 100)


class IPAddress(PrimaryModel):
class IPAddress(ContactsMixin, PrimaryModel):
"""
An IPAddress represents an individual IPv4 or IPv6 address and its mask. The mask length should match what is
configured in the real world. (Typically, only loopback interfaces are configured with /32 or /128 masks.) Like
Expand Down
21 changes: 21 additions & 0 deletions netbox/ipam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from dcim.filtersets import InterfaceFilterSet
from dcim.models import Interface, Site
from netbox.views import generic
from tenancy.views import ObjectContactsView
from utilities.query import count_related
from utilities.tables import get_table_ordering
from utilities.views import ViewTab, register_model_view
Expand Down Expand Up @@ -405,6 +406,11 @@ class AggregateBulkDeleteView(generic.BulkDeleteView):
table = tables.AggregateTable


@register_model_view(Aggregate, 'contacts')
class AggregateContactsView(ObjectContactsView):
queryset = Aggregate.objects.all()


#
# Prefix/VLAN roles
#
Expand Down Expand Up @@ -643,6 +649,11 @@ class PrefixBulkDeleteView(generic.BulkDeleteView):
table = tables.PrefixTable


@register_model_view(Prefix, 'contacts')
class PrefixContactsView(ObjectContactsView):
queryset = Prefix.objects.all()


#
# IP Ranges
#
Expand Down Expand Up @@ -726,6 +737,11 @@ class IPRangeBulkDeleteView(generic.BulkDeleteView):
table = tables.IPRangeTable


@register_model_view(IPRange, 'contacts')
class IPRangeContactsView(ObjectContactsView):
queryset = IPRange.objects.all()


#
# IP addresses
#
Expand Down Expand Up @@ -893,6 +909,11 @@ def get_children(self, request, parent):
return parent.get_related_ips().restrict(request.user, 'view')


@register_model_view(IPAddress, 'contacts')
class IPAddressContactsView(ObjectContactsView):
queryset = IPAddress.objects.all()


#
# VLAN groups
#
Expand Down

0 comments on commit 17799df

Please sign in to comment.