-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathnodeRemove.py
More file actions
executable file
·70 lines (56 loc) · 2.27 KB
/
nodeRemove.py
File metadata and controls
executable file
·70 lines (56 loc) · 2.27 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
"""Remove Node from Cluster"""
### usage: ./backupNow.py -v mycluster -u admin -j 'VM Backup'
### import pyhesity wrapper module
from pyhesity import *
### command line arguments
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--vip', type=str, required=True)
parser.add_argument('-u', '--username', type=str, required=True)
parser.add_argument('-d', '--domain', type=str, default='local')
parser.add_argument('-n', '--nodeId', type=int, default=0)
parser.add_argument('-m', '--maxFull', type=int, default=70)
args = parser.parse_args()
vip = args.vip
username = args.username
domain = args.domain
nodeId = args.nodeId
maxFull = args.maxFull
### authenticate
apiauth(vip, username, domain)
### get cluster stats
cluster = api('get', 'cluster?fetchStats=true')
### check minimum node count
if cluster['nodeCount'] == cluster['supportedConfig']['minNodesAllowed']:
print("Can not remove a node. Current node count: %i (Minimum required: %i)" % (cluster['nodeCount'], cluster['supportedConfig']['minNodesAllowed']))
exit()
### check free space
newCapacity = cluster['stats']['usagePerfStats']['physicalCapacityBytes'] / cluster['nodeCount'] * (cluster['nodeCount'] - 1) * maxFull / 100
if cluster['stats']['usagePerfStats']['systemUsageBytes'] > newCapacity:
print("Can not remove a node. Resulting capacity would be below the maxFull threshold")
exit()
### check cluster health
clusterStat = api('get', '/nexus/cluster/status')
if clusterStat['healingStatus'] != 'NORMAL':
print("Can not remove a node. Cluster Health Status is abnormal")
exit()
### get node for removal
selectedNodeId = 0
nodeList = sorted(clusterStat['clusterConfig']['proto']['nodeVec'], key=lambda kv: kv['clusterNodeIndex'], reverse=True)
### if node is not specified, select last node of cluster
if nodeId == 0:
selectedNodeId = nodeList[0]['id']
else:
### otherwise find specified node
for node in nodeList:
if nodeId == node['id']:
selectedNodeId = nodeId
break
### if we couldn't find the specified node
if selectedNodeId == 0:
print("Couldn't find a node to remove")
else:
### remove the selected node
print("Removing node %i" % selectedNodeId)
result = api('post', "/nodes/%i" % selectedNodeId)