-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.py
executable file
·52 lines (42 loc) · 2.05 KB
/
start.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/python3
import argparse
from sys import exit
from ganeti_parser.parser import parse_datafile
parser = argparse.ArgumentParser(description="Parse Ganeti cluster state and simulate removing of nodes")
parser.add_argument("filename", type=str, help="Cluster state file as generated by `hscan`")
parser.add_argument("--mode", type=str, default="dump", help="Set operation mode: [dump|remove-first-of-group|remove-node]")
parser.add_argument("--node", type=str, default=None, help="Specify node to remove with --mode remove")
args = parser.parse_args()
cluster = parse_datafile(args.filename)
print("Found {} Node-Groups, {} Nodes, {} Instances, {} Allocation Policies".format(len(cluster.node_groups), len(cluster.nodes), len(cluster.instances), len(cluster.policies)))
for node_group in cluster.node_groups:
filtered_nodes = cluster.get_nodes_by_group(node_group)
filtered_instances = cluster.get_instances_by_nodes(filtered_nodes)
print(" {}: {} Nodes with {} Instances".format(node_group.name, len(filtered_nodes), len(filtered_instances)))
if args.mode == "dump":
cluster.dump_cluster()
exit(0)
elif (args.mode == "remove-first-of-group") or (args.mode == 'remove-first'):
for node_group in cluster.node_groups:
print("Working on node group {}".format(node_group.name))
first_node_from_group = cluster.get_nodes_by_group(node_group)[0].name
print("Trying to remove first node {}".format(first_node_from_group))
print()
try:
cluster.remove_node(first_node_from_group)
print("Successfully removed first node from cluster")
cluster.dump_cluster()
except:
print("Failed to remove first node")
print()
elif args.mode == "remove":
if not args.node:
print()
print("Error: Please specify node to remove")
exit(1)
try:
cluster.remove_node(args.node)
print("Successfully removed {} from cluster".format(args.node))
cluster.dump_cluster()
except:
print("Failed to remove {}".format(args.node))