Add IP/network conversion and subnetting jinja filters#69231
Open
ggiesen wants to merge 2 commits into
Open
Conversation
Add the following salt.utils.network helpers, exposed as Jinja filters: - ip_to_int: integer for an IPv4 or IPv6 address - int_to_ipv4: IPv4 address for an integer - int_to_ipv6: IPv6 address for an integer - nth_host: the Nth address within a network - network_subnets: split a network into subnets of a given prefix length - cidr_merge: merge a list of addresses or networks (merge or span) - slaac: IPv6 SLAAC address from a network and MAC (modified EUI-64) All are implemented with the standard library ipaddress module. Includes unit tests and documentation.
Contributor
Author
|
Base rationale: targeting master, as this adds new functionality (IP/network conversion and subnetting jinja filters), which per Salt's contributing guide goes to master rather than a release branch. |
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.
What does this PR do?
Adds seven Jinja filters to
salt.utils.network, all implemented with thestandard-library
ipaddressmodule:ip_to_int/int_to_ipv4/int_to_ipv6— convert between an IPv4/IPv6 address and its integer representationnth_host— the Nth address within a network (network address is index 0; negative indexes count from the end)network_subnets— split a network into subnets of a given prefix length; returns the subnet count, or the Nth subnet when an index is givencidr_merge— merge a list of addresses/networks into the minimal covering set, or (withaction="span") the single smallest containing networkslaac— derive an IPv6 SLAAC address from a network and a MAC address using modified EUI-64What issues does this PR fix or reference?
None
New Behavior
Seven new Jinja filters as described above, documented in
doc/topics/jinja/index.rst, with unit tests intests/pytests/unit/utils/test_network.py.Merge requirements satisfied?
Commits signed with GPG?
No