示例#1
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')
        envName     = self.get_option('environment')

        env = get_environment(orgName, envName)
        prod = get_product(orgName, prodName, prodLabel, prodId)

        returnCode = os.EX_OK

        cset = self.csapi.create(orgName, env["id"], self.create_cs_name(), constants.PROMOTION)
        try:
            self.csapi.add_content(cset["id"], "products", {'product_id': prod['id']})
            task = self.csapi.apply(cset["id"])
            task = AsyncTask(task)

            run_spinner_in_bg(wait_for_async_task, [task], message=_("Promoting the product, please wait... "))

            if task.succeeded():
                print _("Product [ %(prod_name)s ] promoted to environment [ %(envName)s ] " \
                    % {'prod_name':prod["name"], 'envName':envName})
                returnCode = os.EX_OK
            else:
                print _("Product [ %(prod_name)s ] promotion failed: %(task_errors)s" \
                    % {'prod_name':prod["name"], 'task_errors':format_task_errors(task.errors())} )
                returnCode = os.EX_DATAERR

        except Exception:
            #exception message is printed from action's main method
            raise

        return returnCode
示例#2
0
    def run(self):
        provName = self.get_option("name")
        orgName = self.get_option("org")

        prov = get_provider(orgName, provName)

        task = AsyncTask(self.api.last_sync_status(prov["id"]))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            prov["progress"] = _("%(task_progress)d%% done (%(pkgsCount)d of %(pkgsTotal)d packages downloaded)") % {
                "task_progress": task.get_progress() * 100,
                "pkgsCount": pkgsTotal - pkgsLeft,
                "pkgsTotal": pkgsTotal,
            }

        # TODO: last errors?

        self.printer.add_column("id", _("ID"))
        self.printer.add_column("name", _("Name"))

        self.printer.add_column("last_sync", _("Last Sync"), formatter=format_sync_time)
        self.printer.add_column("sync_state", _("Sync State"), formatter=format_sync_state)
        self.printer.add_column("progress", _("Progress"), show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Provider Status"))
        self.printer.print_item(prov)
        return os.EX_OK
示例#3
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')

        prod = get_product(orgName, prodName, prodLabel, prodId)

        task = AsyncTask(self.api.last_sync_status(orgName, prod['id']))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            prod['progress'] = ("%d%% done (%d of %d packages downloaded)" %
                (task.get_progress()*100, pkgsTotal-pkgsLeft, pkgsTotal))

        #TODO: last errors?

        batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \
            {'provider_id': _("Provider ID")}, {'provider_name': _("Provider Name")})
        self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time)
        self.printer.add_column('sync_state', _("Sync State"), formatter=format_sync_state)
        self.printer.add_column('progress', _("Progress"), show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Product Status"))
        self.printer.print_item(prod)
        return os.EX_OK
示例#4
0
    def run(self):
        repo = self.get_repo()

        task = AsyncTask(self.api.last_sync_status(repo["id"]))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            repo["progress"] = "%(task_progress)d%% done (%(pkgs_count)d of %(pkgs_total)d packages downloaded)" % {
                "task_progress": task.get_progress() * 100,
                "pkgs_count": pkgsTotal - pkgsLeft,
                "pkgs_total": pkgsTotal,
            }

        repo["last_errors"] = format_sync_errors(task)

        self.printer.add_column("package_count", _("Package Count"))
        self.printer.add_column("last_sync", _("Last Sync"), formatter=format_sync_time)
        self.printer.add_column("sync_state", _("Sync State"), formatter=format_sync_state)
        if "next_scheduled_sync" in repo:
            self.printer.add_column("next_scheduled_sync", _("Next Scheduled Sync"), formatter=format_sync_time)
        self.printer.add_column("progress", _("Progress"), show_with=printer.VerboseStrategy)
        self.printer.add_column("last_errors", _("Last Errors"), multiline=True, show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Repository Status"))
        self.printer.print_item(repo)
        return os.EX_OK
示例#5
0
    def run(self):
        provName = self.get_option('name')
        orgName  = self.get_option('org')

        prov = get_provider(orgName, provName)

        task = AsyncTask(self.api.last_sync_status(prov['id']))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            prov['progress'] = (_("%(task_progress)d%% done (%(pkgsCount)d of %(pkgsTotal)d packages downloaded)") % \
                {'task_progress':task.get_progress()*100, 'pkgsCount':pkgsTotal-pkgsLeft, 'pkgsTotal':pkgsTotal})

        #TODO: last errors?

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))

        self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time)
        self.printer.add_column('sync_state', _("Sync State"), formatter=format_sync_state)
        self.printer.add_column('progress', _("Progress"), show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Provider Status"))
        self.printer.print_item(prov)
        return os.EX_OK
示例#6
0
def wait_for_async_task(task, delay=1):
    if not isinstance(task, AsyncTask):
        task = AsyncTask(task)

    while task.is_running():
        time.sleep(delay)
        task.update()
    return task.get_hashes()
示例#7
0
    def run(self):
        name = self.get_option('name')

        task = self.api.delete(name)
        task = AsyncTask(task)

        run_spinner_in_bg(wait_for_async_task, [task], message=_("Deleting the organization, please wait... "))

        if task.succeeded():
            print _("Successfully deleted org [ %s ]") % name
            return os.EX_OK
        else:
            print _("Organization [ %(name)s ] deletion failed: %(format_task_errors)s" \
                % {'name':name, 'format_task_errors':format_task_errors(task.errors())} )
            return os.EX_DATAERR
示例#8
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        async = self.get_option('async')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')

        view = get_content_view(org_name, view_label, view_name, view_id)

        environment = get_environment(org_name, env_name)
        env_id = environment["id"]

        task = self.api.promote(view["id"], env_id)

        if not async:
            task = AsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task],
                    message=_("Promoting content view, please wait..."))

            return evaluate_task_status(task,
                failed = _("View [ %s ] promotion failed") % view["name"],
                ok =     _("Content view [ %(view)s ] promoted to environment [ %(env)s ]") %
                    {"view": view["name"], "env": environment["name"]},
            )

        else:
            print _("Promotion task [ %s ] was successfully created.") % (task["uuid"])
            return os.EX_OK
    def run(self):
        org_name    = self.get_option('org')
        label       = self.get_option('label')
        name        = self.get_option('name')
        def_id      = self.get_option('id')
        view_label  = self.get_option('view_label')
        view_name   = self.get_option('view_name')
        description = self.get_option('description')
        async       = self.get_option('async')
        cvd         = get_cv_definition(org_name, label, name, def_id)


        task = self.api.publish(org_name, cvd["id"], view_name, view_label, description)

        if not async:
            task = AsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task],
                              message=_("Publishing content view, please wait..."))

            return evaluate_task_status(task,
                ok =     _("Content view [ %s ] published successfully.") % view_name,
                failed = _("Content view [ %s ] failed to be promoted") % view_name
            )

        else:
            print _("Publish task [ %s ] was successfully created.") % task['uuid']
            return os.EX_OK
示例#10
0
文件: repo.py 项目: bcrochet/katello
    def run(self):
        repo = self.get_repo()

        task = AsyncTask(self.api.sync(repo['id']))
        run_async_task_with_status(task, ProgressBar())

        if task.succeeded():
            print _("Repo [ %s ] synced" % repo['name'])
            return os.EX_OK
        elif task.cancelled():
            print _("Repo [ %s ] synchronization canceled" % repo['name'])
            return os.EX_OK
        else:
            print _("Repo [ %(repo_name)s ] failed to sync: %(sync_errors)s") \
                % {'repo_name':repo['name'], 'sync_errors':format_sync_errors(task)}
            return os.EX_DATAERR
示例#11
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')
        envName     = self.get_option('environment')

        env = get_environment(orgName, envName)
        prod = get_product(orgName, prodName, prodLabel, prodId)


        if not self.repoapi.repos_by_product(orgName, prod['id']):
            print _("Product [ %(prod_name)s ] has no repository") % {'prod_name':prod['name']}
            return os.EX_DATAERR

        cset = self.csapi.create(orgName, env["id"], self.create_cs_name(), constants.PROMOTION)

        self.csapi.add_content(cset["id"], "products", {'product_id': prod['id']})
        task = self.csapi.apply(cset["id"])
        task = AsyncTask(task)

        run_spinner_in_bg(wait_for_async_task, [task], message=_("Promoting the product, please wait... "))

        return evaluate_task_status(task,
            failed = _("Product [ %s ] promotion failed") % prod["name"],
            ok =     _("Product [ %(prod)s ] promoted to environment [ %(env)s ]") %
                {'prod':prod["name"], 'env':envName}
        )
示例#12
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')
        prod = get_product(orgName, prodName, prodLabel, prodId)
        set_name      = self.get_option('set_name')

        task = AsyncTask(self.api.disable_repository_set(orgName, prod['id'], set_name))
        task = run_spinner_in_bg(wait_for_async_task, [task],
                message=_("Disabling Repository Set..."))
        task = AsyncTask(task)
        return evaluate_task_status(task,
            failed = _("Repository disable [ %(set_name)s ] failed.") % 
                        {'set_name':set_name},
            ok = _("Repository Set [ %(set_name)s ] disabled.") % {'set_name':set_name}
        )
示例#13
0
    def sync_provider(self, providerName, orgName):
        prov = get_provider(orgName, providerName)

        task = AsyncTask(self.api.sync(prov["id"]))
        run_async_task_with_status(task, ProgressBar())

        if task.failed():
            errors = format_sync_errors(task)
            print _(
                "Provider [ %(providerName)s ] failed to sync: %(errors)s"
                % {"providerName": providerName, "errors": errors}
            )
            return os.EX_DATAERR
        elif task.cancelled():
            print _("Provider [ %s ] synchronization canceled" % providerName)
            return os.EX_DATAERR

        print _("Provider [ %s ] synchronized" % providerName)
        return os.EX_OK
示例#14
0
    def run(self):
        csName = self.get_option('name')
        orgName = self.get_option('org')
        envName = self.get_option('environment')

        cset = get_changeset(orgName, envName, csName)

        task = self.api.apply(cset["id"])
        task = AsyncTask(task)

        run_spinner_in_bg(wait_for_async_task, [task], message=_("Applying the changeset, please wait... "))

        if task.succeeded():
            print _("Changeset [ %s ] applied" % csName)
            return os.EX_OK
        else:
            print _("Changeset [ %(csName)s ] promotion failed: %(task_errors)s" \
                % {'csName':csName, 'task_errors':format_task_errors(task.errors())})
            return os.EX_DATAERR
示例#15
0
    def run(self):
        repo = self.get_repo()

        task = AsyncTask(self.api.sync(repo['id']))
        run_async_task_with_status(task, ProgressBar())

        return evaluate_task_status(task,
            failed =   _("Repo [ %s ] failed to sync") % repo["name"],
            canceled = _("Repo [ %s ] synchronization canceled") % repo["name"],
            ok =       _("Repo [ %s ] synchronized") % repo["name"]
        )
示例#16
0
    def run(self):
        name = self.get_option('name')

        task = self.api.delete(name)
        task = AsyncTask(task)

        run_spinner_in_bg(wait_for_async_task, [task], message=_("Deleting the organization, please wait... "))

        return evaluate_task_status(task,
            failed = _("Organization [ %s ] deletion failed:") % name,
            ok =     _("Successfully deleted org [ %s ]") % name
        )
示例#17
0
    def sync_provider(self, providerName, orgName):
        prov = get_provider(orgName, providerName)

        task = AsyncTask(self.api.sync(prov["id"]))
        run_async_task_with_status(task, ProgressBar())

        return evaluate_task_status(
            task,
            failed=_("Provider [ %s ] failed to sync") % providerName,
            canceled=_("Provider [ %s ] synchronization canceled") %
            providerName,
            ok=_("Provider [ %s ] synchronized") % providerName)
示例#18
0
    def run(self):
        provName = self.get_option('name')
        orgName = self.get_option('org')

        prov = get_provider(orgName, provName)

        task = AsyncTask(self.api.last_sync_status(prov['id']))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            prov['progress'] = (_("%(task_progress)d%% done (%(pkgsCount)d of %(pkgsTotal)d packages downloaded)") % \
                {'task_progress':task.get_progress()*100, 'pkgsCount':pkgsTotal-pkgsLeft, 'pkgsTotal':pkgsTotal})

        #TODO: last errors?

        self.printer.add_column('id', _("ID"))
        self.printer.add_column('name', _("Name"))

        self.printer.add_column('last_sync',
                                _("Last Sync"),
                                formatter=format_sync_time)
        self.printer.add_column('sync_state',
                                _("Sync State"),
                                formatter=format_sync_state)
        self.printer.add_column('progress',
                                _("Progress"),
                                show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Provider Status"))
        self.printer.print_item(prov)
        return os.EX_OK
示例#19
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')

        prod = get_product(orgName, prodName, prodLabel, prodId)

        task = AsyncTask(self.api.last_sync_status(orgName, prod['id']))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            prod['progress'] = ("%d%% done (%d of %d packages downloaded)" %
                (task.get_progress()*100, pkgsTotal-pkgsLeft, pkgsTotal))

        #TODO: last errors?

        batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \
            {'provider_id': _("Provider ID")}, {'provider_name': _("Provider Name")})
        self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time)
        self.printer.add_column('sync_state', _("Sync State"), formatter=format_sync_state)
        self.printer.add_column('progress', _("Progress"), show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Product Status"))
        self.printer.print_item(prod)
        return os.EX_OK
示例#20
0
def run_async_task_with_status(task, progress_bar, delay=1):
    if not isinstance(task, AsyncTask):
        task = AsyncTask(task)

    while task.is_running():
        time.sleep(delay)
        task.update()
        progress_bar.update_progress(task.get_progress())

    progress_bar.done()
    return task.get_hashes()
示例#21
0
def wait_for_async_task(task, delay=1):
    if not isinstance(task, AsyncTask):
        task = AsyncTask(task)

    while task.is_running():
        time.sleep(delay)
        task.update()
    return task.get_hashes()
示例#22
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')

        prod = get_product(orgName, prodName, prodLabel, prodId)

        task = AsyncTask(self.api.sync(orgName, prod["id"]))
        run_async_task_with_status(task, ProgressBar())

        if task.failed():
            errors = [t["result"]['errors'][0] for t in task.get_hashes() if t['state'] == 'error' and
                                                                             isinstance(t["result"], dict) and
                                                                             "errors" in t["result"]]
            print _("Product [ %(prod_name)s ] failed to sync: %(errors)s" \
                % {'prod_name':prod["name"], 'errors':errors})
            return os.EX_DATAERR
        elif task.cancelled():
            print _("Product [ %s ] synchronization canceled" % prod["name"])
            return os.EX_DATAERR

        print _("Product [ %s ] synchronized" % prod["name"])
        return os.EX_OK
示例#23
0
文件: repo.py 项目: guymatz/katello
    def run(self):
        repo = self.get_repo()

        task = AsyncTask(self.api.last_sync_status(repo['id']))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            repo['progress'] = ("%(task_progress)d%% done (%(pkgs_count)d of %(pkgs_total)d packages downloaded)" %
                {'task_progress':task.get_progress()*100, 'pkgs_count':pkgsTotal-pkgsLeft, 'pkgs_total':pkgsTotal})

        repo['last_errors'] = format_sync_errors(task)

        self.printer.add_column('package_count', _("Package Count"))
        self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time)
        self.printer.add_column('sync_state', _("Sync State"), formatter=format_sync_state)
        if 'next_scheduled_sync' in repo:
            self.printer.add_column('next_scheduled_sync', _("Next Scheduled Sync"), formatter=format_sync_time)
        self.printer.add_column('progress', _("Progress"), show_with=printer.VerboseStrategy)
        self.printer.add_column('last_errors', _("Last Errors"), multiline=True, show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Repository Status"))
        self.printer.print_item(repo)
        return os.EX_OK
示例#24
0
    def run(self):
        orgName     = self.get_option('org')
        prodName    = self.get_option('name')
        prodLabel   = self.get_option('label')
        prodId      = self.get_option('id')

        prod = get_product(orgName, prodName, prodLabel, prodId)

        task = AsyncTask(self.api.sync(orgName, prod["id"]))
        run_async_task_with_status(task, ProgressBar())

        return evaluate_task_status(task,
            failed =   _("Product [ %s ] failed to sync") % prod["name"],
            canceled = _("Product [ %s ] synchronization canceled") % prod["name"],
            ok =       _("Product [ %s ] synchronized") % prod["name"]
        )
示例#25
0
def run_async_task_with_status(task, progress_bar, delay=1):
    if not isinstance(task, AsyncTask):
        task = AsyncTask(task)

    while task.is_running():
        time.sleep(delay)
        task.update()
        progress_bar.update_progress(task.get_progress())

    progress_bar.done()
    return task.get_hashes()
示例#26
0
    def run(self):
        csName = self.get_option('name')
        orgName = self.get_option('org')
        envName = self.get_option('environment')

        cset = get_changeset(orgName, envName, csName)

        task = self.api.apply(cset["id"])
        task = AsyncTask(task)

        run_spinner_in_bg(wait_for_async_task, [task],
                          message=_("Applying the changeset, please wait... "))

        return evaluate_task_status(
            task,
            failed=_("Changeset [ %s ] promotion failed") % csName,
            ok=_("Changeset [ %s ] applied") % csName)
示例#27
0
    def run(self):
        org_name = self.get_option('org')
        view_label = self.get_option('label')
        view_id = self.get_option('id')
        view_name = self.get_option('name')
        async = self.get_option('async')

        view = get_content_view(org_name, view_label, view_name, view_id)

        task = self.api.refresh(view["id"])

        if not async:
            task = AsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task],
                              message=_("Refreshing view, please wait..."))

            return evaluate_task_status(task,
                ok =     _("Content view [ %s ] was successfully refreshed.") % view["name"],
                failed = _("View [ %s ] refresh failed") % view["name"]
            )

        else:
            print _("Refresh task [ %s ] was successfully created.") % (task["uuid"])
            return os.EX_OK
示例#28
0
    def run(self):
        repo = self.get_repo()

        task = AsyncTask(self.api.last_sync_status(repo['id']))

        if task.is_running():
            pkgsTotal = task.total_count()
            pkgsLeft = task.items_left()
            repo['progress'] = ("%(task_progress)d%% done (%(pkgs_count)d of %(pkgs_total)d packages downloaded)" %
                {'task_progress':task.get_progress()*100, 'pkgs_count':pkgsTotal-pkgsLeft, 'pkgs_total':pkgsTotal})

        repo['last_errors'] = format_sync_errors(task)

        self.printer.add_column('package_count', _("Package Count"))
        self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time)
        self.printer.add_column('sync_state', _("Sync State"), formatter=format_sync_state)
        if 'next_scheduled_sync' in repo:
            self.printer.add_column('next_scheduled_sync', _("Next Scheduled Sync"), formatter=format_sync_time)
        self.printer.add_column('progress', _("Progress"), show_with=printer.VerboseStrategy)
        self.printer.add_column('last_errors', _("Last Errors"), multiline=True, show_with=printer.VerboseStrategy)

        self.printer.set_header(_("Repository Status"))
        self.printer.print_item(repo)
        return os.EX_OK