diff --git a/CHANGELOG.md b/CHANGELOG.md index 2999d3e82..e3724ddf0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ v2.5.3 (FUTURE) ## Enhancements +* [#1630](https://github.com/digitalocean/netbox/issues/1630) - Enable bulk editing of prefix/IP mask length * [#2693](https://github.com/digitalocean/netbox/issues/2693) - Additional cable colors * [#2726](https://github.com/digitalocean/netbox/issues/2726) - Include cables in global search diff --git a/netbox/ipam/forms.py b/netbox/ipam/forms.py index 570716532..b6209f5df 100644 --- a/netbox/ipam/forms.py +++ b/netbox/ipam/forms.py @@ -422,6 +422,11 @@ class PrefixBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEditF required=False, label='VRF' ) + prefix_length = forms.IntegerField( + min_value=1, + max_value=127, + required=False + ) tenant = forms.ModelChoiceField( queryset=Tenant.objects.all(), required=False @@ -819,6 +824,11 @@ class IPAddressBulkEditForm(BootstrapMixin, AddRemoveTagsForm, CustomFieldBulkEd required=False, label='VRF' ) + mask_length = forms.IntegerField( + min_value=1, + max_value=128, + required=False + ) tenant = forms.ModelChoiceField( queryset=Tenant.objects.all(), required=False diff --git a/netbox/ipam/models.py b/netbox/ipam/models.py index 789e65b82..6f7a21236 100644 --- a/netbox/ipam/models.py +++ b/netbox/ipam/models.py @@ -385,6 +385,15 @@ class Prefix(ChangeLoggedModel, CustomFieldModel): self.description, ) + def _set_prefix_length(self, value): + """ + Expose the IPNetwork object's prefixlen attribute on the parent model so that it can be manipulated directly, + e.g. for bulk editing. + """ + if self.prefix is not None: + self.prefix.prefixlen = value + prefix_length = property(fset=_set_prefix_length) + def get_status_class(self): return STATUS_CHOICE_CLASSES[self.status] @@ -630,6 +639,15 @@ class IPAddress(ChangeLoggedModel, CustomFieldModel): self.description, ) + def _set_mask_length(self, value): + """ + Expose the IPNetwork object's prefixlen attribute on the parent model so that it can be manipulated directly, + e.g. for bulk editing. + """ + if self.address is not None: + self.address.prefixlen = value + mask_length = property(fset=_set_mask_length) + @property def device(self): if self.interface: