From 64216178049385b9ef6524820a3f23a2f75e13d4 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: May 21 2019 14:05:11 +0000 Subject: PR#1425: add --show-channels listing to list-hosts Merges #1425 https://pagure.io/koji/pull-request/1425 Fixes: #1424 https://pagure.io/koji/issue/1424 Add channels to list-hosts --- diff --git a/cli/koji_cli/commands.py b/cli/koji_cli/commands.py index c263a75..02c3f6b 100644 --- a/cli/koji_cli/commands.py +++ b/cli/koji_cli/commands.py @@ -2771,6 +2771,7 @@ def anon_handle_list_hosts(goptions, session, args): parser.add_option("--not-enabled", action="store_false", dest="enabled", help=_("Limit to not enabled hosts")) parser.add_option("--quiet", action="store_true", default=goptions.quiet, help=_("Do not print header information")) + parser.add_option("--show-channels", action="store_true", help=_("Show host's channels")) (options, args) = parser.parse_args(args) opts = {} activate_session(session, goptions) @@ -2809,10 +2810,25 @@ def anon_handle_list_hosts(goptions, session, args): host['ready'] = yesno(host['ready']) host['arches'] = ','.join(host['arches'].split()) + # pull hosts' channels + if options.show_channels: + session.multicall = True + for host in hosts: + session.listChannels(host['id']) + for host, [channels] in zip(hosts, session.multiCall()): + host['channels'] = ','.join(sorted([c['name'] for c in channels])) + + longest_host = max([len(h['name']) for h in hosts]) if not options.quiet: - print("Hostname Enb Rdy Load/Cap Arches Last Update") + hdr = "{hostname:<{longest_host}} Enb Rdy Load/Cap Arches Last Update".format(longest_host=longest_host, hostname='Hostname') + if options.show_channels: + hdr += " Channels" + print(hdr) + mask = "%%(name)-%ss %%(enabled)-3s %%(ready)-3s %%(task_load)4.1f/%%(capacity)-4.1f %%(arches)-16s %%(update)-19s" % longest_host + if options.show_channels: + mask += " %(channels)s" for host in hosts: - print("%(name)-28s %(enabled)-3s %(ready)-3s %(task_load)4.1f/%(capacity)-4.1f %(arches)-16s %(update)s" % host) + print(mask % host) def anon_handle_list_pkgs(goptions, session, args):