root / snf-astakos-app / astakos / im / management / commands / astakos-quota-verify.py @ f2c27eb6
History | View | Annotate | Download (3.8 kB)
1 | fc1e2f02 | Sofia Papagiannaki | # Copyright 2012 GRNET S.A. All rights reserved.
|
---|---|---|---|
2 | fc1e2f02 | Sofia Papagiannaki | #
|
3 | fc1e2f02 | Sofia Papagiannaki | # Redistribution and use in source and binary forms, with or
|
4 | fc1e2f02 | Sofia Papagiannaki | # without modification, are permitted provided that the following
|
5 | fc1e2f02 | Sofia Papagiannaki | # conditions are met:
|
6 | fc1e2f02 | Sofia Papagiannaki | #
|
7 | fc1e2f02 | Sofia Papagiannaki | # 1. Redistributions of source code must retain the above
|
8 | fc1e2f02 | Sofia Papagiannaki | # copyright notice, this list of conditions and the following
|
9 | fc1e2f02 | Sofia Papagiannaki | # disclaimer.
|
10 | fc1e2f02 | Sofia Papagiannaki | #
|
11 | fc1e2f02 | Sofia Papagiannaki | # 2. Redistributions in binary form must reproduce the above
|
12 | fc1e2f02 | Sofia Papagiannaki | # copyright notice, this list of conditions and the following
|
13 | fc1e2f02 | Sofia Papagiannaki | # disclaimer in the documentation and/or other materials
|
14 | fc1e2f02 | Sofia Papagiannaki | # provided with the distribution.
|
15 | fc1e2f02 | Sofia Papagiannaki | #
|
16 | fc1e2f02 | Sofia Papagiannaki | # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 | fc1e2f02 | Sofia Papagiannaki | # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 | fc1e2f02 | Sofia Papagiannaki | # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 | fc1e2f02 | Sofia Papagiannaki | # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 | fc1e2f02 | Sofia Papagiannaki | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 | fc1e2f02 | Sofia Papagiannaki | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 | fc1e2f02 | Sofia Papagiannaki | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 | fc1e2f02 | Sofia Papagiannaki | # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 | fc1e2f02 | Sofia Papagiannaki | # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 | fc1e2f02 | Sofia Papagiannaki | # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 | fc1e2f02 | Sofia Papagiannaki | # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 | fc1e2f02 | Sofia Papagiannaki | # POSSIBILITY OF SUCH DAMAGE.
|
28 | fc1e2f02 | Sofia Papagiannaki | #
|
29 | fc1e2f02 | Sofia Papagiannaki | # The views and conclusions contained in the software and
|
30 | fc1e2f02 | Sofia Papagiannaki | # documentation are those of the authors and should not be
|
31 | fc1e2f02 | Sofia Papagiannaki | # interpreted as representing official policies, either expressed
|
32 | fc1e2f02 | Sofia Papagiannaki | # or implied, of GRNET S.A.
|
33 | fc1e2f02 | Sofia Papagiannaki | |
34 | 84a3f701 | Giorgos Korfiatis | from optparse import make_option |
35 | 84a3f701 | Giorgos Korfiatis | from django.core.management.base import BaseCommand, CommandError |
36 | 84a3f701 | Giorgos Korfiatis | from django.db import transaction |
37 | fc1e2f02 | Sofia Papagiannaki | |
38 | 84a3f701 | Giorgos Korfiatis | from astakos.im.models import sync_all_users, sync_projects |
39 | 3c049f6d | Giorgos Korfiatis | from astakos.im.functions import get_user_by_uuid |
40 | fc1e2f02 | Sofia Papagiannaki | |
41 | 9a06d96f | Olga Brani | import logging |
42 | 9a06d96f | Olga Brani | logger = logging.getLogger(__name__) |
43 | 9a06d96f | Olga Brani | |
44 | 84a3f701 | Giorgos Korfiatis | class Command(BaseCommand): |
45 | 140da2d1 | Giorgos Korfiatis | help = "Inspect quotaholder status"
|
46 | 5ce3ce4f | Sofia Papagiannaki | |
47 | 84a3f701 | Giorgos Korfiatis | option_list = BaseCommand.option_list + ( |
48 | 140da2d1 | Giorgos Korfiatis | make_option('--check',
|
49 | 84a3f701 | Giorgos Korfiatis | action='store_true',
|
50 | 140da2d1 | Giorgos Korfiatis | dest='check',
|
51 | 140da2d1 | Giorgos Korfiatis | default=True,
|
52 | 140da2d1 | Giorgos Korfiatis | help="Check if quotaholder is in sync with astakos (default)"),
|
53 | 140da2d1 | Giorgos Korfiatis | make_option('--sync',
|
54 | 84a3f701 | Giorgos Korfiatis | action='store_true',
|
55 | 140da2d1 | Giorgos Korfiatis | dest='sync',
|
56 | 84a3f701 | Giorgos Korfiatis | default=False,
|
57 | 140da2d1 | Giorgos Korfiatis | help="Sync quotaholder"),
|
58 | 84a3f701 | Giorgos Korfiatis | ) |
59 | 84a3f701 | Giorgos Korfiatis | |
60 | 84a3f701 | Giorgos Korfiatis | @transaction.commit_on_success
|
61 | 84a3f701 | Giorgos Korfiatis | def handle(self, *args, **options): |
62 | 140da2d1 | Giorgos Korfiatis | sync = options['sync']
|
63 | 5ce3ce4f | Sofia Papagiannaki | |
64 | fc1e2f02 | Sofia Papagiannaki | try:
|
65 | 140da2d1 | Giorgos Korfiatis | log = sync_all_users(sync=sync) |
66 | 62fda315 | Giorgos Korfiatis | existing, nonexisting, registered_quotas, astakos_quotas = log |
67 | 62fda315 | Giorgos Korfiatis | |
68 | 3c049f6d | Giorgos Korfiatis | if nonexisting:
|
69 | f2c27eb6 | Georgios D. Tsoukalas | self.stdout.write("Users not registered in quotaholder:\n") |
70 | 3c049f6d | Giorgos Korfiatis | for user in nonexisting: |
71 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("%s\n" % (user)) |
72 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("\n") |
73 | 3c049f6d | Giorgos Korfiatis | |
74 | 3c049f6d | Giorgos Korfiatis | diffs = 0
|
75 | 3c049f6d | Giorgos Korfiatis | for holder, local in astakos_quotas.iteritems(): |
76 | 3c049f6d | Giorgos Korfiatis | registered = registered_quotas.pop(holder, None)
|
77 | 3c049f6d | Giorgos Korfiatis | if registered is None: |
78 | 3c049f6d | Giorgos Korfiatis | diffs += 1
|
79 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("No quotas for %s in quotaholder.\n\n" % |
80 | 3c049f6d | Giorgos Korfiatis | (get_user_by_uuid(holder))) |
81 | 3c049f6d | Giorgos Korfiatis | elif local != registered:
|
82 | 3c049f6d | Giorgos Korfiatis | diffs += 1
|
83 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("Quotas differ for %s:\n" % (get_user_by_uuid(holder))) |
84 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("Quotas according to quotaholder:\n") |
85 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("%s\n" % (registered)) |
86 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("Quotas according to astakos:\n") |
87 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("%s\n\n" % (local)) |
88 | 3c049f6d | Giorgos Korfiatis | |
89 | 3c049f6d | Giorgos Korfiatis | if diffs:
|
90 | 3c049f6d | Giorgos Korfiatis | self.stdout.write("Quotas differ for %d users.\n" % (diffs)) |
91 | fc1e2f02 | Sofia Papagiannaki | except BaseException, e: |
92 | 9a06d96f | Olga Brani | logger.exception(e) |
93 | 9a06d96f | Olga Brani | raise CommandError("Syncing failed.") |