Ejemplo n.º 1
0
def service_project_quotas(request):
    projectstr = request.GET.get("project")
    projects = projectstr.split(",") if projectstr is not None else None
    result = service_get_project_quotas(request.component_instance, projects=projects)

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

    return json_response(result)
Ejemplo n.º 2
0
def service_project_quotas(request):
    projectstr = request.GET.get('project')
    projects = projectstr.split(',') if projectstr is not None else None
    result = service_get_project_quotas(request.component_instance,
                                        projects=projects)

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

    return json_response(result)
Ejemplo n.º 3
0
    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")
Ejemplo n.º 4
0
    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")