Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jul 14, 2023
1 parent 41a2e1c commit d449236
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Name | Description
[ansible.utils.index_of](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.index_of_filter.rst)|Find the indices of items in a list matching some criteria
[ansible.utils.ip4_hex](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.ip4_hex_filter.rst)|This filter is designed to convert IPv4 address to Hexadecimal notation with optional delimiter.
[ansible.utils.ipaddr](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.ipaddr_filter.rst)|This filter is designed to return the input value if a query is True, else False.
[ansible.utils.ipcut](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.ipcut_filter.rst)|This filter is designed to get 1st or last few bits of IP address.
[ansible.utils.ipmath](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.ipmath_filter.rst)|This filter is designed to do simple IP math/arithmetic.
[ansible.utils.ipsubnet](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.ipsubnet_filter.rst)|This filter can be used to manipulate network subnets in several ways.
[ansible.utils.ipv4](https://github.com/ansible-collections/ansible.utils/blob/main/docs/ansible.utils.ipv4_filter.rst)|To filter only Ipv4 addresses Ipv4 filter is used.
Expand Down
11 changes: 6 additions & 5 deletions plugins/filter/ipcut.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

try:
import netaddr

HAS_NETADDR = True
except ImportError:
# in this case, we'll make the filters return error messages (see bottom)
Expand Down Expand Up @@ -99,15 +100,15 @@ def ipcut(value, amount):
)
raise AnsibleFilterError(msg)
else:
if amount<0:
if amount < 0:
ipsub = ipv6address[amount:]
else:
else:
ipsub = ipv6address[0:amount]
ipsubfinal = [(ipsub[i:i+16]) for i in range(0, len(ipsub), 16)]

ipsubfinal = [(ipsub[i : i + 16]) for i in range(0, len(ipsub), 16)]
for i in ipsubfinal:
x = hex(int(i, 2))
ipv6_oct.append(x.replace('0x', ''))
ipv6_oct.append(x.replace("0x", ""))
return str(":".join(ipv6_oct))


Expand Down

0 comments on commit d449236

Please sign in to comment.