Skip to content
Discussion options

You must be logged in to vote

How do I get a list of devices (dcim.device) whose primary IP addresses are in a certain prefix (ipam.prefix) using the REST API?

The available filters on /api/dcim/devices/ are in the source code here.

The only query params which relate to primary ip are has_primary_ip, primary_ip4_id and primary_ip6_id.

However...

If this is not possible, is it possible to get a list of IP addresses that are in a certain prefix?

Yes. To find all the IP addresses within prefix 192.168.1.0/24, you would call /api/ipam/ip-addresses/?parent=192.168.1.0%2F24 - code reference here.

Furthermore, you'll find each returned IP address has an assigned_object field, which will tell you the interface and device …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@drygdryg
Comment options

Answer selected by drygdryg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants