-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfind_head_node_ip.py
More file actions
29 lines (21 loc) · 898 Bytes
/
Copy pathfind_head_node_ip.py
File metadata and controls
29 lines (21 loc) · 898 Bytes
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
#!/usr/bin/python
#filename: find_head_node_ip.py
#author: Theodore Knab
#date: 11/8/21
#description: get hode node IP from the slurm config
#bash equivalent get_head_nodeip=$( cat /opt/slurm/etc/slurm_parallelcluster.conf | grep -i ^SlurmctldHost | sed -e s/.*\(//g | sed -e s/\)//g)
import re
def read_file(myfile):
with open(myfile) as f:
lines = f.readlines()
f.close()
return lines
def find_head_node_ip(filename):
mylines=read_file(filename)
for line in mylines:
#print("debug %s" % line.rstrip())
p = re.compile('SlurmctldHost=*',re.IGNORECASE)
if p.match(line):
return line.split("=")[1].split("(")[1].split(')')[0] #tripple split on line 1. get second field after "=', 2. get second field after '(', 3. drop last ")' character
myvalue=find_head_node_ip("/opt/slurm/etc/slurm_parallelcluster.conf")
print(myvalue)