-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbfnode
More file actions
78 lines (73 loc) · 2.13 KB
/
bfnode
File metadata and controls
78 lines (73 loc) · 2.13 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
71
72
73
74
75
76
77
78
#!/bin/env python3
# a brief way to show node info
# by jtyang 2020/6/8
import os
import time
import re
username = os.popen('whoami').readline()[:-1]
tmpfile="/tmp/"+username+"tmpqnodes"
os.popen("qnodes >"+tmpfile)
time.sleep(0.1) # give time to write file
# print(tmpfile)
finObj=open(tmpfile)
class Node:
'just node'
def __init__(self,name):
self.name= name
self.totCore= 28
self.usedCore= 0
self.pState= "R"
self.state=""
self.np=""
def qNode(self):
print(' {:12s}{:>2d}/{:02d} {:8s}'.format(self.name, self.usedCore, self.totCore, self.pState) )
# get used core number
def getUsedCore(line):
# print(line)
nUsedCore=0
tmpList=[]
words= re.findall(r"[ \,](.+?)/\d+\.master?",line)
if "jobs" in line[0:11]:
words[0]=words[0][11:]
# print(words)
# print("its a job line")
# get core one by one
for i in range(len(words)):
if "-" in words[i]:
tmpList= re.findall(r"(\d+)-(\d+)",words[i])
for j in range(len(tmpList)):
nUsedCore= nUsedCore+ int(tmpList[0][1])- int(tmpList[0][0])
nUsedCore= nUsedCore+ words[i].count(",") +1
return nUsedCore
else:
return nUsedCore
print(" name used/tot stat")
print("-------- -------- ----")
# analysis the file
## if node info
while True:
line=finObj.readline()
if not line:
break
elif line[0:6]== "master" or line[0:4]== "node":
# init
nTmp= Node(line[0:-1])
line= finObj.readline()
# state
nTmp.state= str.split(line)[2]
line= finObj.readline()
# power state
nTmp.pState= str.split(line)[2][0]
if nTmp.pState== 'R' : nTmp.pState= 'r'
# tot core
line= finObj.readline()
nTmp.totCore= int(str.split(line)[2])
# ntype
line= finObj.readline() # ntype
# status or jobs
line= finObj.readline()
### get usedCore
nTmp.usedCore= getUsedCore(line)
### show info
nTmp.qNode()
print("-------- -------- ----")