Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple search terms when searching for IP addresses #3525

Closed
muroj opened this issue Sep 20, 2019 · 5 comments · Fixed by #3847
Closed

Allow multiple search terms when searching for IP addresses #3525

muroj opened this issue Sep 20, 2019 · 5 comments · Fixed by #3847
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@muroj
Copy link

muroj commented Sep 20, 2019

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

@DanSheps
Copy link
Member

DanSheps commented 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.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Oct 17, 2019
@jeremystretch
Copy link
Member

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
Copy link
Member

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 jeremystretch added status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Dec 13, 2019
@kobayashi
Copy link
Contributor

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

@kobayashi
Copy link
Contributor

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 kobayashi self-assigned this Dec 26, 2019
jeremystretch added a commit that referenced this issue Jan 14, 2020
Fixes #3525: Filter muiltiple ipaddress terms
@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants