|
34 | 34 | import datetime |
35 | 35 | import os |
36 | 36 |
|
| 37 | +from mig.lib.accounting import get_usage |
37 | 38 | from mig.shared import returnvalues |
38 | 39 | from mig.shared.accountreq import renew_account_access_template |
39 | 40 | from mig.shared.accountstate import account_expire_info |
@@ -213,6 +214,67 @@ def html_tmpl(configuration, client_id, environ, title_entry): |
213 | 214 | </div> |
214 | 215 | ''' % fill_helpers |
215 | 216 |
|
| 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 %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 | + |
216 | 278 | html += ''' |
217 | 279 | <div class="col-lg-12 vertical-spacer"></div> |
218 | 280 | </div> |
|
0 commit comments