From 6e1c7e772c3f915bc499f93ffb91a286becc6753 Mon Sep 17 00:00:00 2001 From: Jana Cupova Date: Jun 23 2021 13:32:18 +0000 Subject: Hosts page with more filters and added channel column Fixes: https://pagure.io/koji/issue/1423 Fixes: https://pagure.io/koji/issue/827 --- diff --git a/www/kojiweb/hosts.chtml b/www/kojiweb/hosts.chtml index 0750f77..aa34e91 100644 --- a/www/kojiweb/hosts.chtml +++ b/www/kojiweb/hosts.chtml @@ -1,13 +1,47 @@ #from kojiweb import util -#attr _PASSTHROUGH = ['state', 'order'] +#def headerState($state) + #if $state == 'enabled' +Enabled hosts + #elif $state == 'disabled' +Disabled hosts + #else +Hosts + #end if +#end def + +#def headerReady($ready) + #if $ready == 'ready' +which are ready + #elif $ready == 'notready' +which are not ready + #end if +#end def + +#def headerArch($arch) + #if $arch == 'all' +on all arches + #else +on $arch arch + #end if +#end def + +#def headerChannel($channel) + #if $channel == 'all' +in all channels + #else +in $channel channel + #end if +#end def + +#attr _PASSTHROUGH = ['state', 'order', 'ready', 'channel', 'arch'] #include "includes/header.chtml" -

Hosts

+

$headerState($state) $headerReady($ready) $headerArch($arch) $headerChannel($channel)

- - + @@ -58,6 +122,11 @@ + @@ -65,11 +134,11 @@ #end for #else - + #end if -
+ + + +
State: @@ -17,12 +51,41 @@ + + Channels: + + +
+ Ready: + + + + Arches: + +
+ #if $len($hostPages) > 1
Page: @@ -48,6 +111,7 @@
ID $util.sortImage($self, 'id') Name $util.sortImage($self, 'name') Arches $util.sortImage($self, 'arches')Channels $util.sortImage($self, 'channels') Enabled? $util.sortImage($self, 'enabled') Ready? $util.sortImage($self, 'ready') Last Update $util.sortImage($self, 'last_update')$host.id $host.name $host.arches + #for $channame, $chan_id in zip($host.channels, $host.channels_id) + $channame + #end for + #if $host.enabled then $util.imageTag('yes') else $util.imageTag('no')# #if $host.ready then $util.imageTag('yes') else $util.imageTag('no')# $util.formatTime($host.last_update)
No hostsNo hosts
+ #if $len($hostPages) > 1 Page: diff --git a/www/kojiweb/index.py b/www/kojiweb/index.py index c33d173..4a6d283 100644 --- a/www/kojiweb/index.py +++ b/www/kojiweb/index.py @@ -30,6 +30,7 @@ import os.path import re import sys import time +import itertools import koji import kojiweb.util @@ -1621,30 +1622,62 @@ def cancelbuild(environ, buildID): _redirect(environ, 'buildinfo?buildID=%i' % build['id']) -def hosts(environ, state='enabled', start=None, order='name'): +def hosts(environ, state='enabled', start=None, order='name', ready='all', channel='all', + arch='all'): values = _initValues(environ, 'Hosts', 'hosts') server = _getServer(environ) values['order'] = order - args = {} + hosts = server.listHosts() + values['arches'] = sorted(set(itertools.chain(*[host['arches'].split() for host in hosts]))) if state == 'enabled': - args['enabled'] = True + hosts = [x for x in hosts if x['enabled']] elif state == 'disabled': - args['enabled'] = False + hosts = [x for x in hosts if not x['enabled']] else: state = 'all' values['state'] = state - hosts = server.listHosts(**args) + if ready == 'yes': + hosts = [x for x in hosts if x['ready']] + elif ready == 'no': + hosts = [x for x in hosts if not x['ready']] + else: + ready = 'all' + values['ready'] = ready - server.multicall = True - for host in hosts: - server.getLastHostUpdate(host['id'], ts=True) - updates = server.multiCall() - for host, [lastUpdate] in zip(hosts, updates): - host['last_update'] = lastUpdate + if arch != 'all': + arch = _validate_arch(arch) + if arch: + hosts = [x for x in hosts if arch in x['arches']] + else: + arch = 'all' + values['arch'] = arch + + with server.multicall() as m: + list_channels = [m.listChannels(hostID=host['id']) for host in hosts] + for host, channels in zip(hosts, list_channels): + host['channels'] = [] + host['channels_id'] = [] + for chan in channels.result: + host['channels'].append(chan['name']) + host['channels_id'].append(chan['id']) + + if channel != 'all': + hosts = [x for x in hosts if channel in x['channels']] + else: + channel = 'all' + values['channel'] = channel + + values['channels'] = server.listChannels() + + with server.multicall() as m: + updates = [m.getLastHostUpdate(host['id'], ts=True) for host in hosts] + + for host, lastUpdate in zip(hosts, updates): + host['last_update'] = lastUpdate.result # Paginate after retrieving last update info so we can sort on it kojiweb.util.paginateList(values, hosts, start, 'hosts', 'host', order)