Skip to content

Expose cidr_to_ipv4_netmask as a Jinja filter#69538

Merged
dwoz merged 2 commits into
saltstack:masterfrom
ggiesen:add-cidr-to-ipv4-netmask-jinja-filter
Jun 27, 2026
Merged

Expose cidr_to_ipv4_netmask as a Jinja filter#69538
dwoz merged 2 commits into
saltstack:masterfrom
ggiesen:add-cidr-to-ipv4-netmask-jinja-filter

Conversation

@ggiesen

@ggiesen ggiesen commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Exposes the existing salt.utils.network.cidr_to_ipv4_netmask() function as a Jinja filter so templates can render a dotted-decimal IPv4 netmask from a CIDR prefix length:

{{ 24 | cidr_to_ipv4_netmask }}

renders 255.255.255.0.

What issues does this PR fix or reference?

Follow-up to #69231, which added the other IP/network Jinja filters. cidr_to_ipv4_netmask() has shipped in salt.utils.network for years; only the @jinja_filter registration was missing, so it could be called from Python but not used as a Jinja filter.

Previous Behavior

cidr_to_ipv4_netmask() was not registered as a Jinja filter, so {{ prefix | cidr_to_ipv4_netmask }} raised an undefined-filter error.

New Behavior

The function is registered with @jinja_filter("cidr_to_ipv4_netmask") (the decorator is already imported in salt/utils/network.py), documented alongside the other network filters, and covered by a test asserting it is registered. No behavior change to the function itself.

Merge requirements satisfied?

  • Tests written/updated (registration test fails without the decorator, passes with it; the existing function-correctness test is unchanged)
  • Changelog entry
  • Documentation added (doc/topics/jinja/index.rst)

Commits signed with GPG?

No

salt.utils.network.cidr_to_ipv4_netmask() has existed for years but was
never registered as a Jinja filter, so templates could not render a
dotted-decimal netmask from a CIDR prefix length with
`{{ prefix | cidr_to_ipv4_netmask }}`. Add the @jinja_filter decorator
(the import is already present), document it alongside the other network
filters, and test that it is registered.

Follow-up to saltstack#69231, which added the rest of the IP/network jinja filters.
@dwoz dwoz added the test:full Run the full test suite label Jun 26, 2026
@dwoz dwoz merged commit 67acd27 into saltstack:master Jun 27, 2026
984 of 1030 checks passed
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