Merge "Concurrency testcases to be configured over cli"
[yardstick.git] / ansible / filter_plugins / fuel_lookups.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 def do_find_fuel_nodes(fuel_nodes):
16     ips = {}
17     for fuel_node in fuel_nodes:
18         if 'controller' in fuel_node['roles']:
19             ips.setdefault("controller_ids", []).append(fuel_node['id'])
20             ips.setdefault("controllers_ips", []).append(fuel_node['ip'])
21         if 'compute' in fuel_node['roles']:
22             ips.setdefault("compute_ids", []).append(fuel_node['id'])
23             ips.setdefault("computes_ips", []).append(fuel_node['ip'])
24     return ips
25
26 # def do_find_fuel_nodes(fuel_output):
27 #     ips = {}
28 #     for l in fuel_output.splitlines():
29 #         splits = l.splti()
30 #         if 'controller' in l:
31 #             ips["controller_ids"] = splits[0]
32 #             ips["controllers_ips"] = splits[9]
33 #         if 'compute' in l:
34 #             ips["compute_ids"] = splits[0]
35 #             ips["computes_ips"] = splits[9]
36 #     return ips
37
38
39 class FilterModule(object):
40     def filters(self):
41         return {
42             'find_fuel_nodes': do_find_fuel_nodes,
43         }
44
45
46 SAMPLE = """\
47 id | status | name             | cluster | ip        | mac               | roles                | pending_roles | online | group_id
48 ---+--------+------------------+---------+-----------+-------------------+----------------------+---------------+--------+---------
49  4 | ready  | Untitled (9a:b1) |       1 | 10.20.0.6 | 0c:c4:7a:75:9a:b1 | ceph-osd, compute    |               |      1 |        1
50  1 | ready  | Untitled (9a:ab) |       1 | 10.20.0.4 | 0c:c4:7a:75:9a:ab | ceph-osd, controller |               |      1 |        1
51  5 | ready  | Untitled (9a:1b) |       1 | 10.20.0.7 | 0c:c4:7a:75:9a:1b | ceph-osd, compute    |               |      1 |        1
52  2 | ready  | Untitled (9a:67) |       1 | 10.20.0.3 | 0c:c4:7a:75:9a:67 | controller           |               |      1 |        1
53  3 | ready  | Untitled (99:d7) |       1 | 10.20.0.5 | 0c:c4:7a:75:99:d7 | controller, mongo    |               |      1 |        1
54 """