Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Include zero usage users in crc-bank account info output #335

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions bank/system/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,14 @@ def get_cluster_usage_per_user(self, cluster: str, start: date, end: date, in_ho
if not in_hours:
time = 'Seconds'

cmd = ShellCmd(f"sreport cluster AccountUtilizationByUser -Pn -T Billing -t {time} cluster={cluster} "
cmd1 = ShellCmd(f"sreport cluster AccountUtilizationByUser -Pn -T Billing -t {time} cluster={cluster} "
f"Account={self.account_name} start={start.strftime('%Y-%m-%d')} end={end.strftime('%Y-%m-%d')} format=Proper,Used")

cmd2 = ShellCmd(f"sacctmgr -nP show association where Account={self.account_name} Cluster={cluster} Format=User")

try:
account_total, *data = cmd.out.split('\n')
account_total, *data = cmd1.out.split('\n')
users = cmd2.out.split('\n')
except ValueError:
return None

Expand All @@ -188,6 +191,12 @@ def get_cluster_usage_per_user(self, cluster: str, start: date, end: date, in_ho
usage = int(usage)
out_data[user] = usage

for user in users:
if user in out_data.keys():
continue
else:
out_data[user] = 0

return out_data

def get_cluster_usage_total(
Expand Down