Skip to content

Search for IP address with given address and pagination #19

Description

@Cosaquee

Hi! First of all, thanks for you library it is really awesome! Everything works nicely.

I'm making OpenStack to NetBox exporter and I want to check if IP address with given IP exists or not. I can obtain all ip addresses and then search if there is object with address same as one I obtain from OpenStack but I wonder if there is a way to search for IP with given address. It is not a big issue but requesting couple of thousands IP addresses and search in them is not so effective as one search query.

I tried NetboxClientRuby.ipam.ip_addresses.filter(address: '192.168.4.40/24') but it doesn't work for me.

Pagination also seems to be not documented(just one entry in example config file). It would be really nice to see an example code block about working with pagination IPAM module.

EDIT: Ok, in code I found out that you can use #all method to get all objects. But you need to remember to set your MAX_PAGE_SIZE to 0 in configuration.py in your NetBox installation if you want to get all objects at once from api.

So is it possible?

Activity

  1. changed the title [-]Search for IP address with given address[/-] [+]Search for IP address with given address and pagination[/+] on Dec 20, 2017
  2. cimnine commented on Jan 17, 2018

    @cimnine
    Contributor

    To work with the pagination, you can do:

    NetboxClientRuby.ipam.ip_addresses.limit(100).offset(100) # addresses 101 - 200
    # or
    NetboxClientRuby.ipam.ip_addresses.page(0) # first page

    limit and offset work just like documented in netbox. page is a convenience method, which just calculates the offset from the current (default) limit.

  3. cimnine commented on Jan 17, 2018

    @cimnine
    Contributor

    As for this one:

    I tried NetboxClientRuby.ipam.ip_addresses.filter(address: '192.168.4.40/24') but it doesn't work for me.

    You're using the API wrong.

    In you browser, go to http://YOUR_NETBOX/api/ipam/ip-addresses/?address=192.168.4.40/24. You'll see that all IPs you have in there are returned.

    But if you go to http://YOUR_NETBOX/api/ipam/ip-addresses/?q=192.168.4.40/24 instead, you'll see that only the one IP is returned.

  4. cimnine commented on Jan 17, 2018

    @cimnine
    Contributor

    Btw, I'm sorry for the long response time. I did not see that someone opened an issue.

  5. locked and limited conversation to collaborators on May 26, 2025
  6. converted this issue into a discussion #105 on May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions