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
def run(self): tplName = self.get_option('name') orgName = self.get_option('org') envName = self.get_option('environment') template = get_template(orgName, envName, tplName) template["products"] = [p["name"] for p in template["products"]] template["repositories"] = [r["name"] for r in template["repositories"]] template["packages"] = [self._build_nvrea(p) for p in template["packages"]] template["parameters"] = [key+":\t"+value for key, value in template["parameters"].iteritems()] template["package_groups"] = [p["name"] for p in template["package_groups"]] template["package_group_categories"] = [p["name"] for p in template["pg_categories"]] batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}) self.printer.add_column('revision', _("Revision"), show_with=printer.VerboseStrategy) self.printer.add_column('description', _("Description"), multiline=True) self.printer.add_column('environment_id', _("Environment ID")) self.printer.add_column('parent_id', _("Parent ID")) batch_add_columns(self.printer, {'errata': _("Errata")}, {'products': _("Products")}, \ {'repositories': _("Repositories")}, {'packages': _("Packages")}, \ {'parameters': _("Parameters")}, {'package_groups': _("Package Groups")}, \ {'package_group_categories': _("Package Group Categories")}, multiline=True, \ show_with=printer.VerboseStrategy) self.printer.set_header(_("Template Info")) self.printer.print_item(template) return os.EX_OK
def run(self): packId = self.get_option('id') repoId = self.get_option('repo_id') repoName = self.get_option('repo') orgName = self.get_option('org') envName = self.get_option('environment') prodName = self.get_option('product') prodLabel = self.get_option('product_label') prodId = self.get_option('product_id') viewName = self.get_option('view_name') viewLabel = self.get_option('view_label') viewId = self.get_option('view_id') if not repoId: repo = get_repo(orgName, repoName, prodName, prodLabel, prodId, envName, False, viewName, viewLabel, viewId) repoId = repo["id"] pack = self.api.package(packId, repoId) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'filename': _("Filename")}, {'arch': _("Arch")}, {'release': _("Release")}, \ {'version': _("Version")}, {'vendor': _("Vendor")}) self.printer.add_column('download_url', _("Download URL"), show_with=printer.VerboseStrategy) batch_add_columns(self.printer, {'description': _("Description")}, \ {'provides': _("Provides")}, {'requires': _("Requires")}, multiline=True, \ show_with=printer.VerboseStrategy) self.printer.set_header(_("Package Information")) self.printer.print_item(pack) return os.EX_OK
def run(self): org_name = self.get_option('org') env_name = self.get_option('environment') pool_id = self.get_option('pool_id') systems = self.get_systems(org_name, env_name, pool_id) if env_name is None: self.printer.set_header(_("Systems List For Org [ %s ]") % org_name) else: self.printer.set_header(_("Systems List For Environment [ %(env_name)s ] in Org [ %(org_name)s ]") \ % {'env_name':env_name, 'org_name':org_name}) batch_add_columns(self.printer, {'name': _("Name")}, {'uuid': _("UUID")}) self.printer.add_column('environment', _("Environment"), \ item_formatter=lambda p: "%s" % (p['environment']['name'])) self.printer.add_column('serviceLevel', _("Service Level")) cv_format = lambda p: "%s" % (p['content_view']['name'] if 'content_view' in p else "") self.printer.add_column('content_view', _("Content View"), item_formatter=cv_format) self.printer.print_items(systems) return os.EX_OK
def run(self): org_name = self.get_option("org") env_name = self.get_option("environment") pool_id = self.get_option("pool_id") systems = self.get_systems(org_name, env_name, pool_id) if env_name is None: self.printer.set_header(_("Systems List For Org [ %s ]") % org_name) else: self.printer.set_header( _("Systems List For Environment [ %(env_name)s ] in Org [ %(org_name)s ]") % {"env_name": env_name, "org_name": org_name} ) batch_add_columns(self.printer, {"name": _("Name")}, {"uuid": _("UUID")}) self.printer.add_column( "environment", _("Environment"), item_formatter=lambda p: "%s" % (p["environment"]["name"]) ) self.printer.add_column("serviceLevel", _("Service Level")) cv_format = lambda p: "%s" % (p["content_view"]["name"] if "content_view" in p else "") self.printer.add_column("content_view", _("Content View"), item_formatter=cv_format) self.printer.print_items(systems) return os.EX_OK
def run(self): org_name = self.get_option('org') env_name = self.get_option('environment') prov_name = self.get_option('prov') all_opt = self.get_option('all') batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'label': _("Label")}, {'provider_id': _("Provider ID")}, \ {'provider_name': _("Provider Name")}, {'sync_plan_name': _("Sync Plan Name")}) self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time) self.printer.add_column('gpg_key_name', _("GPG key")) if prov_name: prov = get_provider(org_name, prov_name) self.printer.set_header(_("Product List For Provider [ %s ]") % (prov_name)) prods = self.api.products_by_provider(prov["id"]) else: env = get_environment(org_name, env_name) self.printer.set_header(_("Product List For Organization %(org_name)s, Environment '%(env_name)s'") \ % {'org_name':org_name, 'env_name':env["name"]}) prods = self.api.products_by_env(env['id']) # hide marketing products by default if not all_opt: def isNotMarketingProduct(p): return not (("marketing_product" in p) and (p["marketing_product"])) prods = filter(isNotMarketingProduct, prods) self.printer.print_items(prods) return os.EX_OK
def run(self): org_name = self.get_option('org') env_name = self.get_option('environment') prov_name = self.get_option('prov') all_opt = self.get_option('all') batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'label': _("Label")}, {'provider_id': _("Provider ID")}, \ {'provider_name': _("Provider Name")}, {'sync_plan_name': _("Sync Plan Name")}) self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time) self.printer.add_column('gpg_key_name', _("GPG key")) if prov_name: prov = get_provider(org_name, prov_name) self.printer.set_header(_("Product List For Provider [ %s ]") % (prov_name)) prods = self.api.products_by_provider(prov["id"]) else: env = get_environment(org_name, env_name) self.printer.set_header(_("Product List For Organization %(org_name)s, Environment '%(env_name)s'") \ % {'org_name':org_name, 'env_name':env["name"]}) prods = self.api.products_by_env(env['id']) # hide marketing products by default if not all_opt: def isNotMarketingProduct(p): return not (("marketing_product" in p) and (p["marketing_product"])) prods = filter(isNotMarketingProduct, prods) self.printer.print_items(prods) return os.EX_OK
def run(self): errId = self.get_option("id") repoId = self.get_option("repo_id") repoName = self.get_option("repo") orgName = self.get_option("org") envName = self.get_option("environment") prodName = self.get_option("product") prodLabel = self.get_option("product_label") prodId = self.get_option("product_id") if not repoId: repo = get_repo(orgName, prodName, prodLabel, prodId, repoName, envName) repoId = repo["id"] pack = self.api.errata(errId, repoId) pack["affected_packages"] = [u_str(pinfo["filename"]) for pkg in pack["pkglist"] for pinfo in pkg["packages"]] batch_add_columns(self.printer, {"id": _("ID")}, {"title": _("Title")}) self.printer.add_column("description", _("Description"), multiline=True) batch_add_columns( self.printer, {"type": _("Type")}, {"issued": _("Issued")}, {"updated": _("Updated")}, {"version": _("Version")}, {"release": _("Release")}, {"status": _("Status")}, {"reboot_suggested": _("Reboot Suggested")}, ) self.printer.add_column("affected_packages", _("Affected Packages"), multiline=True) self.printer.set_header(_("Errata Information")) self.printer.print_item(pack) return os.EX_OK
def run(self): org_name = self.get_option('org') env_name = self.get_option('environment') dist_name = self.get_option('name') dist_uuid = self.get_option('uuid') if dist_uuid: self.printer.set_header(_("Distributor Information [ %s ]") % dist_uuid) elif env_name is None: self.printer.set_header(_("Distributor Information For Org [ %s ]") % org_name) else: self.printer.set_header(_("Distributor Information For Environment [ %(env)s ] in Org [ %(org)s ]") \ % {'env':env_name, 'org':org_name}) # get distributor details distributor = get_distributor(org_name, dist_name, env_name, dist_uuid) custom_info_api = CustomInfoAPI() custom_info = custom_info_api.get_custom_info("distributor", distributor['id']) distributor['custom_info'] = stringify_custom_info(custom_info) if 'environment' in distributor: distributor['environment'] = distributor['environment']['name'] batch_add_columns(self.printer, {'name': _("Name")}, {'version': _("Version")}, {'uuid': _("UUID")}, {'environment': _("Environment")}) self.printer.add_column('created_at', _("Created"), formatter=format_date) self.printer.add_column('updated_at', _("Last Updated"), formatter=format_date) self.printer.add_column('description', _("Description"), multiline=True) self.printer.add_column('custom_info', _("Custom Info"), multiline=True, show_with=printer.VerboseStrategy) self.printer.print_item(distributor) return os.EX_OK
def run(self): packId = self.get_option('id') repoId = self.get_option('repo_id') repoName = self.get_option('repo') orgName = self.get_option('org') envName = self.get_option('environment') prodName = self.get_option('product') prodLabel = self.get_option('product_label') prodId = self.get_option('product_id') viewName = self.get_option('view_name') viewLabel = self.get_option('view_label') viewId = self.get_option('view_id') if not repoId: repo = get_repo(orgName, repoName, prodName, prodLabel, prodId, envName, False, viewName, viewLabel, viewId) repoId = repo["id"] pack = self.api.package(packId, repoId) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'filename': _("Filename")}, {'arch': _("Arch")}, {'release': _("Release")}, \ {'version': _("Version")}, {'vendor': _("Vendor")}) self.printer.add_column('download_url', _("Download URL"), show_with=printer.VerboseStrategy) batch_add_columns(self.printer, {'description': _("Description")}, \ {'provides': _("Provides")}, {'requires': _("Requires")}, multiline=True, \ show_with=printer.VerboseStrategy) self.printer.set_header(_("Package Information")) self.printer.print_item(pack) return os.EX_OK
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
def run(self): systemGroupApi = SystemGroupAPI() org_name = self.get_option('org') group_name = self.get_option('name') type_in = self.get_option('type') system_group = get_system_group(org_name, group_name) system_group_id = system_group['id'] errata = systemGroupApi.errata(org_name, system_group_id, type_in=type_in) batch_add_columns(self.printer, {'errata_id': _("ID")}, {'title': _("Title")}, {'type': _("Type")}) self.printer.add_column('systems', _('# Systems'), formatter=len) self.printer.add_column('systems', _("Systems"), multiline=True, show_with=printer.VerboseStrategy) self.printer.set_header( _("Errata for system group %(org_name)s in organization %(org_name)s" ) % { 'group_name': group_name, 'org_name': org_name }) self.printer.print_items(errata) return os.EX_OK
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
def run(self): org_name = self.get_option('org') env_name = self.get_option('environment') pool_id = self.get_option('pool_id') systems = self.get_systems(org_name, env_name, pool_id) if env_name is None: self.printer.set_header( _("Systems List For Org [ %s ]") % org_name) else: self.printer.set_header(_("Systems List For Environment [ %(env_name)s ] in Org [ %(org_name)s ]") \ % {'env_name':env_name, 'org_name':org_name}) batch_add_columns(self.printer, {'name': _("Name")}, {'uuid': _("UUID")}) self.printer.add_column('environment', _("Environment"), \ item_formatter=lambda p: "%s" % (p['environment']['name'])) self.printer.add_column('serviceLevel', _("Service Level")) cv_format = lambda p: "%s" % (p['content_view']['name'] if 'content_view' in p else "") self.printer.add_column('content_view', _("Content View"), item_formatter=cv_format) self.printer.print_items(systems) return os.EX_OK
def run(self): module_id = self.get_option('id') 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') view_name = self.get_option('view_name') view_label = self.get_option('view_label') view_id = self.get_option('view_id') if not repo_id: repo = get_repo(org_name, repo_name, prod_name, prod_label, prod_id, env_name, False, view_name, view_label, view_id) repo_id = repo["id"] module = self.api.puppet_module(module_id, repo_id) batch_add_columns(self.printer, {'_id': _("ID")}, {'name': _("Name")}, {'_storage_path': _("Path")}, {'license': _("License")}, {'project_page': _("Project page")}, {'version': _("Version")}, {'author': _("Author")}) batch_add_columns(self.printer, {'description': _("Description")}, {'summary': _("Summary")}, multiline=True, show_with=printer.VerboseStrategy) self.printer.set_header(_("Puppet Module Information")) self.printer.print_item(module) return os.EX_OK
def run(self): configtemplate = self.api.show(self.get_option('id')) configtemplate = unnest_one(configtemplate) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'snippet': _("Snippet")}) if not configtemplate.get('snippet'): self.printer.add_column('kind', _("Template Kind"), item_formatter=lambda item: format_sub_resource(item, 'kind', 'kind_id')) if configtemplate.get('template_combinations'): content = [] for combo in configtemplate.get('template_combinations'): combo = unnest_one(combo) content.append("%s / %s (Id: %d)" % (combo['hostgroup_id'], combo['environment_id'], combo['id'])) # key = "Hostgroup / Environment id %d" % combo['id'] configtemplate['Hostgroup/Environment combinations'] = ', '.join(content) self.printer.add_column('Hostgroup/Environment combinations', _("Hostgroup/Environment Combinations")) if configtemplate.get('operatingsystems'): content = [] for system in configtemplate.get('operatingsystems'): system = unnest_one(system) content.append("%s (Id: %d)" % (system['name'], system['id'])) configtemplate['Operating Systems'] = ', '.join(content) self.printer.add_column('Operating Systems', _("Operating Systems")) self.printer.add_column('template', _("Template")) self.printer.set_header(_("Config Template")) self.printer.print_item(configtemplate)
def run(self): errId = self.get_option('id') repoId = self.get_option('repo_id') repoName = self.get_option('repo') orgName = self.get_option('org') envName = self.get_option('environment') prodName = self.get_option('product') prodLabel = self.get_option('product_label') prodId = self.get_option('product_id') viewName = self.get_option('view_name') viewLabel = self.get_option('view_label') viewId = self.get_option('view_id') if not repoId: repo = get_repo(orgName, repoName, prodName, prodLabel, prodId, envName, viewName, viewLabel, viewId) repoId = repo["id"] pack = self.api.errata(errId, repoId) pack['affected_packages'] = [u_str(pinfo['filename']) for pkg in pack['pkglist'] for pinfo in pkg['packages']] batch_add_columns(self.printer, {'errata_id': _("ID")}, {'title': _("Title")}) self.printer.add_column('description', _("Description"), multiline=True) batch_add_columns(self.printer, {'type': _("Type")}, {'issued': _("Issued")}, \ {'updated': _("Updated")}, {'version': _("Version")}, {'release': _("Release")}, \ {'status': _("Status")}, {'reboot_suggested': _("Reboot Suggested")}) self.printer.add_column('affected_packages', _("Affected Packages"), multiline=True) self.printer.set_header(_("Errata Information")) self.printer.print_item(pack) return os.EX_OK
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
def run(self): org_name = self.get_option('org') prov_name = self.get_option('prov') all_opt = self.get_option('all') batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'label': _("Label")}, {'provider_id': _("Provider ID")}, \ {'provider_name': _("Provider Name")}, {'sync_plan_name': _("Sync Plan Name")}) self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time) self.printer.add_column('gpg_key_name', _("GPG key")) if prov_name: prov = get_provider(org_name, prov_name) self.printer.set_header(_("Product List For Provider [ %s ]") % (prov_name)) prods = self.api.products_by_provider(prov["id"], marketing=all_opt) else: self.printer.set_header(_("Product List For Organization %(org_name)s") \ % {'org_name':org_name}) prods = self.api.products_by_org(org_name, None, all_opt) self.printer.print_items(prods) return os.EX_OK
def run(self): proxy = self.api.show(self.get_option('name')) proxy = unnest_one(proxy) batch_add_columns(self.printer, {'name': _("Name")}, {'url': _("URL")}) self.printer.add_column('features', _("Features"), multiline=True) self.printer.set_header(_("Smart Proxy")) self.printer.print_item(proxy)
def run(self): orgName = self.get_option("org") envName = self.get_option("environment") prodName = self.get_option("product") prodLabel = self.get_option("product_label") prodId = self.get_option("product_id") listDisabled = self.has_option("disabled") content_view_name = self.get_option("view_name") content_view_label = self.get_option("view_label") content_view_id = self.get_option("view_id") batch_add_columns( self.printer, {"id": _("ID")}, {"name": _("Name")}, {"label": _("Label")}, {"content_type": _("Type")}, {"package_count": _("Package Count")}, {"puppet_module_count": _("Puppet Module Count")}, ) self.printer.add_column("last_sync", _("Last Sync"), formatter=format_sync_time) if content_view_name or content_view_label or content_view_id: content_view = get_content_view(orgName, content_view_label, content_view_name, content_view_id) content_view_id = content_view["id"] prodIncluded = prodName or prodLabel or prodId if prodIncluded and envName: env = get_environment(orgName, envName) prod = get_product(orgName, prodName, prodLabel, prodId) self.printer.set_header( _("Repo List For Org %(org_name)s Environment %(env_name)s Product %(prodName)s") % {"org_name": orgName, "env_name": env["name"], "prodName": prodName} ) repos = self.api.repos_by_env_product(env["id"], prod["id"], None, listDisabled, content_view_id) self.printer.print_items(repos) elif prodIncluded: prod = get_product(orgName, prodName, prodLabel, prodId) self.printer.set_header( _("Repo List for Product %(prodName)s in Org %(orgName)s ") % {"prodName": prodName, "orgName": orgName} ) repos = self.api.repos_by_product(orgName, prod["id"], listDisabled) self.printer.print_items(repos) else: env = get_environment(orgName, envName) self.printer.set_header( _("Repo List For Org %(orgName)s Environment %(env_name)s") % {"orgName": orgName, "env_name": env["name"]} ) repos = self.api.repos_by_org_env(orgName, env["id"], listDisabled, content_view_id) self.printer.print_items(repos) return os.EX_OK
def run(self): domain_id = self.get_option('id') domain = unnest_one(self.api.show(domain_id)) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'fullname': _("Full Name")}, {'dns_id': _("DNS ID")}) self.printer.set_header(_("Domain")) self.printer.print_item(domain)
def run(self): orgs = self.api.organizations() batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'label': _("Label")}) self.printer.add_column('description', _("Description"), multiline=True) self.printer.set_header(_("Organization List")) self.printer.print_items(orgs) return os.EX_OK
def run(self): archs = self.api.index() if archs: archs = unnest_one(archs) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}) self.printer.set_header(_("Architectures List")) self.printer.print_items(archs) return os.EX_OK
def run(self): arch = self.api.show(self.get_option('name')) arch = unnest_one(arch) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}) self.printer.set_header(_("Architecture")) self.printer.print_item(arch) return os.EX_OK
def run(self): orgs = self.api.organizations() batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'label': _("Label")}) self.printer.add_column('description', _("Description"), multiline=True) self.printer.set_header(_("Organization List")) self.printer.print_items(orgs) return os.EX_OK
def run(self): data = self.get_option_dict('order', 'search') configtemplates = self.api.list(data) if configtemplates: configtemplates = unnest_one(configtemplates) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'snippet': _("Snippet")}) self.printer.set_header(_("Config Template")) self.printer.print_items(configtemplates)
def run(self): subnets = unnest_one(self.api.list()) batch_add_columns(self.printer, {'name': _("Name")}, {'network': _("Network")}, \ {'mask': _("Mask")}) batch_add_columns(self.printer, {'dhcp': _("DHCP")}, {'tftp': _("TFTP")}, \ {'dns': _("DNS")}, formatter=self.format_smart_proxy) self.printer.set_header(_("Subnets")) self.printer.print_items(subnets)
def run(self): users = self.api.users() batch_add_columns(self.printer, {'id': _("ID")}, {'username': _("Username")}, \ {'email': _("Email")}, {'disabled': _("Disabled")}, \ {'default_organization': _("Default Organization")}, \ {'default_environment': _("Default Environment")}) self.printer.set_header(_("User List")) self.printer.print_items(users) return os.EX_OK
def run(self): users = self.api.users() batch_add_columns(self.printer, {'id': _("ID")}, {'username': _("Username")}, \ {'email': _("Email")}, {'disabled': _("Disabled")}, \ {'default_organization': _("Default Organization")}, \ {'default_environment': _("Default Environment")}) self.printer.set_header(_("User List")) self.printer.print_items(users) return os.EX_OK
def run(self): data = self.get_option_dict('search', 'order') domains = self.api.list(data) if domains: domains = unnest_one(domains) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'fullname': _("Full Name")}, {'dns_id': _("DNS ID")}) self.printer.set_header(_("Domains")) self.printer.print_items(domains)
def run(self): status = self.api.ping() batch_add_columns(self.printer, {'status': _("Status")}, {'service': _("Service")}, \ {'result': _("Result")}, {'duration': _("Duration")}, {'message': _("Message")}) self.printer.set_header(_("Katello Status")) statusList = self.__statusToList(status) self.printer.print_items(statusList) return self.__returnCode(status)
def run(self): status = self.api.ping() batch_add_columns(self.printer, {'status': _("Status")}, {'service': _("Service")}, \ {'result': _("Result")}, {'duration': _("Duration")}, {'message': _("Message")}) self.printer.set_header(_("Katello Status")) statusList = self.__statusToList(status) self.printer.print_items(statusList) return self.__returnCode(status)
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') if sys_uuid: self.printer.set_header(_("System Information [ %s ]") % sys_uuid) elif env_name is None: self.printer.set_header(_("System Information For Org [ %s ]") % org_name) else: self.printer.set_header(_("System Information For Environment [ %(env_name)s ] in Org [ %(org_name)s ]") \ % {'env_name':env_name, 'org_name':org_name}) # get system details system = get_system(org_name, sys_name, env_name, sys_uuid) custom_info_api = CustomInfoAPI() custom_info = custom_info_api.get_custom_info("system", system['id']) system['custom_info'] = stringify_custom_info(custom_info) system["activation_keys"] = "[ "+ ", ".join([ak["name"] for ak in system["activation_key"]]) +" ]" if 'host' in system: system['host'] = system['host']['name'] if 'guests' in system: system["guests"] = "[ "+ ", ".join([guest["name"] for guest in system["guests"]]) +" ]" if 'environment' in system: system['environment'] = system['environment']['name'] if 'content_view' in system: system['content_view'] = "[ %s ]" % system['content_view']['name'] batch_add_columns(self.printer, {'name': _("Name")}, {'ipv4_address': _("IPv4 Address")}, \ {'uuid': _("UUID")}, {'environment': _("Environment")}, {'location': _("Location")}) self.printer.add_column('created_at', _("Registered"), formatter=format_date) self.printer.add_column('updated_at', _("Last Updated"), formatter=format_date) self.printer.add_column('description', _("Description"), multiline=True) if 'release' in system and system['release']: self.printer.add_column('release', _("OS Release")) self.printer.add_column('activation_keys', _("Activation Keys"), multiline=True, \ show_with=printer.VerboseStrategy) self.printer.add_column('host', _("Host"), show_with=printer.VerboseStrategy) self.printer.add_column('sockets', _("Sockets")) self.printer.add_column('ram', _("RAM (MB)")) self.printer.add_column('serviceLevel', _("Service Level")) self.printer.add_column('guests', _("Guests"), show_with=printer.VerboseStrategy) self.printer.add_column('custom_info', _("Custom Info"), multiline=True, show_with=printer.VerboseStrategy) self.printer.add_column('content_view', _("Content View")) self.printer.print_item(system) return os.EX_OK
def run(self): subnet = unnest_one(self.api.get(self.get_option("name"))) batch_add_columns(self.printer, {'name': _("Name")}, {'network': _("Network")}, \ {'mask': _("Mask")}, {'gateway': _("Gateway")}, {'dns_primary': _("Primary DNS")}, \ {'dns_secondary': _("Secondary DNS")}, {'from': _("From")}, {'to': _("To")}, \ {'vlanid': _("VLAN ID")}) self.printer.add_column('domain_ids', _("Domain IDs"), multiline=True) batch_add_columns(self.printer, {'dhcp': _("DHCP")}, {'tftp': _("TFTP")}, \ {'dns': _("DNS")}, formatter=self.format_smart_proxy) self.printer.set_header(_("Subnet")) self.printer.print_item(subnet)
def run(self): repoid = self.get_option('repo_id') groups = self.api.packagegroups(repoid) if not groups: system_exit(os.EX_DATAERR, _("No package groups found in repo [%s]") % (repoid)) self.printer.set_header(_("Package Group Information")) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'description': _("Description")}) self.printer.print_items(groups) return os.EX_OK
def run(self): orgName = self.get_option('org') envs = self.api.environments_by_org(orgName) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'label': _("Label")}) self.printer.add_column('description', _("Description"), multiline=True) self.printer.add_column('organization', _('Org')) self.printer.add_column('prior', _("Prior Environment")) self.printer.set_header(_("Environment List")) self.printer.print_items(envs) return os.EX_OK
def run(self): resources = self.api.index() resources = unnest_one(resources) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'url': _("Url")}, {'provider': _("Provider")} ) self.printer.set_header(_("Compute Resources List")) self.printer.print_items(resources) return os.EX_OK
def run(self): repoid = self.get_option('repo_id') groups = self.api.packagegroups(repoid) if not groups: system_exit(os.EX_DATAERR, _("No package groups found in repo [%s]") % (repoid)) self.printer.set_header(_("Package Group Information")) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'description': _("Description")}) self.printer.print_items(groups) return os.EX_OK
def run(self): categoryId = self.get_option('id') repoid = self.get_option('repo_id') category = self.api.packagegroupcategory_by_id(repoid, categoryId) if category == None: system_exit(os.EX_DATAERR, _("Package group category [%(categoryId)s] not found in repo [%(repoid)s]") \ % {'categoryId':categoryId, 'repoid':repoid}) self.printer.set_header(_("Package Group Category Information")) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'packagegroupids': _("Package Group IDs")}) self.printer.print_item(category)
def run(self): categoryId = self.get_option('id') repoid = self.get_option('repo_id') category = self.api.packagegroupcategory_by_id(repoid, categoryId) if category == None: system_exit(os.EX_DATAERR, _("Package group category [%(categoryId)s] not found in repo [%(repoid)s]") \ % {'categoryId':categoryId, 'repoid':repoid}) self.printer.set_header(_("Package Group Category Information")) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'packagegroupids': _("Package Group IDs")}) self.printer.print_item(category)
def run(self): repoId = self.get_option('repo_id') dist_id = self.get_option('id') data = self.api.distribution(repoId, dist_id) batch_add_columns(self.printer, {'id': _("ID")}, {'description': _("Description")}, \ {'family': _("Family")}, {'variant': _("Variant")}, {'version': _("Version")}) self.printer.add_column('files', _("Files"), multiline=True, \ show_with=printer.VerboseStrategy) self.printer.set_header(_("Distribution Information")) self.printer.print_item(data) return os.EX_OK
def run(self): orgName = self.get_option('org') envs = self.api.environments_by_org(orgName) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'label': _("Label")}) self.printer.add_column('description', _("Description"), multiline=True) self.printer.add_column('organization', _('Org')) self.printer.add_column('prior', _("Prior Environment")) self.printer.set_header(_("Environment List")) self.printer.print_items(envs) return os.EX_OK
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) sets = self.api.repository_sets(orgName, prod["id"]) sets = sorted(sets, key=lambda k: k['name']) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'katello_enabled': _("Enabled?")}) self.printer.set_header(_("Repository Sets For Product [ %s ]") % (prod['name'])) self.printer.print_items(sets) return os.EX_OK
def run(self): org_name = self.get_option('org') env_name = self.get_option('environment') dist_name = self.get_option('name') dist_uuid = self.get_option('uuid') if dist_uuid: self.printer.set_header( _("Distributor Information [ %s ]") % dist_uuid) elif env_name is None: self.printer.set_header( _("Distributor Information For Org [ %s ]") % org_name) else: self.printer.set_header(_("Distributor Information For Environment [ %(env)s ] in Org [ %(org)s ]") \ % {'env':env_name, 'org':org_name}) # get distributor details distributor = get_distributor(org_name, dist_name, env_name, dist_uuid) custom_info_api = CustomInfoAPI() custom_info = custom_info_api.get_custom_info("distributor", distributor['id']) distributor['custom_info'] = stringify_custom_info(custom_info) if 'environment' in distributor: distributor['environment'] = distributor['environment']['name'] batch_add_columns(self.printer, {'name': _("Name")}, \ {'uuid': _("UUID")}, {'environment': _("Environment")}) self.printer.add_column('created_at', _("Created"), formatter=format_date) self.printer.add_column('updated_at', _("Last Updated"), formatter=format_date) self.printer.add_column('description', _("Description"), multiline=True) self.printer.add_column('custom_info', _("Custom Info"), multiline=True, show_with=printer.VerboseStrategy) self.printer.print_item(distributor) return os.EX_OK
def run(self): repo = self.get_repo(True) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'package_count': _("Package Count")}) batch_add_columns(self.printer, {'arch': _("Arch")}, {'feed': _("URL")}, \ show_with=printer.VerboseStrategy) self.printer.add_column('last_sync', _("Last Sync"), \ show_with=printer.VerboseStrategy, formatter=format_sync_time) self.printer.add_column('sync_state', _("Progress"), \ show_with=printer.VerboseStrategy, formatter=format_sync_state) self.printer.add_column('gpg_key_name', _("GPG Key"), \ show_with=printer.VerboseStrategy) self.printer.set_header(_("Information About Repo %s") % repo['id']) self.printer.print_item(repo) return os.EX_OK
def run(self): groupid = self.get_option('id') repoid = self.get_option('repo_id') group = self.api.packagegroup_by_id(repoid, groupid) if group == None: system_exit(os.EX_DATAERR, _("Package group [%(groupid)s] not found in repo [%(repoid)s]") \ % {'groupid':groupid, 'repoid':repoid}) self.printer.set_header(_("Package Group Information")) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}) batch_add_columns(self.printer, {'description': _("Description")}, \ {'mandatory_package_names': _("Mandatory Package Names")}, \ {'default_package_names': _("Default Package Names")}, \ {'optional_package_names': _("Optional Package Names")}, \ {'conditional_package_names': _("Conditional Package Names")}, multiline=True) self.printer.print_item(group)
def run(self): username = self.get_option('username') user = get_user(username) batch_add_columns(self.printer, {'id': _("ID")}, {'username': _("Username")}, \ {'email': _("Email")}, {'disabled': _("Disabled")}, \ {'default_organization': _("Default Organization")}, \ {'default_environment': _("Default Environment")}, \ {'default_locale': _("Default Locale")}) self.printer.set_header(_("User Information")) # Add user locale to user dictionary try: user['default_locale'] = user['preferences']['user']['locale'] except KeyError: user['default_locale'] = None self.printer.print_item(user) return os.EX_OK
def run(self): systemApi = SystemAPI() org_name = self.get_option('org') sys_name = self.get_option('name') system = get_system(org_name, sys_name) errata = systemApi.errata(system["uuid"]) batch_add_columns(self.printer, {'errata_id': _("ID")}, {'title': _("Title")}, {'type': _("Type")}) self.printer.set_header( _("Errata for system %(sys_name)s in organization %(org_name)s") % { 'sys_name': sys_name, 'org_name': org_name }) self.printer.print_items(errata) return os.EX_OK
def run(self): errId = self.get_option('id') repoId = self.get_option('repo_id') repoName = self.get_option('repo') orgName = self.get_option('org') envName = self.get_option('environment') prodName = self.get_option('product') prodLabel = self.get_option('product_label') prodId = self.get_option('product_id') viewName = self.get_option('view_name') viewLabel = self.get_option('view_label') viewId = self.get_option('view_id') if not repoId: repo = get_repo(orgName, repoName, prodName, prodLabel, prodId, envName, viewName, viewLabel, viewId) repoId = repo["id"] pack = self.api.errata(errId, repoId) pack['affected_packages'] = [ u_str(pinfo['filename']) for pkg in pack['pkglist'] for pinfo in pkg['packages'] ] batch_add_columns(self.printer, {'errata_id': _("ID")}, {'title': _("Title")}) self.printer.add_column('description', _("Description"), multiline=True) batch_add_columns(self.printer, {'type': _("Type")}, {'issued': _("Issued")}, \ {'updated': _("Updated")}, {'version': _("Version")}, {'release': _("Release")}, \ {'status': _("Status")}, {'reboot_suggested': _("Reboot Suggested")}) self.printer.add_column('affected_packages', _("Affected Packages"), multiline=True) self.printer.set_header(_("Errata Information")) self.printer.print_item(pack) return os.EX_OK
def run(self): org_name = self.get_option('org') env_name = self.get_option('environment') pool_id = self.get_option('pool_id') distributors = self.get_distributors(org_name, env_name, pool_id) if env_name is None: self.printer.set_header( _("Distributors List For Org [ %s ]") % org_name) else: self.printer.set_header(_("Distributors List For Environment [ %(env_name)s ] in Org [ %(org_name)s ]") \ % {'env_name':env_name, 'org_name':org_name}) batch_add_columns(self.printer, {'name': _("Name")}, {'uuid': _("UUID")}) self.printer.add_column('environment', _("Environment"), \ item_formatter=lambda p: "%s" % (p['environment']['name'])) self.printer.add_column('serviceLevel', _("Service Level")) self.printer.print_items(distributors) return os.EX_OK
def run(self): orgName = self.get_option('org') envName = self.get_option('environment') verbose = self.get_option('verbose') env = get_environment(orgName, envName) changesets = self.api.changesets(orgName, env['id']) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'action_type': _("Action Type")}) self.printer.add_column('updated_at', _("Last Updated"), formatter=format_date) batch_add_columns(self.printer, {'state': _("State")}, \ {'environment_id': _("Environment ID")}, {'environment_name': _("Environment Name")}) if verbose: self.printer.add_column('description', _("Description"), multiline=True) self.printer.set_header(_("Changeset List")) self.printer.print_items(changesets) return os.EX_OK
def run(self): orgName = self.get_option('org') envName = self.get_option('environment') prodName = self.get_option('product') prodLabel = self.get_option('product_label') prodId = self.get_option('product_id') listDisabled = self.has_option('disabled') batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, \ {'label': _("Label")}, {'package_count': _("Package Count")}) self.printer.add_column('last_sync', _("Last Sync"), formatter=format_sync_time) prodIncluded = prodName or prodLabel or prodId if prodIncluded and envName: env = get_environment(orgName, envName) prod = get_product(orgName, prodName, prodLabel, prodId) self.printer.set_header(_("Repo List For Org %(org_name)s Environment %(env_name)s Product %(prodName)s") % {'org_name':orgName, 'env_name':env["name"], 'prodName':prodName}) repos = self.api.repos_by_env_product(env["id"], prod["id"], None, listDisabled) self.printer.print_items(repos) elif prodIncluded: prod = get_product(orgName, prodName, prodLabel, prodId) self.printer.set_header(_("Repo List for Product %(prodName)s in Org %(orgName)s ") % {'prodName':prodName, 'orgName':orgName}) repos = self.api.repos_by_product(orgName, prod["id"], listDisabled) self.printer.print_items(repos) else: env = get_environment(orgName, envName) self.printer.set_header(_("Repo List For Org %(orgName)s Environment %(env_name)s") % {'orgName':orgName, 'env_name':env["name"]}) repos = self.api.repos_by_org_env(orgName, env["id"], listDisabled) self.printer.print_items(repos) return os.EX_OK
def run(self): org_name = self.get_option('org') system_group_name = self.get_option('name') job_id = self.get_option('job_id') self.printer.set_header( _("System Group Job tasks For [ %s ]") % (system_group_name)) system_group = get_system_group(org_name, system_group_name) # get list of jobs history = self.api.system_group_history(org_name, system_group['id'], job_id) if history == None: print >> sys.stderr, _("Could not find job [ %(job_id)s ] for system group [ %(system_group_name)s ]") \ % {'job_id':job_id, 'system_group_name':system_group_name} return os.EX_DATAERR tasks = history['tasks'] batch_add_columns(self.printer, {'id': _("Task ID")}, {'uuid': _("System UUID")}, \ {'state': _("State")}, {'progress': _("Progress")}, {'start_time': _("Start Time")}, \ {'finish_time': _("Finish Time")}) self.printer.print_items(tasks)
def run(self): orgName = self.get_option('org') envName = self.get_option('environment') csName = self.get_option('name') displayDeps = self.has_option('deps') cset = get_changeset(orgName, envName, csName) cset['environment_name'] = envName cset["errata"] = self.format_item_list("display_name", cset["errata"]) cset["products"] = self.format_item_list("name", cset["products"]) cset["packages"] = self.format_item_list("display_name", cset["packages"]) cset["repositories"] = self.format_item_list("name", cset["repos"]) cset["content_views"] = self.format_item_list("name", cset["content_views"]) cset["distributions"] = self.format_item_list("distribution_id", cset["distributions"]) if displayDeps: cset["dependencies"] = self.get_dependencies(cset["id"]) batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'action_type': _("Action Type")}) self.printer.add_column('description', _("Description"), multiline=True, show_with=printer.VerboseStrategy) self.printer.add_column('updated_at', _("Last Updated"), formatter=format_date) batch_add_columns(self.printer, {'state': _("State")}, \ {'environment_id': _("Environment ID")}, {'environment_name': _("Environment Name")}) batch_add_columns(self.printer, {'errata': _("Errata")}, {'products': _("Products")}, \ {'packages': _("Packages")}, {'repositories': _("Repositories")}, \ {'distributions': _("Distributions")}, {'content_views': _("Content Views")}, \ multiline=True, show_with=printer.VerboseStrategy) if displayDeps: self.printer.add_column('dependencies', _("Dependencies"), \ multiline=True, show_with=printer.VerboseStrategy) self.printer.set_header(_("Changeset Info")) self.printer.print_item(cset) return os.EX_OK
def test_it_adds_columns(self): batch_add_columns(self.printer, {'col_a': "Column A"}, {'col_b': "Column B"}) self.printer.add_column.assert_any_call("col_a", "Column A") self.printer.add_column.assert_any_call("col_b", "Column B")
def print_packages(self, packages): batch_add_columns(self.printer, {'id': _("ID")}, {'name': _("Name")}, {'filename': _("Filename")}) self.printer.print_items(packages)
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') if sys_uuid: self.printer.set_header(_("System Information [ %s ]") % sys_uuid) elif env_name is None: self.printer.set_header( _("System Information For Org [ %s ]") % org_name) else: self.printer.set_header(_("System Information For Environment [ %(env_name)s ] in Org [ %(org_name)s ]") \ % {'env_name':env_name, 'org_name':org_name}) # get system details system = get_system(org_name, sys_name, env_name, sys_uuid) custom_info_api = CustomInfoAPI() custom_info = custom_info_api.get_custom_info("system", system['id']) system['custom_info'] = stringify_custom_info(custom_info) system["activation_keys"] = "[ " + ", ".join( [ak["name"] for ak in system["activation_key"]]) + " ]" if 'host' in system: system['host'] = system['host']['name'] if 'guests' in system: system["guests"] = "[ " + ", ".join( [guest["name"] for guest in system["guests"]]) + " ]" if 'environment' in system: system['environment'] = system['environment']['name'] if 'content_view' in system: system['content_view'] = "[ %s ]" % system['content_view']['name'] batch_add_columns(self.printer, {'name': _("Name")}, {'ipv4_address': _("IPv4 Address")}, \ {'uuid': _("UUID")}, {'environment': _("Environment")}, {'location': _("Location")}) self.printer.add_column('created_at', _("Registered"), formatter=format_date) self.printer.add_column('updated_at', _("Last Updated"), formatter=format_date) self.printer.add_column('description', _("Description"), multiline=True) if 'release' in system and system['release']: self.printer.add_column('release', _("OS Release")) self.printer.add_column('activation_keys', _("Activation Keys"), multiline=True, \ show_with=printer.VerboseStrategy) self.printer.add_column('host', _("Host"), show_with=printer.VerboseStrategy) self.printer.add_column('sockets', _("Sockets")) self.printer.add_column('ram', _("RAM (MB)")) self.printer.add_column('serviceLevel', _("Service Level")) self.printer.add_column('guests', _("Guests"), show_with=printer.VerboseStrategy) self.printer.add_column('custom_info', _("Custom Info"), multiline=True, show_with=printer.VerboseStrategy) self.printer.add_column('content_view', _("Content View")) self.printer.print_item(system) return os.EX_OK
def run(self): name = self.get_option('name') org = self.get_option('org') available = self.get_option('available') uuid = self.get_option('uuid') display_name = name or uuid if not uuid: uuid = get_distributor(org, name)['uuid'] self.printer.set_strategy(VerboseStrategy()) if not available: # listing current subscriptions result = self.api.subscriptions(uuid) if result == None or len(result['entitlements']) == 0: print _("No Subscriptions found for Distributor [ %(display_name)s ] in Org [ %(org)s ]") \ % {'display_name':display_name, 'org':org} return os.EX_OK def entitlements(): for entitlement in result['entitlements']: entitlement_ext = entitlement.copy() provided_products = ', '.join([ e['name'] for e in entitlement_ext['providedProducts'] ]) if provided_products: entitlement_ext['providedProductsFormatted'] = _( 'Not Applicable') else: entitlement_ext[ 'providedProductsFormatted'] = provided_products serial_ids = ', '.join( [u_str(s['id']) for s in entitlement_ext['serials']]) entitlement_ext['serialIds'] = serial_ids yield entitlement_ext self.printer.set_header( _("Current Subscriptions for Distributor [ %s ]") % display_name) self.printer.add_column('entitlementId', _("Subscription ID")) self.printer.add_column('serialIds', _('Serial ID')) batch_add_columns(self.printer, {'poolName': _("Pool Name")}, \ {'expires': _("Expires")}, {'consumed': _("Consumed")}, \ {'quantity': _("Quantity")}, {'sla': _("SLA")}, {'contractNumber': _("Contract Number")}) self.printer.add_column('providedProductsFormatted', _('Provided Products')) self.printer.print_items(entitlements()) else: # listing available pools result = self.api.available_pools(uuid) if result == None or len(result) == 0: print _("No Pools found for Distributor [ %(display_name)s ] in Org [ %(org)s ]") \ % {'display_name':display_name, 'org':org} return os.EX_OK def available_pools(): for pool in result['pools']: pool_ext = pool.copy() provided_products = ', '.join([ p['productName'] for p in pool_ext['providedProducts'] ]) if provided_products: pool_ext['providedProductsFormatted'] = _( 'Not Applicable') else: pool_ext[ 'providedProductsFormatted'] = provided_products if pool_ext['quantity'] == -1: pool_ext['quantity'] = _('Unlimited') # Make the productAttributes easier to access for productAttribute in pool['productAttributes']: pool_ext['attr_' + productAttribute['name']] = productAttribute[ 'value'] yield pool_ext self.printer.set_header( _("Available Subscriptions for Distributor [ %s ]") % display_name) self.printer.add_column('id', _("ID")) self.printer.add_column('productName', _("Name")) batch_add_columns(self.printer, {'endDate': _("End Date")}, \ {'consumed': _("Consumed")}, {'quantity': _("Quantity")}, {'sockets': _("Sockets")}) self.printer.add_column('attr_stacking_id', _("Stacking ID")) self.printer.add_column('attr_multi-entitlement', _("Multi-entitlement")) self.printer.add_column('providedProductsFormatted', _("Provided products")) self.printer.print_items(available_pools()) return os.EX_OK