From ecb4419225c434e23ca7e89bb6e019a9177a5e96 Mon Sep 17 00:00:00 2001 From: pl0xym0r <148605740+pl0xym0r@users.noreply.github.com> Date: Sun, 10 Nov 2024 09:54:58 +0000 Subject: [PATCH 1/2] add is_oob parameter on bulk_import ipaddress --- netbox/ipam/forms/bulk_import.py | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index dea250c7921..99c36d68766 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -326,12 +326,17 @@ class IPAddressImportForm(NetBoxModelImportForm): help_text=_('Make this the primary IP for the assigned device'), required=False ) + is_oob = forms.BooleanField( + label=_('Is Out-Of-Band'), + help_text=_('Make this the Out-Of-Band IP for the assigned device'), + required=False + ) class Meta: model = IPAddress fields = [ 'address', 'vrf', 'tenant', 'status', 'role', 'device', 'virtual_machine', 'interface', 'is_primary', - 'dns_name', 'description', 'comments', 'tags', + 'is_oob', 'dns_name', 'description', 'comments', 'tags', ] def __init__(self, data=None, *args, **kwargs): @@ -345,7 +350,7 @@ def __init__(self, data=None, *args, **kwargs): **{f"device__{self.fields['device'].to_field_name}": data['device']} ) - # Limit interface queryset by assigned device + # Limit interface queryset by assigned VM elif data.get('virtual_machine'): self.fields['interface'].queryset = VMInterface.objects.filter( **{f"virtual_machine__{self.fields['virtual_machine'].to_field_name}": data['virtual_machine']} @@ -358,16 +363,29 @@ def clean(self): virtual_machine = self.cleaned_data.get('virtual_machine') interface = self.cleaned_data.get('interface') is_primary = self.cleaned_data.get('is_primary') + is_oob = self.cleaned_data.get('is_oob') - # Validate is_primary + # Validate is_primary and is_oob if is_primary and not device and not virtual_machine: raise forms.ValidationError({ "is_primary": _("No device or virtual machine specified; cannot set as primary IP") }) + if is_oob and not device: + raise forms.ValidationError({ + "is_oob": _("No device specified; cannot set as out-of-band IP") + }) + if is_oob and virtual_machine: + raise forms.ValidationError({ + "is_oob": _("Cannot set out-of-band IP on VM") + }) if is_primary and not interface: raise forms.ValidationError({ "is_primary": _("No interface specified; cannot set as primary IP") }) + if is_oob and not interface: + raise forms.ValidationError({ + "is_oob": _("No interface specified; cannot set as out-of-band IP") + }) def save(self, *args, **kwargs): @@ -386,6 +404,12 @@ def save(self, *args, **kwargs): parent.primary_ip6 = ipaddress parent.save() + # Set as OOB for device + if self.cleaned_data.get('is_oob'): + parent = self.cleaned_data.get('device') + parent.oob_ip = ipaddress + parent.save() + return ipaddress From e35a43014fa95f43e35f5ee1f2041a7cce8c1b01 Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Mon, 9 Dec 2024 10:12:55 -0500 Subject: [PATCH 2/2] Tweak wording --- netbox/ipam/forms/bulk_import.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/netbox/ipam/forms/bulk_import.py b/netbox/ipam/forms/bulk_import.py index 99c36d68766..749ab9ccff4 100644 --- a/netbox/ipam/forms/bulk_import.py +++ b/netbox/ipam/forms/bulk_import.py @@ -327,8 +327,8 @@ class IPAddressImportForm(NetBoxModelImportForm): required=False ) is_oob = forms.BooleanField( - label=_('Is Out-Of-Band'), - help_text=_('Make this the Out-Of-Band IP for the assigned device'), + label=_('Is out-of-band'), + help_text=_('Designate this as the out-of-band IP address for the assigned device'), required=False ) @@ -376,7 +376,7 @@ def clean(self): }) if is_oob and virtual_machine: raise forms.ValidationError({ - "is_oob": _("Cannot set out-of-band IP on VM") + "is_oob": _("Cannot set out-of-band IP for virtual machines") }) if is_primary and not interface: raise forms.ValidationError({