Skip to content

Add IP/network conversion and subnetting jinja filters#69231

Open
ggiesen wants to merge 2 commits into
saltstack:masterfrom
ggiesen:add-ip-int-jinja-filters
Open

Add IP/network conversion and subnetting jinja filters#69231
ggiesen wants to merge 2 commits into
saltstack:masterfrom
ggiesen:add-ip-int-jinja-filters

Conversation

@ggiesen
Copy link
Copy Markdown
Contributor

@ggiesen ggiesen commented May 27, 2026

What does this PR do?

Adds seven Jinja filters to salt.utils.network, all implemented with the
standard-library ipaddress module:

  • ip_to_int / int_to_ipv4 / int_to_ipv6 — convert between an IPv4/IPv6 address and its integer representation
  • nth_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 given
  • cidr_merge — merge a list of addresses/networks into the minimal covering set, or (with action="span") the single smallest containing network
  • slaac — derive an IPv6 SLAAC address from a network and a MAC address using modified EUI-64

What 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 in
tests/pytests/unit/utils/test_network.py.

Merge requirements satisfied?

  • Docs
  • Changelog
  • Tests written/updated

Commits signed with GPG?

No

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.
@ggiesen ggiesen requested a review from a team as a code owner May 27, 2026 01:56
@ggiesen
Copy link
Copy Markdown
Contributor Author

ggiesen commented May 27, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants