Skip to content

Commit

Permalink
Merge pull request #10235 from netbox-community/10220-vm-primary-ips
Browse files Browse the repository at this point in the history
Fixes #10220: Validate IP version when assigning primary IPs to a VM
  • Loading branch information
jeremystretch authored Sep 1, 2022
2 parents 899b612 + d818c25 commit bb269af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release-notes/version-3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [#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
* [#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

---

Expand Down
7 changes: 6 additions & 1 deletion netbox/virtualization/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,14 @@ def clean(self):

# Validate primary IP addresses
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)
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:
pass
elif ip.nat_inside is not None and ip.nat_inside.assigned_object in interfaces:
Expand Down

0 comments on commit bb269af

Please sign in to comment.