예제 #1
0
    def quotas(self, sync, verify, user_ident, output_format, style):
        list_only = not sync and not verify

        if user_ident is not None:
            users = [self.get_user(user_ident)]
        else:
            users = AstakosUser.objects.verified()

        if list_only:
            qh_quotas, astakos_i = list_user_quotas(users)

            info = {}
            for user in users:
                info[user.uuid] = user.email

            print_data, labels = show_quotas(qh_quotas,
                                             astakos_i,
                                             info,
                                             style=style)
            utils.pprint_table(self.stdout, print_data, labels, output_format)

        elif verify or sync:
            qh_limits, diff_q = qh_sync_users_diffs(users, sync=sync)
            if verify:
                self.print_verify(qh_limits, diff_q)
            if sync:
                self.print_sync(diff_q)
예제 #2
0
    def handle(self, *args, **options):
        output_format = options["output_format"]
        displayname = bool(options["displayname"])
        unit_style = options["unit_style"]
        common.check_style(unit_style)

        filteropt = options["filter_by"]
        if filteropt is not None:
            filters = filteropt.split(",")
        else:
            filters = []

        QHQ, INITQ = Q(), Q()
        for flt in filters:
            q = filtering.make_query(flt, self.QHFLT)
            if q is not None:
                QHQ &= q
            q = filtering.make_query(flt, self.INITFLT)
            if q is not None:
                INITQ &= q

        overlimit = bool(options["overlimit"])
        if overlimit:
            QHQ &= Q(usage_max__gt=F("limit"))

        with_custom = options["with_custom"]
        if with_custom is not None:
            qeq = Q(capacity=F("resource__uplimit"))
            try:
                INITQ &= ~qeq if utils.parse_bool(with_custom) else qeq
            except ValueError as e:
                raise CommandError(e)

        users = AstakosUser.objects.accepted()
        qh_quotas, astakos_i = list_user_quotas(
            users, qhflt=QHQ, initflt=INITQ)

        if displayname:
            info = {}
            for user in users:
                info[user.uuid] = user.email
        else:
            info = None

        print_data, labels = common.show_quotas(
            qh_quotas, astakos_i, info, style=unit_style)
        utils.pprint_table(self.stdout, print_data, labels, output_format)
예제 #3
0
    def handle(self, *args, **options):
        output_format = options["output_format"]
        displayname = bool(options["display-mails"])
        unit_style = options["unit_style"]
        common.check_style(unit_style)

        filteropt = options["filter_by"]
        if filteropt is not None:
            filters = filteropt.split(",")
        else:
            filters = []

        QHQ = Q()
        for flt in filters:
            q = filtering.make_query(flt, self.QHFLT)
            if q is not None:
                QHQ &= q

        overlimit = bool(options["overlimit"])
        if overlimit:
            QHQ &= Q(usage_max__gt=F("limit"))

        users = AstakosUser.objects.accepted()
        qh_quotas = list_user_quotas(users, qhflt=QHQ)

        if displayname:
            info = {}
            for user in users:
                info[user.uuid] = user.email
        else:
            info = None

        print_data, labels = common.show_quotas(qh_quotas,
                                                info,
                                                style=unit_style)
        utils.pprint_table(self.stdout, print_data, labels, output_format)
예제 #4
0
    def handle(self, *args, **options):
        output_format = options["output_format"]
        displayname = bool(options["display-mails"])
        unit_style = options["unit_style"]
        common.check_style(unit_style)

        filteropt = options["filter_by"]
        if filteropt is not None:
            filters = filteropt.split(",")
        else:
            filters = []

        QHQ = Q()
        for flt in filters:
            q = filtering.make_query(flt, self.QHFLT)
            if q is not None:
                QHQ &= q

        overlimit = bool(options["overlimit"])
        if overlimit:
            QHQ &= Q(usage_max__gt=F("limit"))

        users = AstakosUser.objects.accepted()
        qh_quotas = list_user_quotas(
            users, qhflt=QHQ)

        if displayname:
            info = {}
            for user in users:
                info[user.uuid] = user.email
        else:
            info = None

        print_data, labels = common.show_quotas(
            qh_quotas, info, style=unit_style)
        utils.pprint_table(self.stdout, print_data, labels, output_format)
예제 #5
0
파일: quota.py 프로젝트: vkoukis/synnefo
    def quotas(self, sync, verify, user_ident, output_format, style):
        list_only = not sync and not verify

        if user_ident is not None:
            users = [self.get_user(user_ident)]
        else:
            users = AstakosUser.objects.accepted()

        if list_only:
            qh_quotas, astakos_i = list_user_quotas(users)

            info = {}
            for user in users:
                info[user.uuid] = user.email

            print_data, labels = show_quotas(qh_quotas, astakos_i, info, style=style)
            utils.pprint_table(self.stdout, print_data, labels, output_format)

        elif verify or sync:
            qh_limits, diff_q = qh_sync_users_diffs(users, sync=sync)
            if verify:
                self.print_verify(qh_limits, diff_q)
            if sync:
                self.print_sync(diff_q)
예제 #6
0
파일: user-show.py 프로젝트: cstavr/synnefo
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a user ID or email")

        identifier = args[0]
        if identifier.isdigit():
            users = AstakosUser.objects.filter(id=int(identifier))
        else:
            try:
                uuid.UUID(identifier)
            except:
                users = AstakosUser.objects.filter(email__iexact=identifier)
            else:
                users = AstakosUser.objects.filter(uuid=identifier)
        if users.count() == 0:
            field = 'id' if identifier.isdigit() else 'email'
            msg = "Unknown user with %s '%s'" % (field, identifier)
            raise CommandError(msg)

        for user in users:
            kv = OrderedDict(
                [
                    ('id', user.id),
                    ('uuid', user.uuid),
                    ('status', user.status_display),
                    ('email', user.email),
                    ('first name', user.first_name),
                    ('last name', user.last_name),
                    ('active', user.is_active),
                    ('admin', user.is_superuser),
                    ('last login', user.last_login),
                    ('date joined', user.date_joined),
                    ('last update', user.updated),
                    #('token', user.auth_token),
                    ('token expiration', user.auth_token_expires),
                    ('providers', user.auth_providers_display),
                    ('verified', user.is_verified),
                    ('groups', [elem.name for elem in user.groups.all()]),
                    ('permissions', [elem.codename
                                     for elem in user.user_permissions.all()]),
                    ('group permissions', user.get_group_permissions()),
                    ('email verified', user.email_verified),
                    ('username', user.username),
                    ('activation_sent_date', user.activation_sent),
                ])

            if get_latest_terms():
                has_signed_terms = user.signed_terms
                kv['has_signed_terms'] = has_signed_terms
                if has_signed_terms:
                    kv['date_signed_terms'] = user.date_signed_terms

            utils.pprint_table(self.stdout, [kv.values()], kv.keys(),
                               options["output_format"], vertical=True)

            if options["list_quotas"]:
                unit_style = options["unit_style"]
                check_style(unit_style)

                quotas, initial = list_user_quotas([user])
                if quotas:
                    self.stdout.write("\n")
                    print_data, labels = show_quotas(quotas, initial,
                                                     style=unit_style)
                    utils.pprint_table(self.stdout, print_data, labels,
                                       options["output_format"],
                                       title="User Quota")

            if options["list_projects"]:
                print_data, labels = ownerships(user)
                if print_data:
                    self.stdout.write("\n")
                    utils.pprint_table(self.stdout, print_data, labels,
                                       options["output_format"],
                                       title="Owned Projects")

                print_data, labels = memberships(user)
                if print_data:
                    self.stdout.write("\n")
                    utils.pprint_table(self.stdout, print_data, labels,
                                       options["output_format"],
                                       title="Project Memberships")
예제 #7
0
    def handle(self, *args, **options):
        if len(args) != 1:
            raise CommandError("Please provide a user ID or email")

        identifier = args[0]
        if identifier.isdigit():
            users = AstakosUser.objects.filter(id=int(identifier))
        else:
            try:
                uuid.UUID(identifier)
            except:
                users = AstakosUser.objects.filter(email__iexact=identifier)
            else:
                users = AstakosUser.objects.filter(uuid=identifier)
        if users.count() == 0:
            field = 'id' if identifier.isdigit() else 'email'
            msg = "Unknown user with %s '%s'" % (field, identifier)
            raise CommandError(msg)

        for user in users:
            kv = OrderedDict([
                ('id', user.id),
                ('uuid', user.uuid),
                ('status', user.status_display),
                ('email', user.email),
                ('first name', user.first_name),
                ('last name', user.last_name),
                ('active', user.is_active),
                ('admin', user.is_superuser),
                ('last login', user.last_login),
                ('date joined', user.date_joined),
                ('last update', user.updated),
                #('token', user.auth_token),
                ('token expiration', user.auth_token_expires),
                ('providers', user.auth_providers_display),
                ('verified', user.is_verified),
                ('groups', [elem.name for elem in user.groups.all()]),
                ('permissions',
                 [elem.codename for elem in user.user_permissions.all()]),
                ('group permissions', user.get_group_permissions()),
                ('email verified', user.email_verified),
                ('username', user.username),
                ('activation_sent_date', user.activation_sent),
            ])

            if get_latest_terms():
                has_signed_terms = user.signed_terms
                kv['has_signed_terms'] = has_signed_terms
                if has_signed_terms:
                    kv['date_signed_terms'] = user.date_signed_terms

            utils.pprint_table(self.stdout, [kv.values()],
                               kv.keys(),
                               options["output_format"],
                               vertical=True)

            if options["list_quotas"]:
                unit_style = options["unit_style"]
                check_style(unit_style)

                quotas, initial = list_user_quotas([user])
                if quotas:
                    self.stdout.write("\n")
                    print_data, labels = show_quotas(quotas,
                                                     initial,
                                                     style=unit_style)
                    utils.pprint_table(self.stdout,
                                       print_data,
                                       labels,
                                       options["output_format"],
                                       title="User Quota")

            if options["list_projects"]:
                print_data, labels = ownerships(user)
                if print_data:
                    self.stdout.write("\n")
                    utils.pprint_table(self.stdout,
                                       print_data,
                                       labels,
                                       options["output_format"],
                                       title="Owned Projects")

                print_data, labels = memberships(user)
                if print_data:
                    self.stdout.write("\n")
                    utils.pprint_table(self.stdout,
                                       print_data,
                                       labels,
                                       options["output_format"],
                                       title="Project Memberships")