Beispiel #1
0
def service_quotas(request):
    user = request.GET.get('user')
    users = [user] if user is not None else None
    result = service_get_quotas(request.component_instance, users=users)

    if user is not None and result == {}:
        raise ItemNotFound("No such user '%s'" % user)

    return json_response(result)
Beispiel #2
0
def service_quotas(request):
    user = request.GET.get('user')
    users = [user] if user is not None else None
    result = service_get_quotas(request.component_instance, users=users)

    if user is not None and result == {}:
        raise ItemNotFound("No such user '%s'" % user)

    return json_response(result)
Beispiel #3
0
def service_quotas(request):
    userstr = request.GET.get("user")
    users = userstr.split(",") if userstr is not None else None
    projectstr = request.GET.get("project")
    projects = projectstr.split(",") if projectstr is not None else None
    result = service_get_quotas(request.component_instance, users=users, sources=projects)

    if userstr is not None and result == {}:
        raise ItemNotFound("No user with UUID '%s'" % userstr)

    return json_response(result)
Beispiel #4
0
def service_quotas(request):
    userstr = request.GET.get('user')
    users = userstr.split(",") if userstr is not None else None
    projectstr = request.GET.get('project')
    projects = projectstr.split(",") if projectstr is not None else None
    result = service_get_quotas(request.component_instance, users=users,
                                sources=projects)

    if userstr is not None and result == {}:
        raise ItemNotFound("No user with UUID '%s'" % userstr)

    return json_response(result)
    def handle(self, *args, **options):
        write = self.stdout.write
        force = options['force']
        userid = options['userid']

        try:
            astakos = Component.objects.get(name="astakos")
        except Component.DoesNotExist:
            raise CommandError("Component 'astakos' not found.")

        query = [userid] if userid is not None else None
        qh_holdings = service_get_quotas(astakos, query)

        if userid is None:
            users = AstakosUser.objects.accepted()
        else:
            try:
                user = AstakosUser.objects.get(uuid=userid)
            except AstakosUser.DoesNotExist:
                raise CommandError("There is no user with uuid '%s'." % userid)
            if not user.is_accepted():
                raise CommandError("%s is not an accepted user." % userid)
            users = [user]

        db_holdings = count_pending_app(users)

        pending_exists = False
        unknown_user_exists = False
        unsynced = []
        for user in users:
            uuid = user.uuid
            db_value = db_holdings.get(uuid, 0)
            try:
                qh_all = qh_holdings[uuid]
            except KeyError:
                write("User '%s' does not exist in Quotaholder!\n" % uuid)
                unknown_user_exists = True
                continue

            # Assuming only one source
            system_qh = qh_all.get(SYSTEM, {})
            # Assuming only one resource
            resource = 'astakos.pending_app'
            try:
                qh_values = system_qh[resource]
                qh_value = qh_values['usage']
                qh_pending = qh_values['pending']
            except KeyError:
                write("Resource '%s' does not exist in Quotaholder"
                      " for user '%s'!\n" % (resource, uuid))
                continue
            if qh_pending:
                write("Pending commission. User '%s', resource '%s'.\n" %
                      (uuid, resource))
                pending_exists = True
                continue
            if db_value != qh_value:
                data = (uuid, resource, db_value, qh_value)
                unsynced.append(data)

        headers = ("User", "Resource", "Astakos", "Quotaholder")
        if unsynced:
            pprint_table(self.stderr, unsynced, headers)
            if options["fix"]:
                provisions = map(create_provision, unsynced)
                try:
                    s = qh.issue_commission('astakos', provisions,
                                            name='RECONCILE', force=force)
                except qh_exception.NoCapacityError:
                    write("Reconciling failed because a limit has been "
                          "reached. Use --force to ignore the check.\n")
                    return

                qh.resolve_pending_commission('astakos', s)
                write("Fixed unsynced resources\n")

        if pending_exists:
            write("Found pending commissions. "
                  "This is probably a bug. Please report.\n")
        elif not (unsynced or unknown_user_exists):
            write("Everything in sync.\n")
    def handle(self, *args, **options):
        write = self.stdout.write
        force = options['force']
        userid = options['userid']

        try:
            astakos = Component.objects.get(name="astakos")
        except Component.DoesNotExist:
            raise CommandError("Component 'astakos' not found.")

        query = [userid] if userid is not None else None
        qh_holdings = service_get_quotas(astakos, query)

        if userid is None:
            users = AstakosUser.objects.verified()
        else:
            try:
                users = [AstakosUser.objects.get(uuid=userid)]
            except AstakosUser.DoesNotExist:
                raise CommandError("There is no user with uuid '%s'." % userid)

        db_holdings = count_pending_app(users)

        pending_exists = False
        unknown_user_exists = False
        unsynced = []
        for user in users:
            uuid = user.uuid
            db_value = db_holdings.get(uuid, 0)
            try:
                qh_all = qh_holdings[uuid]
            except KeyError:
                write("User '%s' does not exist in Quotaholder!\n" % uuid)
                unknown_user_exists = True
                continue

            # Assuming only one source
            system_qh = qh_all.get(SYSTEM, {})
            # Assuming only one resource
            resource = 'astakos.pending_app'
            try:
                qh_values = system_qh[resource]
                qh_value = qh_values['usage']
                qh_pending = qh_values['pending']
            except KeyError:
                write("Resource '%s' does not exist in Quotaholder"
                      " for user '%s'!\n" % (resource, uuid))
                continue
            if qh_pending:
                write("Pending commission. User '%s', resource '%s'.\n" %
                      (uuid, resource))
                pending_exists = True
                continue
            if db_value != qh_value:
                data = (uuid, resource, db_value, qh_value)
                unsynced.append(data)

        headers = ("User", "Resource", "Astakos", "Quotaholder")
        if unsynced:
            pprint_table(self.stderr, unsynced, headers)
            if options["fix"]:
                provisions = map(create_provision, unsynced)
                try:
                    s = qh.issue_commission('astakos',
                                            provisions,
                                            name='RECONCILE',
                                            force=force)
                except qh_exception.NoCapacityError:
                    write("Reconciling failed because a limit has been "
                          "reached. Use --force to ignore the check.\n")
                    return

                qh.resolve_pending_commission('astakos', s)
                write("Fixed unsynced resources\n")

        if pending_exists:
            write("Found pending commissions. "
                  "This is probably a bug. Please report.\n")
        elif not (unsynced or unknown_user_exists):
            write("Everything in sync.\n")
    def handle(self, *args, **options):
        write = self.stderr.write
        force = options['force']
        userid = options['userid']
        project = options['project']

        resources = [quotas.PENDING_APP_RESOURCE]

        try:
            astakos = Component.objects.get(name="astakos")
        except Component.DoesNotExist:
            raise CommandError("Component 'astakos' not found.")

        query = [userid] if userid is not None else None
        qh_holdings = quotas.service_get_quotas(astakos, query)
        query = [project] if project is not None else None
        qh_project_holdings = quotas.service_get_project_quotas(astakos, query)

        if userid is None:
            users = AstakosUser.objects.accepted().select_related(
                'base_project')
        else:
            try:
                user = AstakosUser.objects.get(uuid=userid)
            except AstakosUser.DoesNotExist:
                raise CommandError("There is no user with uuid '%s'." % userid)
            if not user.is_accepted():
                raise CommandError("%s is not an accepted user." % userid)
            users = [user]

        db_holdings = count_pending_app(users)

        db_project_holdings = {}
        for user, user_holdings in db_holdings.iteritems():
            db_project_holdings.update(user_holdings)

        unsynced_users, users_pending, users_unknown =\
            reconcile.check_users(self.stderr, resources,
                                  db_holdings, qh_holdings)

        unsynced_projects, projects_pending, projects_unknown =\
            reconcile.check_projects(self.stderr, resources,
                                     db_project_holdings, qh_project_holdings)
        pending_exists = users_pending or projects_pending
        unknown_exists = users_unknown or projects_unknown

        headers = ("Type", "Holder", "Source", "Resource", "Astakos",
                   "Quotaholder")
        unsynced = unsynced_users + unsynced_projects
        if unsynced:
            pprint_table(self.stdout, unsynced, headers)
            if options["fix"]:
                user_provisions = create_user_provisions(unsynced_users)
                project_provisions = create_project_provisions(
                    unsynced_projects)
                provisions = user_provisions + project_provisions
                name = ("client: reconcile-resources-astakos, time: %s" %
                        datetime.now())
                try:
                    s = qh.issue_commission('astakos',
                                            provisions,
                                            name=name,
                                            force=force)
                except qh_exception.NoCapacityError:
                    write("Reconciling failed because a limit has been "
                          "reached. Use --force to ignore the check.\n")
                    return

                qh.resolve_pending_commission('astakos', s)
                write("Fixed unsynced resources\n")

        if pending_exists:
            write("Found pending commissions. "
                  "This is probably a bug. Please report.\n")
        elif not (unsynced or unknown_exists):
            write("Everything in sync.\n")
    def handle(self, *args, **options):
        write = self.stderr.write
        force = options['force']
        userid = options['userid']
        project = options['project']

        resources = [quotas.PENDING_APP_RESOURCE]

        try:
            astakos = Component.objects.get(name="astakos")
        except Component.DoesNotExist:
            raise CommandError("Component 'astakos' not found.")

        query = [userid] if userid is not None else None
        qh_holdings = quotas.service_get_quotas(astakos, query)
        query = [project] if project is not None else None
        qh_project_holdings = quotas.service_get_project_quotas(astakos, query)

        if userid is None:
            users = AstakosUser.objects.accepted().select_related(
                'base_project')
        else:
            try:
                user = AstakosUser.objects.get(uuid=userid)
            except AstakosUser.DoesNotExist:
                raise CommandError("There is no user with uuid '%s'." % userid)
            if not user.is_accepted():
                raise CommandError("%s is not an accepted user." % userid)
            users = [user]

        db_holdings = count_pending_app(users)

        db_project_holdings = {}
        for user, user_holdings in db_holdings.iteritems():
            db_project_holdings.update(user_holdings)

        unsynced_users, users_pending, users_unknown =\
            reconcile.check_users(self.stderr, resources,
                                  db_holdings, qh_holdings)

        unsynced_projects, projects_pending, projects_unknown =\
            reconcile.check_projects(self.stderr, resources,
                                     db_project_holdings, qh_project_holdings)
        pending_exists = users_pending or projects_pending
        unknown_exists = users_unknown or projects_unknown

        headers = ("Type", "Holder", "Source", "Resource",
                   "Astakos", "Quotaholder")
        unsynced = unsynced_users + unsynced_projects
        if unsynced:
            pprint_table(self.stdout, unsynced, headers)
            if options["fix"]:
                user_provisions = create_user_provisions(unsynced_users)
                project_provisions = create_project_provisions(
                    unsynced_projects)
                provisions = user_provisions + project_provisions
                name = ("client: reconcile-resources-astakos, time: %s"
                        % datetime.now())
                try:
                    s = qh.issue_commission('astakos', provisions,
                                            name=name, force=force)
                except qh_exception.NoCapacityError:
                    write("Reconciling failed because a limit has been "
                          "reached. Use --force to ignore the check.\n")
                    return

                qh.resolve_pending_commission('astakos', s)
                write("Fixed unsynced resources\n")

        if pending_exists:
            write("Found pending commissions. "
                  "This is probably a bug. Please report.\n")
        elif not (unsynced or unknown_exists):
            write("Everything in sync.\n")