mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Fixes #8102: Raise validation error when attempting to assign an IP address to multiple objects
This commit is contained in:
@ -22,7 +22,7 @@
|
|||||||
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
|
* [#8088](https://github.com/netbox-community/netbox/issues/8088) - Improve legibility of text in labels with light-colored backgrounds
|
||||||
* [#8092](https://github.com/netbox-community/netbox/issues/8092) - Rack elevations should not include device asset tags
|
* [#8092](https://github.com/netbox-community/netbox/issues/8092) - Rack elevations should not include device asset tags
|
||||||
* [#8096](https://github.com/netbox-community/netbox/issues/8096) - Fix DataError during change logging of objects with very long string representations
|
* [#8096](https://github.com/netbox-community/netbox/issues/8096) - Fix DataError during change logging of objects with very long string representations
|
||||||
* [#8102](https://github.com/netbox-community/netbox/issues/8102) - Cause validation error when editing IPAddress when more than one object is selected for assignment
|
* [#8102](https://github.com/netbox-community/netbox/issues/8102) - Raise validation error when attempting to assign an IP address to multiple objects
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
@ -461,27 +461,16 @@ class IPAddressForm(TenancyForm, CustomFieldModelForm):
|
|||||||
def clean(self):
|
def clean(self):
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.cleaned_data['interface'] and self.cleaned_data['vminterface'] and self.cleaned_data['fhrpgroup']:
|
|
||||||
self.add_error('interface', "Can only assign an interface, VM interface or FHRP group")
|
|
||||||
self.add_error('vminterface', "Can only assign an interface, VM interface or FHRP group")
|
|
||||||
self.add_error('fhrpgroup', "Can only assign an interface, VM interface or FHRP group")
|
|
||||||
elif self.cleaned_data['interface'] and self.cleaned_data['vminterface']:
|
|
||||||
self.add_error('interface', "Can only assign an interface or VM interface")
|
|
||||||
self.add_error('vminterface', "Can only assign an interface or VM interface")
|
|
||||||
elif self.cleaned_data['interface'] and self.cleaned_data['fhrpgroup']:
|
|
||||||
self.add_error('interface', "Can only assign an interface or FHRP group")
|
|
||||||
self.add_error('fhrpgroup', "Can only assign an interface or FHRP group")
|
|
||||||
elif self.cleaned_data['vminterface'] and self.cleaned_data['fhrpgroup']:
|
|
||||||
self.add_error('vminterface', "Can only assign an VM interface or FHRP group")
|
|
||||||
self.add_error('fhrpgroup', "Can only assign an VM interface or FHRP group")
|
|
||||||
|
|
||||||
# Handle object assignment
|
# Handle object assignment
|
||||||
if self.cleaned_data['interface']:
|
selected_objects = [
|
||||||
self.instance.assigned_object = self.cleaned_data['interface']
|
field for field in ('interface', 'vminterface', 'fhrpgroup') if self.cleaned_data[field]
|
||||||
elif self.cleaned_data['vminterface']:
|
]
|
||||||
self.instance.assigned_object = self.cleaned_data['vminterface']
|
if len(selected_objects) > 1:
|
||||||
elif self.cleaned_data['fhrpgroup']:
|
raise forms.ValidationError({
|
||||||
self.instance.assigned_object = self.cleaned_data['fhrpgroup']
|
selected_objects[1]: "An IP address can only be assigned to a single object."
|
||||||
|
})
|
||||||
|
elif selected_objects:
|
||||||
|
self.instance.assigned_object = self.cleaned_data[selected_objects[0]]
|
||||||
|
|
||||||
# Primary IP assignment is only available if an interface has been assigned.
|
# Primary IP assignment is only available if an interface has been assigned.
|
||||||
interface = self.cleaned_data.get('interface') or self.cleaned_data.get('vminterface')
|
interface = self.cleaned_data.get('interface') or self.cleaned_data.get('vminterface')
|
||||||
|
Reference in New Issue
Block a user