-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsmith_avail
More file actions
executable file
·66 lines (53 loc) · 1.89 KB
/
smith_avail
File metadata and controls
executable file
·66 lines (53 loc) · 1.89 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
#!/usr/bin/env python3
# Author: Kurt Irvin Rojas
# https://github.com/kimrojas/smith_utils
import sys, os, subprocess
sys.dont_write_bytecode = True
from smith_user_parse import user
import smith_check
from smith_output import blue, green, warning, fail, bold
# Check connection
method = smith_check.check()
if method == 'UseLocal': bashCommand = f"ssh -Y {user['smith_username']}@{user['smith_ip']}"
if method == 'UseGlobal': bashCommand = f"ssh -Y {user['smith_username']}@localhost -p {user['smith_univ_port']}"
# Setup and run ssh query command
lookCommand = "qstat -f"
fullCommand = f"{bashCommand} '{lookCommand}'"
process = subprocess.Popen(fullCommand, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
output = (output.decode('ascii')).splitlines()
# Trim output
okay = []
for line in output:
cond1 = ' 0/0/' in line
cond2 = '-NA-' not in line
if cond1 and cond2: okay.append(line.split())
okay
# Show output
def see_capacity(cap):
b = cap.split('/')
return f"{b[0]}/{b[1]}/ {b[2]}"
outlines = []
outlines.append(green("RESOURCE AVAILABILITY"))
outlines.append(green(f"{'-'*53}"))
if len(okay) == 0:
outlines.append(warning("No resources available at this moment, try again later."))
else:
outlines.append(bold(f"{'QUEUE':^10}{'NODE':^10}{'CAPACITY':^10}{'LOAD':^8}"))
b4queue = ""
init = 1
for line in okay:
queue,node = line[0].split('@')[0], line[0].split('@')[-1]
if b4queue != queue:
if init != 1: outlines.append(f"{'-':^10}{'-':^10}{'-':^10}{'-':^8}")
b4queue = queue
init = 2
else:
queue = ""
capacity = line[2].split('/')[-1]
load = line[3]
queue = blue(queue)
outlines.append(f"{queue:^19}{node:^10}{capacity:^10}{load:^8}")
outlines.append(green(f"{'-'*53}"))
for line in outlines:
print(line)