feat: migrate from IPy to netaddr for IP address handling#377
feat: migrate from IPy to netaddr for IP address handling#377
Conversation
Benchmarks realistic ACL-scale operations: object creation, containment, sorting, string roundtrip, host iteration, prefix introspection, and CIDR merging. Results: netaddr 1.3.0 wins 5/7 tests. IPy only wins sorting (3.5×) and prefix introspection (1.7×), both negligible at real ACL scale. Ref: #376
Replace IPy dependency with netaddr>=1.0.0,<2 across the entire codebase: - Rewrite TIP class to subclass netaddr.IPNetwork instead of IPy.IP - Update make_inverse_mask() to return netaddr.IPAddress - Handle partial IPv4 addresses (e.g. '10/8') by expanding octets - Prevent netaddr's iteration protocol from interfering with RangeList - Update inverse_mask_table in ios.py to use string keys - Replace IPy.IP() calls in global_settings.py, tools.py, netscreen.py, cmds.py - Update prefixlen() method calls to prefixlen property access - Update netmask() method calls to netmask property access Closes #376
Release PreviewNext Version: Changelog PreviewBug Fixes
Features
This version will be automatically released when this PR is merged to main. Reminder: Use conventional commits:
|
- cmds.py: Replace make_net=True with manual network/prefix construction in IPsubnet, and .make_net(mask) with f-string in _make_cidrs - acl/tools.py: Wrap addresses with TIP instead of plain netaddr.IPNetwork in _add_addr so strNormal() is available downstream - acl/support.py: Force /32 and /128 prefix display in junos_str output since TIP.__str__ omits prefix for non-negated single hosts
…_cidrs - _make_ipy, IPsubnet, and IPhost now return TIP objects instead of plain IPNetwork, preserving strNormal() compatibility for callers. - _make_cidrs now uses .cidr to zero out host bits, matching the old IPy.IP(make_net=True) behavior.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Summary
Migrate the entire codebase from the IPy library to netaddr for IP address handling.
Changes
netaddr.IPNetworkinstead ofIPy.IP10/8→10.0.0.0/8)net(),strNormal()) preserved for existing call sitesnetaddr.IPAddressinstead of TIP for raw integer maskstrigger/acl/ios.py): Uses string keys for consistent lookupprefixlen()→prefixlen,netmask()→netmask(netaddr uses properties)IPy>=1.01withnetaddr>=1.0.0,<2in pyproject.tomlTest Results
All 164 tests pass (excluding 2 pre-existing failures unrelated to this change:
test_pingandtest_reachabilityfail due to missingpingbinary in CI).Closes #376
Note
Medium Risk
Touches core ACL parsing/comparison and vendor-specific rendering paths; subtle differences between IPy and netaddr (string forms, containment, sorting) could change rule ordering or output in edge cases.
Overview
Switches Trigger’s IP/network primitive from IPy to netaddr across ACL parsing, output formatting, and interface parsing, including updating settings defaults and helper utilities to construct/compare networks using netaddr semantics.
Rewrites
TIPto subclassnetaddr.IPNetwork(withexcept/inactivehandling), updates prefix/netmask/inverse-mask logic and IOS inverse-mask parsing, and adds guards soTIPis not treated as an iterable/sequence byRangeList. Dependencies are updated to dropIPyin favor ofnetaddr, and a newbenchmarks/ipy_vs_netaddr.pyscript is added to compare performance on ACL-like workloads.Written by Cursor Bugbot for commit 9e4ff57. This will update automatically on new commits. Configure here.