Skip to content
Discussion options

You must be logged in to vote

There's no direct link between device or virtual machine and VLAN. The relationships you have are:

  • device -> interfaces -> IPs -> prefix -> VLAN
  • virtualmachine -> vminterfaces -> IPs -> prefix -> VLAN

So you need to first do a query which finds all prefixes in the VLAN of interest:

>>> v = nb.ipam.vlans.get(name='mgmt-dmz')
>>> v.id
2
>>> p = list(nb.ipam.prefixes.filter(vlan_id=2))
>>> p
[10.12.255.0/24, 2001:db8::/64]

Then you need to do a query to find all the IP addresses within each prefix, and see which ones have been assigned to a device interface or vm interface.

>>> i = list(nb.ipam.ip_addresses.filter(parent="10.12.255.0/24"))
>>> len(i)
49
>>> len([j for j in i if j.assigned…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@nlameiras
Comment options

@candlerb
Comment options

Answer selected by nlameiras
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