File size: 845 Bytes
2abfccb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import commands
import numpy as np

masters = ['10.10.11.22', '10.10.12.145', '10.10.20.21', '10.1.72.101']

def parse(string):
    global masters
    result = []
    for line in string.split('\n'):
        fields = line.split('-')
        ip = '.'.join(fields[2:])
	if ip not in masters:
   	    result.append(ip)
    return result


if __name__ == '__main__':
    output = commands.getoutput("scontrol show node  | grep NodeName | awk \'{print$1}\' | awk -F = \'{print$2}\'")
    print 'the set of machines in this cluster is:'
    print output
    serverlist = parse(output)
    print 'transfer into IP address:'
    print serverlist
    with open('server_list.conf', 'w') as wf:            
        np.savetxt(wf, serverlist, delimiter='\n', fmt='%s')
        wf.close()    
    print 'IP addresses have been written into server_list.conf'