Exemple #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
Exemple #2
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        sys_name = self.get_option('name')
        sys_uuid = self.get_option('uuid')

        install = self.get_option('install')
        remove = self.get_option('remove')
        update = self.get_option('update')
        install_groups = self.get_option('install_groups')
        remove_groups = self.get_option('remove_groups')

        task = None

        if env_name is None:
            self.printer.set_header(_("Package Information for System [ %(sys_name)s ] in Org [ %(org_name)s ]") \
                % {'sys_name':sys_name, 'org_name':org_name})
        else:
            self.printer.set_header(_("Package Information for System [ %(sys_name)s ] " \
                "in Environment [ %(env_name)s ] in Org [ %(org_name)s ]") % \
                {'sys_name':sys_name, 'env_name':env_name, 'org_name':org_name})

        system = get_system(org_name, sys_name, env_name, sys_uuid)
        system_id = system['uuid']

        if install:
            task = self.api.install_packages(system_id, install)
        if remove:
            task = self.api.remove_packages(system_id, remove)
        if update:
            if update == '--all':
                update_packages = []
            else:
                update_packages = update
            task = self.api.update_packages(system_id, update_packages)
        if install_groups:
            task = self.api.install_package_groups(system_id, install_groups)
        if remove_groups:
            task = self.api.remove_package_groups(system_id, remove_groups)

        if task:
            uuid = task["uuid"]
            print (_("Performing remote action [ %s ]... ") % uuid)
            task = SystemAsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task])

            return evaluate_remote_action(task)

        packages = self.api.packages(system_id)

        batch_add_columns(self.printer, {'name': _("Name")}, {'vendor': _("Vendor")}, \
            {'version': _("Version")}, {'release': _("Release")}, {'arch': _("Arch")}, \
            show_with=printer.VerboseStrategy)
        self.printer.add_column('name_version_release_arch', _("Name_Version_Release_Arch"), \
            show_with=printer.GrepStrategy, \
            item_formatter=lambda p: "%s-%s-%s.%s" % (p['name'], p['version'], p['release'], p['arch']))

        self.printer.print_items(packages)

        return os.EX_OK
Exemple #3
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
Exemple #5
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}
        )
Exemple #6
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}
        )
    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
Exemple #8
0
    def run(self):
        org_name = self.get_option('org')
        env_name = self.get_option('environment')
        sys_name = self.get_option('name')
        sys_uuid = self.get_option('uuid')

        install = self.get_option('install')
        remove = self.get_option('remove')
        update = self.get_option('update')
        install_groups = self.get_option('install_groups')
        remove_groups = self.get_option('remove_groups')

        task = None

        if env_name is None:
            self.printer.set_header(_("Package Information for System [ %(sys_name)s ] in Org [ %(org_name)s ]") \
                % {'sys_name':sys_name, 'org_name':org_name})
        else:
            self.printer.set_header(_("Package Information for System [ %(sys_name)s ] " \
                "in Environment [ %(env_name)s ] in Org [ %(org_name)s ]") % \
                {'sys_name':sys_name, 'env_name':env_name, 'org_name':org_name})

        system = get_system(org_name, sys_name, env_name, sys_uuid)
        system_id = system['uuid']

        if install:
            task = self.api.install_packages(system_id, install)
        if remove:
            task = self.api.remove_packages(system_id, remove)
        if update:
            if update == '--all':
                update_packages = []
            else:
                update_packages = update
            task = self.api.update_packages(system_id, update_packages)
        if install_groups:
            task = self.api.install_package_groups(system_id, install_groups)
        if remove_groups:
            task = self.api.remove_package_groups(system_id, remove_groups)

        if task:
            uuid = task["uuid"]
            print(_("Performing remote action [ %s ]... ") % uuid)
            task = SystemAsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task])

            return evaluate_remote_action(task)

        packages = self.api.packages(system_id)

        batch_add_columns(self.printer, {'name': _("Name")}, {'vendor': _("Vendor")}, \
            {'version': _("Version")}, {'release': _("Release")}, {'arch': _("Arch")}, \
            show_with=printer.VerboseStrategy)
        self.printer.add_column('name_version_release_arch', _("Name_Version_Release_Arch"), \
            show_with=printer.GrepStrategy, \
            item_formatter=lambda p: "%s-%s-%s.%s" % (p['name'], p['version'], p['release'], p['arch']))

        self.printer.print_items(packages)

        return os.EX_OK
Exemple #9
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
Exemple #10
0
    def discover_repositories(self, provider_id, url):
        print(_("Discovering repository urls, this could take some time..."))
        task = self.provider_api.repo_discovery(provider_id, url)

        run_spinner_in_bg(wait_for_async_task, [task])
        repourls = self.provider_api.provider(provider_id)['discovered_repos']

        if not len(repourls):
            system_exit(os.EX_OK, "No repositories discovered @ url location [%s]" % url)

        return repourls
Exemple #11
0
    def discover_repositories(self, provider_id, url):
        print(_("Discovering repository urls, this could take some time..."))
        task = self.provider_api.repo_discovery(provider_id, url)

        run_spinner_in_bg(wait_for_async_task, [task])
        repourls = self.provider_api.provider(provider_id)['discovered_repos']

        if not len(repourls):
            system_exit(os.EX_OK, "No repositories discovered @ url location [%s]" % url)

        return repourls
Exemple #12
0
    def run(self):
        org_name = self.get_option("name")

        task = AsyncTask(self.api.attach_all_systems(org_name))
        run_spinner_in_bg(wait_for_async_task, [task],
            message=_("Attaching available subscriptions to all systems, please wait... "))

        return evaluate_task_status(task,
            failed = _("Organization [ %s ] failed to attach subscriptions to all systems") % org_name,
            canceled = _("Organization [ %s ] canceled attachment of subscriptions to all systems") % org_name,
            ok = _("Organzation [ %s ] completed attachment of subscriptions to all systems") % org_name
        )
Exemple #13
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
        )
Exemple #14
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
        )
Exemple #15
0
    def run(self):
        provName = self.get_option('name')
        orgName  = self.get_option('org')

        prov = get_provider(orgName, provName)

        task = ManifestAsyncTask(self.api.refresh_manifest(prov["id"]))
        run_spinner_in_bg(wait_for_async_task, [task], message=_("Refreshing manifest, please wait... "))

        return ManifestAsyncTask.evaluate_task_status(task,
            failed =   _("Provider [ %s ] failed to refresh manifest") % provName,
            canceled = _("Provider [ %s ] canceled manifest refresh") % provName,
            ok =       _("Provider [ %s ] manifest refresh complete") % provName
        )
Exemple #16
0
    def run(self):
        repo_id = self.get_option("repo_id")
        repo_name = self.get_option("repo")
        org_name = self.get_option("org")
        env_name = self.get_option("environment")
        prod_name = self.get_option("product")
        prod_label = self.get_option("product_label")
        prod_id = self.get_option("product_id")
        filepath = self.get_option("filepath")
        content_type = self.get_option("content_type")
        chunk = self.get_option("chunk")

        if not repo_id:
            repo = get_repo(org_name, repo_name, prod_name, prod_label, prod_id, env_name, False)
            repo_id = repo["id"]

        if not self._valid_upload_type(repo_id, content_type):
            return os.EX_DATAERR

        paths = []
        if os.path.isdir(filepath):
            for dirname, __, filenames in os.walk(filepath):
                paths = [os.path.join(dirname, filename) for filename in filenames]
        elif os.path.isfile(filepath):
            paths = [filepath]
        else:
            print _("Invalid path '%s'.") % filepath
            return os.EX_DATAERR

        uploads = []
        for path in paths:
            try:
                upload = self.send_file(path, repo_id, content_type, chunk)
                uploads.append(upload)
            except FileUploadError:
                if len(paths) > 1:
                    print _("Skipping file '%s'.") % path

        if uploads:
            run_spinner_in_bg(
                self.upload_api.import_into_repo, [repo_id, uploads], message=_("Importing content into repository")
            )

            self.remove_uploads(repo_id, uploads)

            print _("Successfully imported content into repository.")
            return os.EX_OK
        else:
            return os.EX_DATAERR
Exemple #17
0
    def run(self):
        provName = self.get_option('name')
        orgName = self.get_option('org')

        prov = get_provider(orgName, provName)

        task = ManifestAsyncTask(self.api.refresh_manifest(prov["id"]))
        run_spinner_in_bg(wait_for_async_task, [task],
                          message=_("Refreshing manifest, please wait... "))

        return ManifestAsyncTask.evaluate_task_status(
            task,
            failed=_("Provider [ %s ] failed to refresh manifest") % provName,
            canceled=_("Provider [ %s ] canceled manifest refresh") % provName,
            ok=_("Provider [ %s ] manifest refresh complete") % provName)
Exemple #18
0
    def send_file(self, filepath, repo_id, content_type, chunk):
        filename = os.path.basename(filepath)
        unit_key, metadata = ContentUpload.get_content_data(content_type, filepath)

        if unit_key is None and metadata is None:
            raise FileUploadError

        upload_id = self.upload_api.create(repo_id)["upload_id"]
        self.send_content(repo_id, upload_id, filepath, chunk)
        run_spinner_in_bg(self.upload_api.import_into_repo,
                          [repo_id, upload_id, unit_key, metadata],
                          message=_("Uploading '%s' to server, please... ") % filename)
        self.upload_api.delete(repo_id, upload_id)

        print _("Successfully uploaded '%s' into repository") % filename
Exemple #19
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
Exemple #20
0
    def run(self):
        provName = self.get_option("name")
        orgName = self.get_option("org")
        manifestPath = self.get_option("file")
        force = self.get_option("force")

        try:
            f = open(get_abs_path(manifestPath))
        except IOError:
            system_exit(os.EX_IOERR, _("File %s does not exist") % manifestPath)

        prov = get_provider(orgName, provName)

        try:
            response = run_spinner_in_bg(
                self.api.import_manifest, (prov["id"], f, force), message=_("Importing manifest, please wait... ")
            )
        except ServerRequestError, re:
            if (
                re.args[0] == 400
                and "displayMessage" in re.args[1]
                and re.args[1]["displayMessage"] == "Import is older than existing data"
            ):
                re.args[1]["displayMessage"] = (
                    "Import is older than existing data," + " please try with --force option to import manifest."
                )
            raise re, None, sys.exc_info()[2]
Exemple #21
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
        )
Exemple #22
0
    def run(self):
        org_name = self.get_option('org')
        group_name = self.get_option('name')

        install = self.get_option('install')
        remove = self.get_option('remove')
        update = self.get_option('update')
        install_groups = self.get_option('install_groups')
        remove_groups = self.get_option('remove_groups')
        update_groups = self.get_option('update_groups')

        job = None

        system_group = get_system_group(org_name, group_name)
        system_group_id = system_group['id']

        if install:
            job = self.api.install_packages(org_name, system_group_id, install)
        if remove:
            job = self.api.remove_packages(org_name, system_group_id, remove)
        if update:
            if update == '--all':
                update_packages = []
            else:
                update_packages = update
            job = self.api.update_packages(org_name, system_group_id,
                                           update_packages)
        if install_groups:
            job = self.api.install_package_groups(org_name, system_group_id,
                                                  install_groups)
        if remove_groups:
            job = self.api.remove_package_groups(org_name, system_group_id,
                                                 remove_groups)
        if update_groups:
            job = self.api.update_package_groups(org_name, system_group_id,
                                                 update_groups)

        if job:
            job_id = job["id"]
            print(_("Performing remote action [ %s ]... ") % job_id)
            job = SystemGroupAsyncJob(org_name, system_group_id, job)
            run_spinner_in_bg(wait_for_async_task, [job])

            return evaluate_remote_action(job)

        return os.EX_OK
Exemple #23
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)
Exemple #24
0
    def run(self):
        node_id = self.get_option("id")
        node_name = self.get_option("name")

        org_name = self.get_option('org')
        env_name = self.get_option('env_name')
        env_id = None
        message = _("Syncing node, please wait... ")
        if env_name is not None:
            env = get_environment(org_name, env_name)
            env_id = env['id']
            message = _("Syncing environment %s to node, please wait...") % env['name']

        node_id = get_node(node_name, node_id)['id']
        sync_tasks = self.api.sync(node_id, env_id)
        task = AsyncTask(sync_tasks)
        run_spinner_in_bg(wait_for_async_task, [task], message=message)
        print _("Sync Complete")
Exemple #25
0
    def send_file(self, filepath, repo_id, content_type, chunk):
        filename = os.path.basename(filepath)
        unit_key, metadata = ContentUpload.get_content_data(content_type, filepath)

        if unit_key is None and metadata is None:
            raise FileUploadError

        try:
            upload_id = self.upload_api.create(repo_id)["upload_id"]
            run_spinner_in_bg(
                self.send_content,
                [repo_id, upload_id, filepath, chunk],
                message=_("Uploading '%s' to server... ") % filename,
            )
        finally:
            print _("Successfully uploaded '%s' into repository") % filename

        return {"id": upload_id, "unit_key": unit_key, "metadata": metadata}
Exemple #26
0
    def run(self):
        org_name = self.get_option('name')
        informable_type = self.get_option('type').lower()
        async = not self.get_option('no_async')

        if async:
            task = AsyncTask(self.default_info_api.apply(org_name, informable_type, async)['task'])
            run_spinner_in_bg(wait_for_async_task, [task], message=_("Applying default info, please wait... "))

            return evaluate_task_status(task,
                failed   = _("Organization [ %s ] failed to apply default info") % org_name,
                canceled = _("Organization [ %s ] canceled applying default info") % org_name,
                ok       = _("Organization [ %s ] completed applying default info") % org_name
            )
        else:
            self.default_info_api.apply(org_name, informable_type, async)

            print _("Organization [ %s ] completed applying default info") % org_name
            return os.EX_OK
Exemple #27
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
    def run(self):
        org_name = self.get_option('name')
        informable_type = self.get_option('type').lower()
        async = not self.get_option('no_async')

        if async:
            task = AsyncTask(self.default_info_api.apply(org_name, informable_type, async)['task'])
            run_spinner_in_bg(wait_for_async_task, [task], message=_("Applying default info, please wait... "))

            return evaluate_task_status(task,
                failed   = _("Organization [ %s ] failed to apply default info") % org_name,
                canceled = _("Organization [ %s ] canceled applying default info") % org_name,
                ok       = _("Organization [ %s ] completed applying default info") % org_name
            )
        else:
            self.default_info_api.apply(org_name, informable_type, async)

            print _("Organization [ %s ] completed applying default info") % org_name
            return os.EX_OK
Exemple #29
0
    def run(self):
        org_name = self.get_option('org')
        group_name = self.get_option('name')

        install = self.get_option('install')
        remove = self.get_option('remove')
        update = self.get_option('update')
        install_groups = self.get_option('install_groups')
        remove_groups = self.get_option('remove_groups')
        update_groups = self.get_option('update_groups')

        job = None

        system_group = get_system_group(org_name, group_name)
        system_group_id = system_group['id']

        if install:
            job = self.api.install_packages(org_name, system_group_id, install)
        if remove:
            job = self.api.remove_packages(org_name, system_group_id, remove)
        if update:
            if update == '--all':
                update_packages = []
            else:
                update_packages = update
            job = self.api.update_packages(org_name, system_group_id, update_packages)
        if install_groups:
            job = self.api.install_package_groups(org_name, system_group_id, install_groups)
        if remove_groups:
            job = self.api.remove_package_groups(org_name, system_group_id, remove_groups)
        if update_groups:
            job = self.api.update_package_groups(org_name, system_group_id, update_groups)

        if job:
            job_id = job["id"]
            print (_("Performing remote action [ %s ]... ") % job_id)
            job = SystemGroupAsyncJob(org_name, system_group_id, job)
            run_spinner_in_bg(wait_for_async_task, [job])

            return evaluate_remote_action(job)

        return os.EX_OK
Exemple #30
0
    def run(self):
        provName = self.get_option('name')
        orgName  = self.get_option('org')

        prov = get_provider(orgName, provName)

        try:
            response = run_spinner_in_bg(self.api.delete_manifest, [prov["id"]],
                message=_("Deleting manifest, please wait... "))
        except ServerRequestError, re:
            raise re, None, sys.exc_info()[2]
Exemple #31
0
    def discover_repositories(self, orgName, url):
        print (_("Discovering repository urls, this could take some time..."))
        task = self.org_api.repo_discovery(orgName, url)

        tasks = run_spinner_in_bg(wait_for_async_task, [task])
        repourls = tasks[0]["result"]

        if not len(repourls):
            system_exit(os.EX_OK, "No repositories discovered @ url location [%s]" % url)

        return repourls
Exemple #32
0
    def run(self):
        provName = self.get_option('name')
        orgName = self.get_option('org')

        prov = get_provider(orgName, provName)

        try:
            response = run_spinner_in_bg(
                self.api.delete_manifest, [prov["id"]],
                message=_("Deleting manifest, please wait... "))
        except ServerRequestError, re:
            raise re, None, sys.exc_info()[2]
Exemple #33
0
    def run(self):
        tplName = self.get_option('name')
        orgName = self.get_option('org')
        newName = self.get_option('new_name')
        desc    = self.get_option('description')
        parentName = self.get_option('parent')
        content = self.getContent()

        env = get_library(orgName)
        template = get_template(orgName, env["name"], tplName)

        if parentName != None:
            parentId = self.get_parent_id(orgName, env["name"], parentName)
        else:
            parentId = None

        run_spinner_in_bg(self.updateTemplate, [template["id"], newName, desc, parentId],
            _("Updating the template, please wait... "))
        run_spinner_in_bg(self.updateContent,  [template["id"], content], _("Updating the template, please wait... "))
        print _("Successfully updated template [ %s ]") % template['name']
        return os.EX_OK
Exemple #34
0
    def run(self):
        provName = self.get_option('name')
        orgName  = self.get_option('org')
        manifestPath = self.get_option('file')
        force = self.get_option('force')

        try:
            f = open(get_abs_path(manifestPath))
        except IOError:
            system_exit(os.EX_IOERR, _("File %s does not exist") % manifestPath)

        prov = get_provider(orgName, provName)

        task = ManifestAsyncTask(self.api.import_manifest(prov["id"], f, force))
        run_spinner_in_bg(wait_for_async_task, [task], message=_("Importing manifest, please wait... "))

        return ManifestAsyncTask.evaluate_task_status(task,
            failed =   _("Provider [ %s ] failed to import manifest") % provName,
            canceled = _("Provider [ %s ] canceled manifest import") % provName,
            ok =       _("Provider [ %s ] manifest import complete") % provName
        )
Exemple #35
0
    def run(self):
        org_name = self.get_option('org')
        group_name = self.get_option('name')
        install = self.get_option('install')

        job = None

        system_group = get_system_group(org_name, group_name)
        system_group_id = system_group['id']

        if install:
            job = self.api.install_errata(org_name, system_group_id, install)

        if job:
            job_id = job["id"]
            print(_("Performing remote action [ %s ]... ") % job_id)
            job = SystemGroupAsyncJob(org_name, system_group_id, job)
            run_spinner_in_bg(wait_for_async_task, [job])

            return evaluate_remote_action(job)

        return os.EX_OK
Exemple #36
0
    def run(self):
        org_name = self.get_option('org')
        group_name = self.get_option('name')
        install = self.get_option('install')

        job = None

        system_group = get_system_group(org_name, group_name)
        system_group_id = system_group['id']

        if install:
            job = self.api.install_errata(org_name, system_group_id, install)

        if job:
            job_id = job["id"]
            print (_("Performing remote action [ %s ]... ") % job_id)
            job = SystemGroupAsyncJob(org_name, system_group_id, job)
            run_spinner_in_bg(wait_for_async_task, [job])

            return evaluate_remote_action(job)

        return os.EX_OK
Exemple #37
0
    def run(self):
        node_id = self.get_option("id")
        node_name = self.get_option("name")

        org_name = self.get_option('org')
        env_name = self.get_option('env_name')
        env_id = None
        message = _("Syncing node, please wait... ")
        if env_name is not None:
            env = get_environment(org_name, env_name)
            env_id = env['id']
            message = _("Syncing environment %s to node, please wait...") % env['name']

        node_id = get_node(node_name, node_id)['id']
        sync_tasks = self.api.sync(node_id, env_id)
        task = AsyncTask(sync_tasks)
        run_spinner_in_bg(wait_for_async_task, [task], message=message)

        return evaluate_task_status(task,
            ok =     _("Sync of environment [ %s ] completed successfully.") % env_name,
            failed = _("Sync of environment [ %s ] failed") % env_name,
            error_formatter = format_node_sync_errors
        )
Exemple #38
0
    def run(self):
        provName = self.get_option('name')
        orgName = self.get_option('org')
        manifestPath = self.get_option('file')
        force = self.get_option('force')

        try:
            f = open(get_abs_path(manifestPath))
        except IOError:
            system_exit(os.EX_IOERR,
                        _("File %s does not exist") % manifestPath)

        prov = get_provider(orgName, provName)

        task = ManifestAsyncTask(self.api.import_manifest(
            prov["id"], f, force))
        run_spinner_in_bg(wait_for_async_task, [task],
                          message=_("Importing manifest, please wait... "))

        return ManifestAsyncTask.evaluate_task_status(
            task,
            failed=_("Provider [ %s ] failed to import manifest") % provName,
            canceled=_("Provider [ %s ] canceled manifest import") % provName,
            ok=_("Provider [ %s ] manifest import complete") % provName)
Exemple #39
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
Exemple #40
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
Exemple #41
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}
        )
Exemple #42
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}
        )
Exemple #43
0
    def run(self):
        desc    = self.get_option('description')
        orgName = self.get_option('org')
        tplPath = self.get_option('file')

        env = get_library(orgName)

        try:
            f = self.open_file(tplPath)
        except IOError:
            print _("File [ %s ] does not exist" % tplPath)
            return os.EX_IOERR

        response = run_spinner_in_bg(self.api.import_tpl, (env["id"], desc, f),
            message=_("Importing template, please wait... "))
        print response
        f.close()
        return os.EX_OK
Exemple #44
0
    def run(self):
        tplName = self.get_option('name')
        orgName = self.get_option('org')
        envName = self.get_option('environment')
        format_in  = self.get_option('format') or "json"
        tplPath = self.get_option('file')

        template = get_template(orgName, envName, tplName)

        try:
            f = self.open_file(tplPath)
        except IOError:
            print >> sys.stderr, _("Could not create file [ %s ]") % tplPath
            return os.EX_IOERR

        self.api.validate_tpl(template["id"], format_in)
        response = run_spinner_in_bg(self.api.export_tpl, (template["id"], format_in),
            message=_("Exporting template, please wait... "))
        f.write(response)
        f.close()
        print _("Template was exported successfully to file [ %s ]") % tplPath
        return os.EX_OK
Exemple #45
0
    def run(self):
        org_name = self.get_option("org")
        env_name = self.get_option("environment")
        sys_name = self.get_option("name")
        sys_uuid = self.get_option("uuid")

        install = self.get_option("install")
        remove = self.get_option("remove")
        update = self.get_option("update")
        install_groups = self.get_option("install_groups")
        remove_groups = self.get_option("remove_groups")

        task = None

        if env_name is None:
            self.printer.set_header(
                _("Package Information for System [ %(sys_name)s ] in Org [ %(org_name)s ]")
                % {"sys_name": sys_name, "org_name": org_name}
            )
        else:
            self.printer.set_header(
                _(
                    "Package Information for System [ %(sys_name)s ] "
                    "in Environment [ %(env_name)s ] in Org [ %(org_name)s ]"
                )
                % {"sys_name": sys_name, "env_name": env_name, "org_name": org_name}
            )

        system = get_system(org_name, sys_name, env_name, sys_uuid)
        system_id = system["uuid"]

        if install:
            task = self.api.install_packages(system_id, install)
        if remove:
            task = self.api.remove_packages(system_id, remove)
        if update:
            if update == "--all":
                update_packages = []
            else:
                update_packages = update
            task = self.api.update_packages(system_id, update_packages)
        if install_groups:
            task = self.api.install_package_groups(system_id, install_groups)
        if remove_groups:
            task = self.api.remove_package_groups(system_id, remove_groups)

        if task:
            uuid = task["uuid"]
            print (_("Performing remote action [ %s ]... ") % uuid)
            task = SystemAsyncTask(task)
            run_spinner_in_bg(wait_for_async_task, [task])

            return evaluate_remote_action(task)

        packages = self.api.packages(system_id)

        batch_add_columns(
            self.printer,
            {"name": _("Name")},
            {"vendor": _("Vendor")},
            {"version": _("Version")},
            {"release": _("Release")},
            {"arch": _("Arch")},
            show_with=printer.VerboseStrategy,
        )
        self.printer.add_column(
            "name_version_release_arch",
            _("Name_Version_Release_Arch"),
            show_with=printer.GrepStrategy,
            item_formatter=lambda p: "%s-%s-%s.%s" % (p["name"], p["version"], p["release"], p["arch"]),
        )

        self.printer.print_items(packages)

        return os.EX_OK