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

IP comparison functions #15

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

greatflyingsteve
Copy link

This is based on the work already submitted in #14, and includes another update to the PDK templates (although unfortunately not very much of one, this time). This adds some usefull functions for comparing and equality-testing IP addresses, both with equivalent functions for traditional boolean-return comparisons (>, >=, ==, <=, and <), and for use with functions like Puppet's sort(), which execute a block and expect one of -1, 0, or 1 as return to indicate whether the left operand is smaller than, equal to, or greater than the right, and will perform arbitrarily elaborate sorts accordingly.

My specific need for this was the sort() case to put a list of IP addresses in sorted order to (hopefully) match the output of a certain popularly-unpopular network management tool, and the others were just simple enough at that point that there wasn't a good reason NOT to include them (or at least, that's what I thought until I started writing docs for all of them, heh).

greatflyingsteve and others added 8 commits January 24, 2022 17:48
Initial commit of implementation and tests for ip_compare(), designed
for use with Puppet's `sort()` to sort a series of IP addresses into
binary-numerical order, regardless of the human-readable representation
in which they were originally written.
Initial commit of greater_than, equal_or_greater_than, equal_to,
equal_or_less_than, and less_than comparator functions and their unit
tests.
Important realization that made me feel kinda dumb: if you want to
handle the case of comparing with-prefix form to no-prefix form, you
can't just key your normalization pass off of both values being one or
the other.  Normalize each value individually, which solves the problem
correctly.
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.

None yet

1 participant