Add bit_length_power_of_2 to filters folder

We are moving this filter into this repository because it's only
usage is here. It will then be removed from openstack-ansible-plugins.

Patch set 2: Fix whitespace

Change-Id: I543328db49dc6b7bbb05878503dbb3d337a18558
Related-Bug: #1826242
This commit is contained in:
mattycarroll 2019-05-02 15:46:42 +00:00 committed by Jonathan Rosser
parent 145038ab78
commit dae154531b
1 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,17 @@
def bit_length_power_of_2(value):
"""Return the smallest power of 2 greater than a numeric value.
:param value: Number to find the smallest power of 2
:type value: ``int``
:returns: ``int``
"""
return 2**(int(value) - 1).bit_length()
class FilterModule(object):
"""Ansible jinja2 filters."""
@staticmethod
def filters():
return {
'bit_length_power_of_2': bit_length_power_of_2
}