Merge "KVMFORNFV: Update Grafana config for Packet Forwarding test cases."
[yardstick.git] / ansible / filter_plugins / networks.py
1 # Copyright (c) 2017 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15
16 from urlparse import urlsplit
17
18
19 def do_prefix_to_netmask(arg):
20     return '.'.join(str((0xffffffff << (32 - int(arg)) >> i) & 0xff) for i in
21                     range(24, -8, -8))
22
23
24 def do_netmask_to_prefix(arg):
25     return sum([bin(int(x)).count('1') for x in arg.split('.')])
26
27
28 def do_urlsplit(arg):
29     return urlsplit(arg)
30
31
32 class FilterModule(object):
33     def filters(self):
34         return {
35             'prefix_to_netmask': do_prefix_to_netmask,
36             'netmask_to_prefix': do_netmask_to_prefix,
37             'urlsplit': do_urlsplit,
38         }