From dae154531b22ae9067c8a06965ec676febed745b Mon Sep 17 00:00:00 2001 From: mattycarroll Date: Thu, 2 May 2019 15:46:42 +0000 Subject: [PATCH] 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 --- filter_plugins/osa-filter.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 filter_plugins/osa-filter.py diff --git a/filter_plugins/osa-filter.py b/filter_plugins/osa-filter.py new file mode 100644 index 00000000..944e3152 --- /dev/null +++ b/filter_plugins/osa-filter.py @@ -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 + }