Skip to content

Commit 473e4ce

Browse files
authored
Display storage usage on user account page (#440)
* Added 'total_report' to lib/accounting * Added Storage Usage to user account page
1 parent 7519f0c commit 473e4ce

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

mig/lib/accounting.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ def update_accounting(configuration,
441441
# Check if all vgrids were accounted for
442442

443443
for vgrid_name in vgrid_quota_files.keys():
444-
if not vgrid_name in vgrids_accounted:
444+
if vgrid_name not in vgrids_accounted:
445445
vgridowner = ''
446446
for owner, owned_vgrids in owned_vgrid.items():
447447
if vgrid_name in owned_vgrids:
@@ -640,6 +640,7 @@ def get_usage(configuration,
640640
'vgrid_total': vgrid_total,
641641
'freeze_total': freeze_bytes,
642642
'ext_users_total': 0,
643+
'total_report': '',
643644
'home_report': home_report,
644645
'freeze_report': freeze_report,
645646
'vgrid_report': vgrid_report,
@@ -695,6 +696,12 @@ def get_usage(configuration,
695696
peers_report = "Accepted by the following peer:%s" % peers_report
696697
account_usage[username]['peers_report'] = peers_report
697698

699+
# Create total usage report for each user
700+
701+
for usage in account_usage.values():
702+
usage['total_report'] = "Total usage: %s" \
703+
% human_readable_filesize(usage['total_bytes'])
704+
698705
# External users are accounted for by their peer
699706
# unless the external user also act as a peer
700707

mig/shared/functionality/account.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import datetime
3535
import os
3636

37+
from mig.lib.accounting import get_usage
3738
from mig.shared import returnvalues
3839
from mig.shared.accountreq import renew_account_access_template
3940
from mig.shared.accountstate import account_expire_info
@@ -213,6 +214,67 @@ def html_tmpl(configuration, client_id, environ, title_entry):
213214
</div>
214215
''' % fill_helpers
215216

217+
# Show storage accounting information if enabled
218+
219+
if configuration.site_enable_accounting:
220+
account_usage = get_usage(configuration, client_id)
221+
accounting = account_usage.get('accounting', {})
222+
accounting_dt = datetime.datetime.fromtimestamp(
223+
account_usage.get('timestamp', 0))
224+
quota = account_usage.get('quota', {})
225+
fill_helpers['usage_helper'] = "Updated: %s" % accounting_dt
226+
fill_helpers['usage_helper'] += "<p>Quota updated:<br/>"
227+
for backend, values in quota.items():
228+
quota_dt = datetime.datetime.fromtimestamp(values.get('mtime', 0))
229+
fill_helpers['usage_helper'] \
230+
+= "%s&nbsp;&nbsp;&nbsp;&nbsp;%s<br/>" % (quota_dt, backend)
231+
fill_helpers['usage_helper'] += "</p><p>"
232+
accounting_report = accounting.get(client_id, {})
233+
if configuration.site_enable_gdp:
234+
# NOTE: Only show vgrid usage when in GDP mode
235+
# as no data is stored in user home
236+
vgrid_report = accounting_report.get('vgrid_report', '')
237+
if vgrid_report:
238+
fill_helpers['usage_helper'] \
239+
+= vgrid_report.replace('\n', '<br/>')
240+
else:
241+
total_report = accounting_report.get('total_report', '')
242+
home_report = accounting_report.get('home_report', '')
243+
freeze_report = accounting_report.get('freeze_report', '')
244+
vgrid_report = accounting_report.get('vgrid_report', '')
245+
ext_users_report = accounting_report.get('ext_users_report', '')
246+
peers_report = accounting_report.get('peers_report', '')
247+
if total_report:
248+
fill_helpers['usage_helper'] \
249+
+= total_report.replace('\n', '<br/>') \
250+
+ "<br/>"
251+
if home_report:
252+
fill_helpers['usage_helper'] \
253+
+= home_report.replace('\n', '<br/>') \
254+
+ "<br/>"
255+
if freeze_report:
256+
fill_helpers['usage_helper'] \
257+
+= freeze_report.replace('\n', '<br/>') \
258+
+ "<br/>"
259+
if vgrid_report:
260+
fill_helpers['usage_helper'] \
261+
+= vgrid_report.replace('\n', '<br/>') \
262+
+ "<br/>"
263+
if ext_users_report:
264+
fill_helpers['usage_helper'] \
265+
+= ext_users_report.replace('\n', '<br/>') \
266+
+ "<br/>"
267+
if peers_report:
268+
fill_helpers['usage_helper'] \
269+
+= peers_report.replace('\n', '<br/>') \
270+
+ "<br/>"
271+
fill_helpers['usage_helper'] += "</p>"
272+
html += '''
273+
<div id="account-usage" class="row">
274+
<h3>Account Usage</h3>
275+
%(usage_helper)s
276+
</div>''' % fill_helpers
277+
216278
html += '''
217279
<div class="col-lg-12 vertical-spacer"></div>
218280
</div>

0 commit comments

Comments
 (0)