Repository navigation
sources: look up existing IP addresses by address instead of a full scan - #622
Open
tyderian1978 wants to merge 1 commit into
Open
tyderian1978 wants to merge 1 commit into
tyderian1978 wants to merge 1 commit into
Conversation
add_update_interface() scanned every IP address in the inventory for each address a source reported, once to find the existing object and, with skip_fhrp_group_ips, once more for an FHRP group binding. Where NetBox is fed from an IPAM the inventory holds tens of thousands of IPs; with ~36,000 that scan was about a tenth of a vCenter run. SourceBase.ip_address_objects_for() keeps an index by address (without prefix length) and returns the candidates in inventory order. The inventory only appends, so the index catches up with objects added since the last lookup. The matching logic and its order are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: AI generated, based off the work we're doing with Netbox.
What happens
For every address a source reports,
add_update_interface()scans every IP address in the inventory to find the existing object, and withskip_fhrp_group_ipsonce more for an FHRP group binding. Where NetBox is fed from an IPAM, the inventory holds tens of thousands of IPs; with our ~36,000, that scan was about a tenth of a vCenter run.Fix
SourceBase.ip_address_objects_for(address)keeps an index by address (without prefix length) and returns the candidates in inventory order, so the matching logic and its order are unchanged; both scans use it, and the loop still checks each candidate's address as before. The inventory only appends during a run, so the index catches up with the objects added since the last lookup instead of being rebuilt.Tests
tests/test_ip_address_index.py: the same candidates in the same order as a full scan (IPv4 and IPv6, several prefix lengths of one address, an address that is a prefix of another as a string), and objects added after the first lookup are found. Both fail ondevelopmentwithout the change. Full suite: 609 passed, 8 skipped; the FHRP tests (test_fhrp_ip_binding.py) pass unchanged.Together with the vCenter tag cache (separate PR), a dry run against our production NetBox and vCenters went from 38 min 45 s to 27 min 42 s, with identical planned changes.