From 63df56ea7e61ba958c8a7258532452c904f4804b Mon Sep 17 00:00:00 2001 From: Mike McLean Date: May 01 2017 18:32:48 +0000 Subject: PR#399 Added hostinfo command to cli Merges #399 https://pagure.io/koji/pull-request/399 Fixes #364 https://pagure.io/koji/issue/364 --- diff --git a/cli/koji b/cli/koji index a777d4c..c6c0a6d 100755 --- a/cli/koji +++ b/cli/koji @@ -3457,6 +3457,60 @@ def anon_handle_buildinfo(options, session, args): print("Changelog:") print(koji.util.formatChangelog(changelog)) +def anon_handle_hostinfo(options, session, args): + "[info] Print basic information about a host" + usage = _("usage: %prog hostinfo [options] [ ...]") + usage += _("\n(Specify the --help global option for a list of other help options)") + parser = OptionParser(usage=usage) + (options, args) = parser.parse_args(args) + if len(args) < 1: + parser.error(_("Please specify a host")) + assert False # pragma: no cover + activate_session(session) + for host in args: + if host.isdigit(): + host = int(host) + info = session.getHost(host) + if info is None: + print("No such host: %s\n" % host) + continue + print("Name: %(name)s" % info) + print("ID: %(id)d" % info) + print("Arches: %(arches)s" % info) + print("Capacity: %(capacity)s" % info) + print("Task Load: %(task_load).2f" % info) + if info['description']: + description = info['description'].splitlines() + print("Description: %s" % description[0]) + for line in description[1:]: + print("%s%s" % (" "*13, line)) + else: + print("Description:") + if info['comment']: + comment = info['comment'].splitlines() + print("Comment: %s" % comment[0]) + for line in comment[1:]: + print("%s%s" % (" "*9, line)) + else: + print("Comment:") + print("Enabled: %s" % (info['enabled'] and 'yes' or 'no')) + print("Ready: %s" % (info['ready'] and 'yes' or 'no')) + update = session.getLastHostUpdate(info['id']) + print("Last Update: %s" % update[:update.find('.')]) + print("Channels: %s" % ' '.join([c['name'] for c in session.listChannels(hostID=info['id'])])) + print("Active Buildroots:") + states = {0:"INIT", 1:"WAITING", 2:"BUILDING"} + rows = [('NAME', 'STATE', 'CREATION TIME')] + for s in range(0,3): + for b in session.listBuildroots(hostID=info['id'], state=s): + rows.append((("%s-%s-%s" % (b['tag_name'], b['id'], b['repo_id'])), states[s], + b['create_event_time'][:b['create_event_time'].find('.')])) + if len(rows) > 1: + for row in rows: + print("%-50s %-10s %-20s" % row) + else: + print("None") + def handle_clone_tag(options, session, args): "[admin] Duplicate the contents of one tag onto another tag" usage = _("usage: %prog clone-tag [options] ") diff --git a/tests/test_cli/data/list-commands.txt b/tests/test_cli/data/list-commands.txt index f2d6a25..5db98c4 100644 --- a/tests/test_cli/data/list-commands.txt +++ b/tests/test_cli/data/list-commands.txt @@ -91,6 +91,7 @@ download commands: info commands: buildinfo Print basic information about a build help List available commands + hostinfo Print basic information about a host latest-build Print the latest builds for a tag list-api Print the list of XML-RPC APIs list-buildroot List the rpms used in or built in a buildroot