Allow multiple search terms when searching for IP addresses #2893

Closed
opened 2025-12-29 18:23:11 +01:00 by adam · 5 comments
Owner

Originally created by @muroj on GitHub (Sep 21, 2019).

Originally assigned to: @kobayashi on GitHub.

Environment

  • Python version: Python 3.6.8
  • NetBox version: NetBox 2.6.3

Proposed Functionality

It would be useful to perform a bulk attribute update on a range of IP's within a subnet. For example, adding (or removing) tag tester-tom to addresses 10.20.102.[50-100]. Right now the IP search is string based (#1620), so searching for 10.20.102.5 will find addresses 10.20.102.5,[10.20.102.50-10.20.102.59], [10.20.102.500-599]. In this scenario, to assign hosts 10.20.102.50/24-10.20.102.100/24 to Tester Tom, we have to perform five searches: 10.20.102.[5,6,7,8,9]: for each search, select all addresses matching the query -> Edit All -> Add/Remove Tags -> Save. One suggestion is to allow the range syntax that is supported on the IP bulk add UI: i.e. 10.20.102.[50-100]. Yet another suggestion, allow for multiple comma-separated search strings e.g.: 10.20.102.5,10.20.102.6.

Use Case

We oftentimes designate blocks of IP addresses within a subnet for certain purposes. For example, within a given subnet we may assign fifty contiguous addresses for use by a particular developer/tester, or for exclusive use by VMs on a given host system. We plan on "assigning" the IPs using tags, as I don't see a concept of IP "ownership" within netbox (although maybe I can use the custom data feature). These designations change fairly rapidly, so the multiple/search update workflow will become very tedious.

This request seems similar to #1410 (but is different), and is somewhat related to #834

Originally created by @muroj on GitHub (Sep 21, 2019). Originally assigned to: @kobayashi on GitHub. ### Environment * Python version: Python 3.6.8 * NetBox version: NetBox 2.6.3 ### Proposed Functionality It would be useful to perform a bulk attribute update on a range of IP's within a subnet. For example, adding (or removing) tag `tester-tom` to addresses `10.20.102.[50-100]`. Right now the IP search is string based (#1620), so searching for `10.20.102.5` will find addresses `10.20.102.5,[10.20.102.50-10.20.102.59], [10.20.102.500-599]`. In this scenario, to assign hosts `10.20.102.50/24-10.20.102.100/24` to Tester Tom, we have to perform five searches: `10.20.102.[5,6,7,8,9]`: for each search, select all addresses matching the query -> Edit All -> Add/Remove Tags -> Save. One suggestion is to allow the range syntax that is supported on the IP bulk add UI: i.e. `10.20.102.[50-100]`. Yet another suggestion, allow for multiple comma-separated search strings e.g.: `10.20.102.5,10.20.102.6`. ### Use Case We oftentimes designate blocks of IP addresses within a subnet for certain purposes. For example, within a given subnet we may assign fifty contiguous addresses for use by a particular developer/tester, or for exclusive use by VMs on a given host system. We plan on "assigning" the IPs using tags, as I don't see a concept of IP "ownership" within netbox (although maybe I can use the custom data feature). These designations change fairly rapidly, so the multiple/search update workflow will become very tedious. This request seems similar to #1410 (but is different), and is somewhat related to #834
adam added the status: acceptedtype: feature labels 2025-12-29 18:23:11 +01:00
adam closed this issue 2025-12-29 18:23:12 +01:00
Author
Owner

@DanSheps commented on GitHub (Sep 23, 2019):

The comma syntax would diverge from the API where we use commas to designate "and" logic.

I think regex would be the best solution for this, if we took it up.

@DanSheps commented on GitHub (Sep 23, 2019): The comma syntax would diverge from the API where we use commas to designate "and" logic. I think regex would be the best solution for this, if we took it up.
Author
Owner

@jeremystretch commented on GitHub (Oct 17, 2019):

It should be possible to pass the address filter multiple times in a URL to OR multiple values. However, I think this is not currently possible because we're using a method filter for this field.

Additionally, I'll note that the parent filter allows you to find all IPs within a given prefix.

@jeremystretch commented on GitHub (Oct 17, 2019): It should be possible to pass the `address` filter multiple times in a URL to `OR` multiple values. However, I think this is not currently possible because we're using a method filter for this field. Additionally, I'll note that the `parent` filter allows you to find all IPs within a given prefix.
Author
Owner

@jeremystretch commented on GitHub (Dec 13, 2019):

Marking this accepted with the understanding that it entails improving the current filter behavior to allow multiple parameters. For example, /api/ipam/ip-address/?address=192.0.2.1&address=192.0.2.2 should return IPs matching either address.

@jeremystretch commented on GitHub (Dec 13, 2019): Marking this accepted with the understanding that it entails improving the current filter behavior to allow multiple parameters. For example, `/api/ipam/ip-address/?address=192.0.2.1&address=192.0.2.2` should return IPs matching either address.
Author
Owner

@kobayashi commented on GitHub (Dec 23, 2019):

Is this issue for filtering multiple ipaddresses? Or more enhancement mentioned in original proposal?

@kobayashi commented on GitHub (Dec 23, 2019): Is this issue for filtering multiple ipaddresses? Or more enhancement mentioned in original proposal?
Author
Owner

@kobayashi commented on GitHub (Dec 26, 2019):

Take a look at ipam/filters.py,

We can do address filtering like this with a new custom lookups.

def filter_address(self, queryset, name, value):
    address_prefix, address_nonprefix = [], []
    try:
        for address in value:
            if '/' in address:
                address_prefix.append(address)
            else:
                address_nonprefix.append(address)

        return queryset.filter(
            Q(address__in=address_prefix) |
            Q(address__net_host_list=address_nonprefix)
        )

    except ValidationError:
        return queryset.none()
@kobayashi commented on GitHub (Dec 26, 2019): Take a look at `ipam/filters.py`, We can do address filtering like this with a new custom lookups. ``` def filter_address(self, queryset, name, value): address_prefix, address_nonprefix = [], [] try: for address in value: if '/' in address: address_prefix.append(address) else: address_nonprefix.append(address) return queryset.filter( Q(address__in=address_prefix) | Q(address__net_host_list=address_nonprefix) ) except ValidationError: return queryset.none() ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2893