|
|
@@ -150,9 +150,6 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|
|
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.
|
|
|
"""
|
|
|
- family = models.PositiveSmallIntegerField(
|
|
|
- choices=IPAddressFamilyChoices
|
|
|
- )
|
|
|
prefix = IPNetworkField()
|
|
|
rir = models.ForeignKey(
|
|
|
to='ipam.RIR',
|
|
|
@@ -182,7 +179,7 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|
|
]
|
|
|
|
|
|
class Meta:
|
|
|
- ordering = ('family', 'prefix', 'pk') # (family, prefix) may be non-unique
|
|
|
+ ordering = ('prefix', 'pk') # prefix may be non-unique
|
|
|
|
|
|
def __str__(self):
|
|
|
return str(self.prefix)
|
|
|
@@ -225,12 +222,6 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|
|
)
|
|
|
})
|
|
|
|
|
|
- def save(self, *args, **kwargs):
|
|
|
- if self.prefix:
|
|
|
- # Infer address family from IPNetwork object
|
|
|
- self.family = self.prefix.version
|
|
|
- super().save(*args, **kwargs)
|
|
|
-
|
|
|
def to_csv(self):
|
|
|
return (
|
|
|
self.prefix,
|
|
|
@@ -239,6 +230,12 @@ class Aggregate(ChangeLoggedModel, CustomFieldModel):
|
|
|
self.description,
|
|
|
)
|
|
|
|
|
|
+ @property
|
|
|
+ def family(self):
|
|
|
+ if self.prefix:
|
|
|
+ return self.prefix.version
|
|
|
+ return None
|
|
|
+
|
|
|
def get_utilization(self):
|
|
|
"""
|
|
|
Determine the prefix utilization of the aggregate and return it as a percentage.
|
|
|
@@ -291,10 +288,6 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|
|
VRFs. A Prefix must be assigned a status and may optionally be assigned a used-define Role. A Prefix can also be
|
|
|
assigned to a VLAN where appropriate.
|
|
|
"""
|
|
|
- family = models.PositiveSmallIntegerField(
|
|
|
- choices=IPAddressFamilyChoices,
|
|
|
- editable=False
|
|
|
- )
|
|
|
prefix = IPNetworkField(
|
|
|
help_text='IPv4 or IPv6 network with mask'
|
|
|
)
|
|
|
@@ -376,7 +369,7 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|
|
}
|
|
|
|
|
|
class Meta:
|
|
|
- ordering = (F('vrf').asc(nulls_first=True), 'family', 'prefix', 'pk') # (vrf, family, prefix) may be non-unique
|
|
|
+ ordering = (F('vrf').asc(nulls_first=True), 'prefix', 'pk') # (vrf, prefix) may be non-unique
|
|
|
verbose_name_plural = 'prefixes'
|
|
|
|
|
|
def __str__(self):
|
|
|
@@ -423,9 +416,6 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|
|
# Clear host bits from prefix
|
|
|
self.prefix = self.prefix.cidr
|
|
|
|
|
|
- # Record address family
|
|
|
- self.family = self.prefix.version
|
|
|
-
|
|
|
super().save(*args, **kwargs)
|
|
|
|
|
|
def to_csv(self):
|
|
|
@@ -442,6 +432,12 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|
|
self.description,
|
|
|
)
|
|
|
|
|
|
+ @property
|
|
|
+ def family(self):
|
|
|
+ if self.prefix:
|
|
|
+ return self.prefix.version
|
|
|
+ return None
|
|
|
+
|
|
|
def _set_prefix_length(self, value):
|
|
|
"""
|
|
|
Expose the IPNetwork object's prefixlen attribute on the parent model so that it can be manipulated directly,
|
|
|
@@ -501,9 +497,9 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|
|
|
|
|
# All IP addresses within a point-to-point prefix (IPv4 /31 or IPv6 /127) are considered usable
|
|
|
if (
|
|
|
- self.family == 4 and self.prefix.prefixlen == 31 # RFC 3021
|
|
|
+ self.prefix.version == 4 and self.prefix.prefixlen == 31 # RFC 3021
|
|
|
) or (
|
|
|
- self.family == 6 and self.prefix.prefixlen == 127 # RFC 6164
|
|
|
+ self.prefix.version == 6 and self.prefix.prefixlen == 127 # RFC 6164
|
|
|
):
|
|
|
return available_ips
|
|
|
|
|
|
@@ -546,7 +542,7 @@ class Prefix(ChangeLoggedModel, CustomFieldModel):
|
|
|
# Compile an IPSet to avoid counting duplicate IPs
|
|
|
child_count = netaddr.IPSet([ip.address.ip for ip in self.get_child_ips()]).size
|
|
|
prefix_size = self.prefix.size
|
|
|
- if self.family == 4 and self.prefix.prefixlen < 31 and not self.is_pool:
|
|
|
+ if self.prefix.version == 4 and self.prefix.prefixlen < 31 and not self.is_pool:
|
|
|
prefix_size -= 2
|
|
|
return int(float(child_count) / prefix_size * 100)
|
|
|
|
|
|
@@ -562,10 +558,6 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|
|
for example, when mapping public addresses to private addresses. When an Interface has been assigned an IPAddress
|
|
|
which has a NAT outside IP, that Interface's Device can use either the inside or outside IP as its primary IP.
|
|
|
"""
|
|
|
- family = models.PositiveSmallIntegerField(
|
|
|
- choices=IPAddressFamilyChoices,
|
|
|
- editable=False
|
|
|
- )
|
|
|
address = IPAddressField(
|
|
|
help_text='IPv4 or IPv6 address (with mask)'
|
|
|
)
|
|
|
@@ -659,7 +651,7 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|
|
}
|
|
|
|
|
|
class Meta:
|
|
|
- ordering = ('family', 'address', 'pk') # (family, address) may be non-unique
|
|
|
+ ordering = ('address', 'pk') # address may be non-unique
|
|
|
verbose_name = 'IP address'
|
|
|
verbose_name_plural = 'IP addresses'
|
|
|
|
|
|
@@ -727,10 +719,6 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
|
|
- # Record address family
|
|
|
- if isinstance(self.address, netaddr.IPNetwork):
|
|
|
- self.family = self.address.version
|
|
|
-
|
|
|
# Force dns_name to lowercase
|
|
|
self.dns_name = self.dns_name.lower()
|
|
|
|
|
|
@@ -754,9 +742,9 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|
|
def to_csv(self):
|
|
|
|
|
|
# Determine if this IP is primary for a Device
|
|
|
- if self.family == 4 and getattr(self, 'primary_ip4_for', False):
|
|
|
+ if self.address.version == 4 and getattr(self, 'primary_ip4_for', False):
|
|
|
is_primary = True
|
|
|
- elif self.family == 6 and getattr(self, 'primary_ip6_for', False):
|
|
|
+ elif self.address.version == 6 and getattr(self, 'primary_ip6_for', False):
|
|
|
is_primary = True
|
|
|
else:
|
|
|
is_primary = False
|
|
|
@@ -775,6 +763,12 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel):
|
|
|
self.description,
|
|
|
)
|
|
|
|
|
|
+ @property
|
|
|
+ def family(self):
|
|
|
+ if self.address:
|
|
|
+ return self.address.version
|
|
|
+ return None
|
|
|
+
|
|
|
def _set_mask_length(self, value):
|
|
|
"""
|
|
|
Expose the IPNetwork object's prefixlen attribute on the parent model so that it can be manipulated directly,
|