1 ##############################################################################
2 # Copyright (c) 2018 Tim Rozet (trozet@redhat.com) and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
15 def get_node_data_by_number(node_type, node_number):
17 for node_name, node_data in data['servers'].items():
18 if node_type == node_data['type']:
19 if node_idx == node_number:
20 return node_name, node_data
25 def get_node_value(node_type, node_number, key):
26 node_name, node_data = get_node_data_by_number(node_type, node_number)
27 if not key and node_name is not None:
29 elif node_data and isinstance(node_data, dict) and key in node_data:
33 def get_number_of_nodes(node_type):
34 nodes = data['servers']
36 for node_name, node_data in nodes.items():
37 if node_data['type'] == node_type:
42 FUNCTION_MAP = {'num_nodes':
43 {'func': get_number_of_nodes,
44 'args': ['node_type']},
46 {'func': get_node_value,
47 'args': ['node_type', 'node_number', 'key']},
50 if __name__ == "__main__":
51 parser = argparse.ArgumentParser()
52 parser.add_argument('command', choices=FUNCTION_MAP.keys())
53 parser.add_argument('-f', '--file',
56 parser.add_argument('--node-type',
59 parser.add_argument('--node-number',
63 parser.add_argument('-k', '--key',
65 args = parser.parse_args(sys.argv[1:])
66 with open(args.node_file, 'r') as fh:
67 data = yaml.safe_load(fh)
68 assert 'servers' in data
69 func = FUNCTION_MAP[args.command]['func']
70 args = [getattr(args, x) for x in FUNCTION_MAP[args.command]['args']]