mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Closes #40: Added IP utilization graph to prefix list
This commit is contained in:
@ -200,7 +200,7 @@ class Aggregate(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
|
|
||||||
def get_utilization(self):
|
def get_utilization(self):
|
||||||
"""
|
"""
|
||||||
Determine the utilization rate of the aggregate prefix and return it as a percentage.
|
Determine the prefix utilization of the aggregate and return it as a percentage.
|
||||||
"""
|
"""
|
||||||
child_prefixes = Prefix.objects.filter(prefix__net_contained_or_equal=str(self.prefix))
|
child_prefixes = Prefix.objects.filter(prefix__net_contained_or_equal=str(self.prefix))
|
||||||
# Remove overlapping prefixes from list of children
|
# Remove overlapping prefixes from list of children
|
||||||
@ -307,9 +307,6 @@ class Prefix(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('ipam:prefix', args=[self.pk])
|
return reverse('ipam:prefix', args=[self.pk])
|
||||||
|
|
||||||
def get_duplicates(self):
|
|
||||||
return Prefix.objects.filter(vrf=self.vrf, prefix=str(self.prefix)).exclude(pk=self.pk)
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
|
|
||||||
if self.prefix:
|
if self.prefix:
|
||||||
@ -357,6 +354,22 @@ class Prefix(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
self.description,
|
self.description,
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def get_status_class(self):
|
||||||
|
return STATUS_CHOICE_CLASSES[self.status]
|
||||||
|
|
||||||
|
def get_duplicates(self):
|
||||||
|
return Prefix.objects.filter(vrf=self.vrf, prefix=str(self.prefix)).exclude(pk=self.pk)
|
||||||
|
|
||||||
|
def get_utilization(self):
|
||||||
|
"""
|
||||||
|
Determine the utilization of the prefix and return it as a percentage.
|
||||||
|
"""
|
||||||
|
child_count = IPAddress.objects.filter(address__net_contained_or_equal=str(self.prefix), vrf=self.vrf).count()
|
||||||
|
prefix_size = self.prefix.size
|
||||||
|
if self.family == 4 and self.prefix.prefixlen < 31 and not self.is_pool:
|
||||||
|
prefix_size -= 2
|
||||||
|
return int(float(child_count) / prefix_size * 100)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def new_subnet(self):
|
def new_subnet(self):
|
||||||
if self.family == 4:
|
if self.family == 4:
|
||||||
@ -368,9 +381,6 @@ class Prefix(CreatedUpdatedModel, CustomFieldModel):
|
|||||||
return IPNetwork('{}/{}'.format(self.prefix.network, self.prefix.prefixlen + 1))
|
return IPNetwork('{}/{}'.format(self.prefix.network, self.prefix.prefixlen + 1))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_status_class(self):
|
|
||||||
return STATUS_CHOICE_CLASSES[self.status]
|
|
||||||
|
|
||||||
|
|
||||||
class IPAddressManager(models.Manager):
|
class IPAddressManager(models.Manager):
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ RIR_ACTIONS = """
|
|||||||
|
|
||||||
UTILIZATION_GRAPH = """
|
UTILIZATION_GRAPH = """
|
||||||
{% load helpers %}
|
{% load helpers %}
|
||||||
{% utilization_graph value %}
|
{% if record.pk %}{% utilization_graph value %}{% else %}—{% endif %}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
ROLE_ACTIONS = """
|
ROLE_ACTIONS = """
|
||||||
@ -241,6 +241,7 @@ class PrefixTable(BaseTable):
|
|||||||
prefix = tables.TemplateColumn(PREFIX_LINK, attrs={'th': {'style': 'padding-left: 17px'}})
|
prefix = tables.TemplateColumn(PREFIX_LINK, attrs={'th': {'style': 'padding-left: 17px'}})
|
||||||
status = tables.TemplateColumn(STATUS_LABEL)
|
status = tables.TemplateColumn(STATUS_LABEL)
|
||||||
vrf = tables.TemplateColumn(VRF_LINK, verbose_name='VRF')
|
vrf = tables.TemplateColumn(VRF_LINK, verbose_name='VRF')
|
||||||
|
get_utilization = tables.TemplateColumn(UTILIZATION_GRAPH, orderable=False, verbose_name='IP Usage')
|
||||||
tenant = tables.TemplateColumn(TENANT_LINK)
|
tenant = tables.TemplateColumn(TENANT_LINK)
|
||||||
site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')])
|
site = tables.LinkColumn('dcim:site', args=[Accessor('site.slug')])
|
||||||
vlan = tables.LinkColumn('ipam:vlan', args=[Accessor('vlan.pk')], verbose_name='VLAN')
|
vlan = tables.LinkColumn('ipam:vlan', args=[Accessor('vlan.pk')], verbose_name='VLAN')
|
||||||
@ -248,7 +249,7 @@ class PrefixTable(BaseTable):
|
|||||||
|
|
||||||
class Meta(BaseTable.Meta):
|
class Meta(BaseTable.Meta):
|
||||||
model = Prefix
|
model = Prefix
|
||||||
fields = ('pk', 'prefix', 'status', 'vrf', 'tenant', 'site', 'vlan', 'role', 'description')
|
fields = ('pk', 'prefix', 'status', 'vrf', 'get_utilization', 'tenant', 'site', 'vlan', 'role', 'description')
|
||||||
row_attrs = {
|
row_attrs = {
|
||||||
'class': lambda record: 'success' if not record.pk else '',
|
'class': lambda record: 'success' if not record.pk else '',
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user