Skip to content

Commit

Permalink
Merge pull request #70 from sukiyaki/fix/vrf
Browse files Browse the repository at this point in the history
Do not filter IP addresses by VRF as default
  • Loading branch information
mochipon authored Aug 15, 2024
2 parents 7c19022 + 009ab25 commit 4cc1aec
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:
del kw["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:
del kw["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 4cc1aec

Please sign in to comment.