Revision b32d9fae snf-pithos-app/pithos/api/management/commands/pithos-reconcile-commissions.py
b/snf-pithos-app/pithos/api/management/commands/pithos-reconcile-commissions.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from django.core.management.base import NoArgsCommand, CommandError |
35 |
from optparse import make_option |
|
35 | 36 |
|
36 | 37 |
from pithos.api.util import get_backend |
37 | 38 |
|
... | ... | |
44 | 45 |
class Command(NoArgsCommand): |
45 | 46 |
help = "Display unresolved commissions and trigger their recovery" |
46 | 47 |
|
48 |
option_list = NoArgsCommand.option_list + ( |
|
49 |
make_option('--fix', |
|
50 |
dest='fix', |
|
51 |
action="store_true", |
|
52 |
default=False, |
|
53 |
help="Fix unresolved commissions"), |
|
54 |
) |
|
55 |
|
|
47 | 56 |
def handle_noargs(self, **options): |
48 | 57 |
b = get_backend() |
49 | 58 |
try: |
... | ... | |
51 | 60 |
clientkey=CLIENTKEY |
52 | 61 |
) |
53 | 62 |
|
54 |
to_accept = b.quotaholder_serials.lookup(pending_commissions) |
|
55 |
self.stdout.write("Accept commissions: %s\n" % to_accept) |
|
56 |
b.quotaholder.accept_commission( |
|
57 |
context = {}, |
|
58 |
clientkey = CLIENTKEY, |
|
59 |
serials = to_accept |
|
60 |
) |
|
61 |
self.stdout.write("Delete serials: %s\n" % to_accept) |
|
62 |
b.quotaholder_serials.delete_many(to_accept) |
|
63 |
if pending_commissions: |
|
64 |
self.stdout.write( |
|
65 |
"Unresolved commissions: %s\n" % pending_commissions |
|
66 |
) |
|
67 |
else: |
|
68 |
self.stdout.write( "No unresolved commissions were found\n") |
|
69 |
return |
|
63 | 70 |
|
64 |
to_reject = list(set(pending_commissions) - set(to_accept)) |
|
65 |
self.stdout.write("Reject commissions: %s\n" % to_reject) |
|
66 |
b.quotaholder.reject_commission( |
|
67 |
context = {}, |
|
68 |
clientkey = CLIENTKEY, |
|
69 |
serials = to_reject |
|
70 |
) |
|
71 |
if options['fix']: |
|
72 |
to_accept = b.quotaholder_serials.lookup(pending_commissions) |
|
73 |
b.quotaholder.accept_commission( |
|
74 |
context = {}, |
|
75 |
clientkey = CLIENTKEY, |
|
76 |
serials = to_accept |
|
77 |
) |
|
78 |
self.stdout.write("Accepted commissions: %s\n" % to_accept) |
|
79 |
|
|
80 |
b.quotaholder_serials.delete_many(to_accept) |
|
81 |
self.stdout.write("Deleted serials: %s\n" % to_accept) |
|
71 | 82 |
|
83 |
to_reject = list(set(pending_commissions) - set(to_accept)) |
|
84 |
b.quotaholder.reject_commission( |
|
85 |
context = {}, |
|
86 |
clientkey = CLIENTKEY, |
|
87 |
serials = to_reject |
|
88 |
) |
|
89 |
self.stdout.write("Rejected commissions: %s\n" % to_reject) |
|
72 | 90 |
except Exception, e: |
73 | 91 |
logger.exception(e) |
74 | 92 |
raise CommandError(e) |
Also available in: Unified diff