#399 Added hostinfo command to cli
Merged 5 years ago by mikem. Opened 5 years ago by breilly.
breilly/koji hostinfo-364  into  master

file modified
+54
@@ -3457,6 +3457,60 @@ 

                  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] <hostname> [<hostname> ...]")

+     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] <src-tag> <dst-tag>")

@@ -91,6 +91,7 @@ 

  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

Sample output:

koji hostinfo buildhw-02.phx2.fedoraproject.org
Name: buildhw-02.phx2.fedoraproject.org
ID: 100
Arches: x86_64 i386
Capacity: 4.0
Task Load: 0.10
Description: None
Comment: None
Enabled: yes
Ready: yes
Last Update: 2017-04-27 15:08:00
Channels:
default
createrepo
appliance
livecd
image
livemedia
Active Buildroots:
None

rebased

5 years ago

Made a change to how channels are displayed, new output:

koji hostinfo 100
Name: buildhw-02.phx2.fedoraproject.org
ID: 100
Arches: x86_64 i386
Capacity: 4.0
Task Load: 0.00
Description: None
Comment: None
Enabled: yes
Ready: yes
Last Update: 2017-04-27 15:15:57
Channels: default createrepo appliance livecd image livemedia
Active Buildroots:
None

rebased

5 years ago

splitlines() is preferred

Maybe just leave blank, as the web ui does?

similar comments on this part

seems like a list comprehension would work nicely here
[c['name] for c in session.listChannels(hostID=info['id']]

Can we also show state and creation time as web does?

rebased

5 years ago

rebased

5 years ago

We can't use .format quite yet. Not until we formally drop RHEL5 support

rebased

5 years ago

Commit 63df56e fixes this pull-request

Pull-Request has been merged by mikem@redhat.com

5 years ago