Skip to content

get-prefixes (and probably others) ignores next field and therefor only returns first 1000 entries #54

@nickper

Description

@nickper

I noticed that the library does nothing with the provided next field of the api, and therefor stays quiet about the fact that not all values were returned.
Can something be added (an extra key for example) which automatically request the next url (based on the next field) and add it to the to return list.

https://127.0.0.1/api/ipam/prefixes/

HTTP 200 OK
Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 1160,
    "next": "https://127.0.0.1/api/ipam/prefixes/?limit=1000?offset=1000",

https://127.0.0.1/api/ipam/prefixes/?limit=1000?offset=1000

HTTP 200 OK
Allow: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 1160,
    "next": "https://127.0.0.1/api/ipam/prefixes/?limit=1000&offset=2000",
    "previous": "https://127.0.0.1/api/ipam/prefixes/?limit=1000",

I now do this as temporary solution

prefixes = []
offset_num = 0
while 1:
    templist = netbox.ipam.get_ip_prefixes(offset=offset_num)
    if templist:
        prefixes.extend(templist)
        offset_num += 1000
        templist = []
    else:
        break

The loop continues until an empty list is returned, which requires an extra unnecessary api call.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions