mirror of
https://github.com/netbox-community/netbox.git
synced 2025-12-21 12:52:21 -06:00
#6454 fix merge conflicts
This commit is contained in:
@@ -179,9 +179,9 @@ class Aggregate(GetAvailablePrefixesMixin, NetBoxModel):
|
||||
blank=True
|
||||
)
|
||||
|
||||
clone_fields = [
|
||||
clone_fields = (
|
||||
'rir', 'tenant', 'date_added', 'description',
|
||||
]
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ('prefix', 'pk') # prefix may be non-unique
|
||||
@@ -368,9 +368,9 @@ class Prefix(GetAvailablePrefixesMixin, NetBoxModel):
|
||||
|
||||
objects = PrefixQuerySet.as_manager()
|
||||
|
||||
clone_fields = [
|
||||
clone_fields = (
|
||||
'site', 'vrf', 'tenant', 'vlan', 'status', 'role', 'is_pool', 'mark_utilized', 'description',
|
||||
]
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = (F('vrf').asc(nulls_first=True), 'prefix', 'pk') # (vrf, prefix) may be non-unique
|
||||
@@ -616,9 +616,9 @@ class IPRange(NetBoxModel):
|
||||
blank=True
|
||||
)
|
||||
|
||||
clone_fields = [
|
||||
clone_fields = (
|
||||
'vrf', 'tenant', 'status', 'role', 'description',
|
||||
]
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = (F('vrf').asc(nulls_first=True), 'start_address', 'pk') # (vrf, start_address) may be non-unique
|
||||
@@ -821,7 +821,7 @@ class IPAddress(NetBoxModel):
|
||||
ct_field='assigned_object_type',
|
||||
fk_field='assigned_object_id'
|
||||
)
|
||||
nat_inside = models.OneToOneField(
|
||||
nat_inside = models.ForeignKey(
|
||||
to='self',
|
||||
on_delete=models.SET_NULL,
|
||||
related_name='nat_outside',
|
||||
@@ -844,9 +844,9 @@ class IPAddress(NetBoxModel):
|
||||
|
||||
objects = IPAddressManager()
|
||||
|
||||
clone_fields = [
|
||||
'vrf', 'tenant', 'status', 'role', 'description',
|
||||
]
|
||||
clone_fields = (
|
||||
'vrf', 'tenant', 'status', 'role', 'dns_name', 'description',
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ('address', 'pk') # address may be non-unique
|
||||
@@ -865,6 +865,25 @@ class IPAddress(NetBoxModel):
|
||||
address__net_host=str(self.address.ip)
|
||||
).exclude(pk=self.pk)
|
||||
|
||||
def get_next_available_ip(self):
|
||||
"""
|
||||
Return the next available IP address within this IP's network (if any)
|
||||
"""
|
||||
if self.address and self.address.broadcast:
|
||||
start_ip = self.address.ip + 1
|
||||
end_ip = self.address.broadcast - 1
|
||||
if start_ip <= end_ip:
|
||||
available_ips = netaddr.IPSet(netaddr.IPRange(start_ip, end_ip))
|
||||
available_ips -= netaddr.IPSet([
|
||||
address.ip for address in IPAddress.objects.filter(
|
||||
vrf=self.vrf,
|
||||
address__gt=self.address,
|
||||
address__net_contained_or_equal=self.address.cidr
|
||||
).values_list('address', flat=True)
|
||||
])
|
||||
if available_ips:
|
||||
return next(iter(available_ips))
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
||||
@@ -915,6 +934,15 @@ class IPAddress(NetBoxModel):
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def clone(self):
|
||||
attrs = super().clone()
|
||||
|
||||
# Populate the address field with the next available IP (if any)
|
||||
if next_available_ip := self.get_next_available_ip():
|
||||
attrs['address'] = f'{next_available_ip}/{self.address.prefixlen}'
|
||||
|
||||
return attrs
|
||||
|
||||
def to_objectchange(self, action):
|
||||
objectchange = super().to_objectchange(action)
|
||||
objectchange.related_object = self.assigned_object
|
||||
|
||||
Reference in New Issue
Block a user