Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: netaddr is_private method deprecation #338

Merged
merged 7 commits into from
Mar 13, 2024

Conversation

rizlas
Copy link
Contributor

@rizlas rizlas commented Mar 1, 2024

SUMMARY

Fix: #331

Netaddr has removed is_private method. This PR aims to fix it using is_global method instead that support both IPv4 and IPv6.

First argument of _private_query is IPNetwork that's why .ip (v.ip) attribute is used. Otherwise is_global function is not available (see below for more infos).

Backward compatibility is maintained till netaddr 0.10.0. Not before.

Netaddr changelog: https://netaddr.readthedocs.io/en/latest/changes.html#release-1-0-0

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ipaddr_utils.py

ADDITIONAL INFORMATION

Install netaddr > 1.0.0 and use ansible.utils.ipaddr('private') to reproduce.

Object attributes of IPNetwork.ip (only notable):

'ipv4', 'ipv6', 'is_global', 'is_hostmask', 'is_ipv4_compat', 'is_ipv4_mapped', 'is_ipv4_private_use', 'is_ipv6_unique_local', 'is_link_local', 'is_loopback', 'is_multicast', 'is_netmask', 'is_reserved', 'is_unicast'

Object attributes of IPAddress class (only notable):

'ipv4', 'ipv6', 'is_global', 'is_hostmask', 'is_ipv4_compat', 'is_ipv4_mapped', 'is_ipv4_private_use', 'is_ipv6_unique_local', 'is_link_local', 'is_loopback', 'is_multicast', 'is_netmask', 'is_reserved', 'is_unicast'

Copy link
Contributor

@RPDiep
Copy link

RPDiep commented Mar 5, 2024

LGTM; this would fix our problems as well. Need a review from a reviewer though.

@sean-m-sullivan
Copy link

LGTM; this would fix our problems as well. Need a review from a reviewer though.

@rizlas
Copy link
Contributor Author

rizlas commented Mar 8, 2024

Hi,
test is failing due to a wrong expected result:

https://github.com/ansible-collections/ansible.utils/blob/main/tests/integration/targets/utils_ipaddr_filter/vars/main.yaml#L29

ipaddr_result3:
  - 192.24.2.1
  - 2001:db8:32c:faad::/64

The IPv6 is reserved for documentation purposes and is not globally reachable and cannot be assigned by an isp (https://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.xhtml). Therefore we can deduce that is not "public".

The range is also present in netaddr ip class https://github.com/netaddr/netaddr/blob/master/netaddr/ip/__init__.py#L2067.

Finally, please do note that is_global method is available since netaddr 0.10.0.

About PR I don't know how the value - "42540766412265424405338506004571095040/64" is "parsed", without @ashwini-mhatre and @Ruchip16 support I can't do any further adjustment.

Thank you

@farwarx
Copy link

farwarx commented Mar 13, 2024

Hi, anynews on the PR?
It's a blocking issue for many ansible colletion like Zabbix for example.
Regards ;)

@ashwini-mhatre
Copy link
Contributor

@rizlas could you please add changelog

@rizlas
Copy link
Contributor Author

rizlas commented Mar 13, 2024

Yeah, on it! Thank you

Copy link
Contributor

@rizlas
Copy link
Contributor Author

rizlas commented Mar 13, 2024

Should I also change this to netaddr>=0.10.1?

Edit: I changed netaddr minimum version. I'll just revert if you don't like it 😅

Copy link
Contributor

@ashwini-mhatre ashwini-mhatre merged commit c176c23 into ansible-collections:main Mar 13, 2024
56 checks passed
freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this pull request May 15, 2024
net/py-netaddr 1.2.1 deprecated and removed the is_private method.
This breaks ansible-collections which is bundled this port's tarball.
The upstream patch uses the is_global methhod instead.

Reported by:	Einar Bjarni Halldorsson <einar@isnic.is>
Obtained from:	ansible-collections/ansible.utils#338
freebsd-git pushed a commit to freebsd/freebsd-ports that referenced this pull request May 15, 2024
net/py-netaddr 1.2.1 deprecated and removed the is_private method.
This breaks ansible-collections which is bundled this port's tarball.
The upstream patch uses the is_global methhod instead.

Reported by:	Einar Bjarni Halldorsson <einar@isnic.is>
Obtained from:	ansible-collections/ansible.utils#338

(cherry picked from commit 698ed6d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

breaking changes in netaddr
5 participants