Filter Prefixes when Role is null #1950

Closed
opened 2025-12-29 17:20:51 +01:00 by adam · 1 comment
Owner

Originally created by @gregbuehler on GitHub (Aug 16, 2018).

Environment

  • Python version: 2.7.12
  • NetBox version: 2.3.6

Proposed Functionality

As a user I would like to filter prefixes with no role set.

Use Case

Listing containers with no specified role:
curl -vLk https://netbox.example.com/api/ipam/prefixes/&role=&site=foo&status=0

Or using pynetbox:

import pynetbox
nb = pynetbox.api(
    'https://netbox.example.com',
    ssl_verify=False
)

for prefix in nb.ipam.prefixes.filter(role=None, site='foo', status=0):
    print(prefix)

Currently, there is post processing required to filter:

>>> raw = nb.ipam.prefixes.filter(site='foo', status=0)
>>> len(raw)
111
>>> e = [x for x in raw if x.role == None]
>>> len(e)
14

Database Changes

No expected changes required

External Dependencies

No external dependencies required.

Originally created by @gregbuehler on GitHub (Aug 16, 2018). ### Environment * Python version: 2.7.12 * NetBox version: 2.3.6 ### Proposed Functionality As a user I would like to filter prefixes with no role set. ### Use Case Listing containers with no specified role: `curl -vLk https://netbox.example.com/api/ipam/prefixes/&role=&site=foo&status=0` Or using `pynetbox`: ``` import pynetbox nb = pynetbox.api( 'https://netbox.example.com', ssl_verify=False ) for prefix in nb.ipam.prefixes.filter(role=None, site='foo', status=0): print(prefix) ``` Currently, there is post processing required to filter: ``` >>> raw = nb.ipam.prefixes.filter(site='foo', status=0) >>> len(raw) 111 >>> e = [x for x in raw if x.role == None] >>> len(e) 14 ``` ### Database Changes No expected changes required ### External Dependencies No external dependencies required.
adam closed this issue 2025-12-29 17:20:51 +01:00
Author
Owner

@jeremystretch commented on GitHub (Aug 16, 2018):

Filtering with role=0 will return only prefixes with no role assigned. 0 is used as a special value to signify null for many filters.

@jeremystretch commented on GitHub (Aug 16, 2018): Filtering with `role=0` will return only prefixes with no role assigned. `0` is used as a special value to signify `null` for many filters.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#1950