mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #10220: Validate IP version when assigning primary IPs to a virtual machine
This commit is contained in:
@ -24,6 +24,7 @@
|
|||||||
* [#10181](https://github.com/netbox-community/netbox/issues/10181) - Restore MultiPartParser (regression from #10031)
|
* [#10181](https://github.com/netbox-community/netbox/issues/10181) - Restore MultiPartParser (regression from #10031)
|
||||||
* [#10208](https://github.com/netbox-community/netbox/issues/10208) - Fix permissions evaluation for interface actions dropdown menu
|
* [#10208](https://github.com/netbox-community/netbox/issues/10208) - Fix permissions evaluation for interface actions dropdown menu
|
||||||
* [#10217](https://github.com/netbox-community/netbox/issues/10217) - Handle exception when trace splits to multiple rear ports
|
* [#10217](https://github.com/netbox-community/netbox/issues/10217) - Handle exception when trace splits to multiple rear ports
|
||||||
|
* [#10220](https://github.com/netbox-community/netbox/issues/10220) - Validate IP version when assigning primary IPs to a virtual machine
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -368,9 +368,14 @@ class VirtualMachine(NetBoxModel, ConfigContextModel):
|
|||||||
|
|
||||||
# Validate primary IP addresses
|
# Validate primary IP addresses
|
||||||
interfaces = self.interfaces.all()
|
interfaces = self.interfaces.all()
|
||||||
for field in ['primary_ip4', 'primary_ip6']:
|
for family in (4, 6):
|
||||||
|
field = f'primary_ip{family}'
|
||||||
ip = getattr(self, field)
|
ip = getattr(self, field)
|
||||||
if ip is not None:
|
if ip is not None:
|
||||||
|
if ip.address.version != family:
|
||||||
|
raise ValidationError({
|
||||||
|
field: f"Must be an IPv{family} address. ({ip} is an IPv{ip.address.version} address.)",
|
||||||
|
})
|
||||||
if ip.assigned_object in interfaces:
|
if ip.assigned_object in interfaces:
|
||||||
pass
|
pass
|
||||||
elif ip.nat_inside is not None and ip.nat_inside.assigned_object in interfaces:
|
elif ip.nat_inside is not None and ip.nat_inside.assigned_object in interfaces:
|
||||||
|
Reference in New Issue
Block a user