Skip to content

Commit

Permalink
Do not filter IP addresses by VRF as default
Browse files Browse the repository at this point in the history
By default, we don't filter IP address information from Netbox by VRF.

Previously, we used `None` as the default for `vrf_id` to avoid this filtering.
However, from pynetbox v7.4.0, `None` will be replaced by `'null'`.
Using `'null'` will only retrieve addresses that do not have a VRF configured, so the default behavior has changed unintentionally.

This commit will remove `vrf_id` from the query parameter by default.
  • Loading branch information
mochipon committed Aug 15, 2024
1 parent 7c19022 commit 1d0afa6
Showing 1 changed file with 30 additions and 12 deletions.
42 changes: 30 additions & 12 deletions octodns_netbox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,22 @@ def _populate_PTR(self, zone: Zone, family: Literal[4, 6]) -> typing.List[Rr]:
ret = []
network = octodns_netbox.reversename.to_network(zone)

kw = {f"{self.field_name}__empty": "false"}
ipam_records = self._nb_client.ipam.ip_addresses.filter(
parent=network.compressed,
family=family,
vrf_id=self.populate_vrf_id,
tag=self.populate_tags,
**kw,
)
kw = {
f"{self.field_name}__empty": "false",
"parent": network.compressed,
"family": family,
"vrf_id": self.populate_vrf_id,
"tag": self.populate_tags,
}

# https://github.com/netbox-community/pynetbox/pull/545
# From pynetbox v7.4.0, None will be mapped to null.
# When vrf_id is null, it does not mean that it is not filtered by vrf_id,
# but it would be an intention that VRF is not set.
if kw["vrf_id"] is None:
kw.remove("vrf_id")

ipam_records = self._nb_client.ipam.ip_addresses.filter(**kw)

for ipam_record in ipam_records:
ip_address = ip_interface(ipam_record.address).ip
Expand All @@ -188,10 +196,20 @@ def _populate_PTR(self, zone: Zone, family: Literal[4, 6]) -> typing.List[Rr]:
def _populate_normal(self, zone: Zone) -> typing.List[Rr]:
ret = []

kw = {f"{self.field_name}__ic": zone.name[:-1]}
ipam_records = self._nb_client.ipam.ip_addresses.filter(
vrf_id=self.populate_vrf_id, tag=self.populate_tags, **kw
)
kw = {
f"{self.field_name}__ic": zone.name[:-1],
"vrf_id": self.populate_vrf_id,
"tag": self.populate_tags,
}

# https://github.com/netbox-community/pynetbox/pull/545
# From pynetbox v7.4.0, None will be mapped to null.
# When vrf_id is null, it does not mean that it is not filtered by vrf_id,
# but it would be an intention that VRF is not set.
if kw["vrf_id"] is None:
kw.remove("vrf_id")

ipam_records = self._nb_client.ipam.ip_addresses.filter(**kw)

for ipam_record in ipam_records:
ip_address = ip_interface(ipam_record.address).ip
Expand Down

0 comments on commit 1d0afa6

Please sign in to comment.