示例#1
0
def as_channelinfo(session: ClientSession,
                   channel: ChannelSpec) -> ChannelInfo:
    """
    Coerces a channel value into a koji channel info dict.

    If channel is an
     * int, will attempt to load as a channel ID
     * str, will attempt to load as a channel name
     * dict, will presume already a channel info

    :param session: an active koji client session

    :param channel: value to lookup

    :raises NoSuchChannel: if the channel value could not be resolved
      into a channel info dict

    :since: 1.1
    """

    if isinstance(channel, (str, int)):
        info = session.getChannel(channel)
    elif isinstance(channel, dict):
        info = channel
    else:
        info = None

    if not info:
        raise NoSuchChannel(channel)

    return info
示例#2
0
def gather_hosts_checkins(
        session: ClientSession,
        arches: Optional[List[str]] = None,
        channel: Optional[str] = None,
        skiplist: Optional[List[str]] = None) -> List[DecoratedHostInfo]:
    """
    Similar to session.listHosts, but results are decorated with a new
    "last_update" entry, which is the timestamp for the host's most
    recent check-in with the hub. This can be used to identify
    builders which are enabled, but no longer responding.

    :param session: an active koji client session

    :param arches: List of architecture names to filter builders by.
        Default, all arches

    :param channel: Channel name to filter builders by. Default,
        builders in any channel.

    :param skiplist: List of glob-style patterns of builders to
        omit. Default, all builders included

    :since: 1.0
    """

    arches = arches or None

    # listHosts only accepts channel filtering by the ID, so let's
    # resolve those. This should also work if channel is already an
    # ID, and should validate that the channel exists.
    if channel:
        chan_data = session.getChannel(channel)
        if chan_data is None:
            raise NoSuchChannel(channel)
        chan_id = chan_data["id"]
    else:
        chan_id = None

    loaded: Iterable[HostInfo]
    loaded = session.listHosts(arches, chan_id, None, True, None, None)
    loaded = filter(None, loaded)

    if skiplist:
        loaded = globfilter(loaded, skiplist, key="name", invert=True)

    # collect a mapping of builder ids to builder info
    bldrs: Dict[int, DecoratedHostInfo]
    bldrs = {b["id"]: cast(DecoratedHostInfo, b) for b in loaded}

    updates = iter_bulk_load(session, session.getLastHostUpdate, bldrs)

    # correlate the update timestamps with the builder info
    for bldr_id, data in updates:
        data = parse_datetime(data, strict=False) if data else None
        bldrs[bldr_id]["last_update"] = data

    return list(bldrs.values())