Revision 84a3f701 snf-astakos-app/astakos/im/management/commands/astakos-qh-sync.py
b/snf-astakos-app/astakos/im/management/commands/astakos-qh-sync.py | ||
---|---|---|
31 | 31 |
# interpreted as representing official policies, either expressed |
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 |
from django.core.management.base import NoArgsCommand, CommandError |
|
34 |
from optparse import make_option |
|
35 |
from django.core.management.base import BaseCommand, CommandError |
|
36 |
from django.db import transaction |
|
35 | 37 |
|
36 |
from astakos.im.models import AstakosUser, Resource |
|
37 |
from astakos.im.endpoints.qh import register_users, register_resources |
|
38 |
from astakos.im.models import sync_all_users, sync_projects |
|
38 | 39 |
|
39 | 40 |
import logging |
40 | 41 |
logger = logging.getLogger(__name__) |
41 | 42 |
|
43 |
class Command(BaseCommand): |
|
44 |
help = "Inspect quotaholder status and sync" |
|
42 | 45 |
|
43 |
class Command(NoArgsCommand): |
|
44 |
help = "Send user information and resource quota in the Quotaholder" |
|
46 |
option_list = BaseCommand.option_list + ( |
|
47 |
make_option('--users', |
|
48 |
action='store_true', |
|
49 |
dest='users', |
|
50 |
default=False, |
|
51 |
help="Check if users and their quotas are in sync with quotaholder"), |
|
52 |
make_option('--projects', |
|
53 |
action='store_true', |
|
54 |
dest='projects', |
|
55 |
default=False, |
|
56 |
help="Check if projects are in sync with quotaholder"), |
|
57 |
make_option('--execute', |
|
58 |
action='store_true', |
|
59 |
dest='execute', |
|
60 |
default=False, |
|
61 |
help="Perform the actual operation"), |
|
62 |
) |
|
63 |
|
|
64 |
@transaction.commit_on_success |
|
65 |
def handle(self, *args, **options): |
|
66 |
execute = options['execute'] |
|
45 | 67 |
|
46 |
def handle_noargs(self, **options): |
|
47 | 68 |
try: |
48 |
resources = list(Resource.objects.all()) |
|
49 |
print("Registering resources") |
|
50 |
register_resources(resources) |
|
51 |
print("Registering users") |
|
52 |
users = list(AstakosUser.objects.verified().all()) |
|
53 |
if users: |
|
54 |
register_users(users) |
|
55 |
else: |
|
56 |
print(" -> No verified users found.") |
|
69 |
if options['users']: |
|
70 |
log = sync_all_users(execute=execute) |
|
71 |
elif options['projects']: |
|
72 |
log = sync_projects(execute=execute) |
|
57 | 73 |
except BaseException, e: |
58 | 74 |
logger.exception(e) |
59 | 75 |
raise CommandError("Syncing failed.") |
60 |
|
Also available in: Unified diff