def handle(self, *args, **options):
        write = self.stderr.write
        userid = options['userid']
        project = options["project"]

        # Get holdings from Cyclades DB
        db_holdings = util.get_db_holdings(user=userid, project=project)
        db_project_holdings = util.get_db_holdings(project=project,
                                                   for_users=False)

        # Get holdings from QuotaHolder
        try:
            qh_holdings = util.get_qh_users_holdings(
                [userid] if userid is not None else None,
                [project] if project is not None else None)
            qh_project_holdings = util.get_qh_project_holdings(
                [project] if project is not None else None)
        except errors.AstakosClientException as e:
            raise CommandError(e)

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

        unsynced_projects, projects_pending, projects_unknown =\
            reconcile.check_projects(self.stderr, quotas.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",
                   "Database", "Quotaholder")
        unsynced = unsynced_users + unsynced_projects
        if unsynced:
            pprint_table(self.stdout, unsynced, headers)
            if options["fix"]:
                qh = quotas.Quotaholder.get()
                force = options["force"]
                name = ("client: reconcile-resources-cyclades, time: %s"
                        % datetime.now())
                user_provisions = reconcile.create_user_provisions(
                    unsynced_users)
                project_provisions = reconcile.create_project_provisions(
                    unsynced_projects)
                try:
                    qh.issue_commission_generic(
                        user_provisions, project_provisions,
                        name=name, force=force,
                        auto_accept=True)
                except quotas.errors.QuotaLimit:
                    write("Reconciling failed because a limit has been "
                          "reached. Use --force to ignore the check.\n")
                    return
                write("Fixed unsynced resources\n")

        if pending_exists:
            write("Found pending commissions. Run 'snf-manage"
                  " reconcile-commissions-cyclades'\n")
        elif not (unsynced or unknown_exists):
            write("Everything in sync.\n")
Ejemplo n.º 2
0
    def handle(self, **options):
        write = self.stdout.write
        try:
            backend.pre_exec()
            userid = options['userid']
            project = options['project']

            # Get holding from Pithos DB
            db_usage = backend.node.node_account_usage(userid, project)
            db_project_usage = backend.node.node_project_usage(project)

            users = set(db_usage.keys())
            if userid and userid not in users:
                if backend._lookup_account(userid) is None:
                    write("User '%s' does not exist in DB!\n" % userid)
                    return

            # Get holding from Quotaholder
            try:
                qh_result = backend.astakosclient.service_get_quotas(userid)
            except NotFound:
                write("User '%s' does not exist in Quotaholder!\n" % userid)
                return

            try:
                qh_project_result = \
                    backend.astakosclient.service_get_project_quotas(project)
            except NotFound:
                write("Project '%s' does not exist in Quotaholder!\n" %
                      project)

            unsynced_users, users_pending, users_unknown =\
                reconcile.check_users(self.stderr, RESOURCES,
                                      db_usage, qh_result)

            unsynced_projects, projects_pending, projects_unknown =\
                reconcile.check_projects(self.stderr, RESOURCES,
                                         db_project_usage, qh_project_result)
            pending_exists = users_pending or projects_pending
            unknown_exists = users_unknown or projects_unknown

            headers = ("Type", "Holder", "Source", "Resource",
                       "Database", "Quotaholder")
            unsynced = unsynced_users + unsynced_projects
            if unsynced:
                utils.pprint_table(self.stdout, unsynced, headers)
                if options["fix"]:
                    force = options["force"]
                    name = ("client: reconcile-resources-pithos, time: %s"
                            % datetime.now())
                    user_provisions = reconcile.create_user_provisions(
                        unsynced_users)
                    project_provisions = reconcile.create_project_provisions(
                        unsynced_projects)
                    try:
                        backend.astakosclient.issue_commission_generic(
                            user_provisions, project_provisions, name=name,
                            force=force, auto_accept=True)
                    except QuotaLimit:
                        write("Reconciling failed because a limit has been "
                              "reached. Use --force to ignore the check.\n")
                        return
                    write("Fixed unsynced resources\n")

            if pending_exists:
                write("Found pending commissions. Run 'snf-manage"
                      " reconcile-commissions-pithos'\n")
            elif not (unsynced or unknown_exists):
                write("Everything in sync.\n")
        except BaseException as e:
            backend.post_exec(False)
            raise CommandError(e)
        else:
            backend.post_exec(True)
        finally:
            backend.close()
    def handle(self, *args, **options):
        write = self.stderr.write
        userid = options['userid']
        project = options["project"]

        # Get holdings from Cyclades DB
        db_holdings = util.get_db_holdings(user=userid, project=project)
        db_project_holdings = util.get_db_holdings(project=project,
                                                   for_users=False)

        # Get holdings from QuotaHolder
        try:
            qh_holdings = util.get_qh_users_holdings(
                [userid] if userid is not None else None,
                [project] if project is not None else None)
            qh_project_holdings = util.get_qh_project_holdings(
                [project] if project is not None else None)
        except errors.AstakosClientException as e:
            raise CommandError(e)

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

        unsynced_projects, projects_pending, projects_unknown =\
            reconcile.check_projects(self.stderr, quotas.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", "Database",
                   "Quotaholder")
        unsynced = unsynced_users + unsynced_projects
        if unsynced:
            pprint_table(self.stdout, unsynced, headers)
            if options["fix"]:
                qh = quotas.Quotaholder.get()
                force = options["force"]
                name = ("client: reconcile-resources-cyclades, time: %s" %
                        datetime.now())
                user_provisions = reconcile.create_user_provisions(
                    unsynced_users)
                project_provisions = reconcile.create_project_provisions(
                    unsynced_projects)
                try:
                    qh.issue_commission_generic(user_provisions,
                                                project_provisions,
                                                name=name,
                                                force=force,
                                                auto_accept=True)
                except quotas.errors.QuotaLimit:
                    write("Reconciling failed because a limit has been "
                          "reached. Use --force to ignore the check.\n")
                    return
                write("Fixed unsynced resources\n")

        if pending_exists:
            write("Found pending commissions. Run 'snf-manage"
                  " reconcile-commissions-cyclades'\n")
        elif not (unsynced or unknown_exists):
            write("Everything in sync.\n")
Ejemplo n.º 4
0
    def handle(self, **options):
        write = self.stdout.write
        try:
            backend.pre_exec()
            userid = options['userid']
            project = options['project']

            # Get holding from Pithos DB
            db_usage = backend.node.node_account_usage(userid, project)
            db_project_usage = backend.node.node_project_usage(project)

            users = set(db_usage.keys())
            if userid and userid not in users:
                if backend._lookup_account(userid) is None:
                    write("User '%s' does not exist in DB!\n" % userid)
                    return

            # Get holding from Quotaholder
            try:
                qh_result = backend.astakosclient.service_get_quotas(userid)
            except NotFound:
                write("User '%s' does not exist in Quotaholder!\n" % userid)
                return

            try:
                qh_project_result = \
                    backend.astakosclient.service_get_project_quotas(project)
            except NotFound:
                write("Project '%s' does not exist in Quotaholder!\n" %
                      project)

            unsynced_users, users_pending, users_unknown =\
                reconcile.check_users(self.stderr, RESOURCES,
                                      db_usage, qh_result)

            unsynced_projects, projects_pending, projects_unknown =\
                reconcile.check_projects(self.stderr, RESOURCES,
                                         db_project_usage, qh_project_result)
            pending_exists = users_pending or projects_pending
            unknown_exists = users_unknown or projects_unknown

            headers = ("Type", "Holder", "Source", "Resource", "Database",
                       "Quotaholder")
            unsynced = unsynced_users + unsynced_projects
            if unsynced:
                utils.pprint_table(self.stdout, unsynced, headers)
                if options["fix"]:
                    force = options["force"]
                    name = ("client: reconcile-resources-pithos, time: %s" %
                            datetime.now())
                    user_provisions = reconcile.create_user_provisions(
                        unsynced_users)
                    project_provisions = reconcile.create_project_provisions(
                        unsynced_projects)
                    try:
                        backend.astakosclient.issue_commission_generic(
                            user_provisions,
                            project_provisions,
                            name=name,
                            force=force,
                            auto_accept=True)
                    except QuotaLimit:
                        write("Reconciling failed because a limit has been "
                              "reached. Use --force to ignore the check.\n")
                        return
                    write("Fixed unsynced resources\n")

            if pending_exists:
                write("Found pending commissions. Run 'snf-manage"
                      " reconcile-commissions-pithos'\n")
            elif not (unsynced or unknown_exists):
                write("Everything in sync.\n")
        except BaseException as e:
            backend.post_exec(False)
            raise CommandError(e)
        else:
            backend.post_exec(True)
        finally:
            backend.close()