Revision 629acc65 snf-cyclades-app/synnefo/quotas/management/commands/cyclades-reset-usage.py

b/snf-cyclades-app/synnefo/quotas/management/commands/cyclades-reset-usage.py
1
# Copyright 2012 GRNET S.A. All rights reserved.
1
# Copyright 2012, 2013 GRNET S.A. All rights reserved.
2 2
#
3 3
# Redistribution and use in source and binary forms, with or
4 4
# without modification, are permitted provided that the following
......
34 34
from django.core.management.base import BaseCommand
35 35
from optparse import make_option
36 36

  
37
from synnefo.quotas import get_quota_holder
37
from synnefo.quotas import Quotaholder
38 38
from synnefo.quotas.util import get_db_holdings
39 39

  
40 40

  
......
58 58
        db_holdings = get_db_holdings(users)
59 59

  
60 60
        # Create commissions
61
        with get_quota_holder() as qh:
62
            for user, resources in db_holdings.items():
63
                if not user:
64
                    continue
65
                reset_holding = []
66
                for res, val in resources.items():
67
                    reset_holding.append((user, "cyclades." + res, "1", val, 0,
68
                                          0, 0))
69
                if not options['dry_run']:
70
                    try:
71
                        qh.reset_holding(context={},
72
                                         reset_holding=reset_holding)
73
                    except Exception as e:
74
                        self.stderr.write("Can not set up holding:%s" % e)
75
                else:
76
                    self.stdout.write("Reseting holding: %s\n" % reset_holding)
61
        qh = Quotaholder.get()
62
        for user, resources in db_holdings.items():
63
            if not user:
64
                continue
65
            reset_holding = []
66
            for res, val in resources.items():
67
                reset_holding.append((user, "cyclades." + res, "1", val, 0,
68
                                      0, 0))
69
            if not options['dry_run']:
70
                try:
71
                    qh.reset_holding(context={},
72
                                     reset_holding=reset_holding)
73
                except Exception as e:
74
                    self.stderr.write("Can not set up holding:%s" % e)
75
            else:
76
                self.stdout.write("Reseting holding: %s\n" % reset_holding)

Also available in: Unified diff