From nobody Fri Dec 19 19:19:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616083927; cv=none; d=zohomail.com; s=zohoarc; b=L9eYyOtX//K47QeBV3tYdoApEauHA47UsmbFflj4nBeUMirc6cwEDawOWRBxcofZ3dLfofAf7hnJ1TD8hx8R973XoaYpq6Yh8rqz0r7zMCOjjR4Ael3pTn54eRjJ3ZgK14aTL8EDjUg9zMjeNEdd7QF2LvpVIfvqXfht38mfTHg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616083927; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=7Qqx+IuMwpZEkuWCbzlmnEsb3NiVzGK2PLCaLgM1ySc=; b=M7MHfncpUQpJc9VHpEpRs3asNh+hEhMoyd3AQe2g5TqGpdskxxgaumqLRARw9TgSpTBZKO6RZqiPo6OhjXoWVac6jByJkfK6JfRQItcD312rRr60VfhBj1ICqycuh3HdADHnzTMpm/7twflhPSBM+RdJ3DN4ls6bsWUIsJtOG3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1616083927675206.3755115697237; Thu, 18 Mar 2021 09:12:07 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-205-5-TVzPSnNbSSRBsIA44VEg-1; Thu, 18 Mar 2021 12:12:03 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 13A43801817; Thu, 18 Mar 2021 16:11:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E26E35C1D1; Thu, 18 Mar 2021 16:11:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A0DCD4BB7C; Thu, 18 Mar 2021 16:11:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12IGBrmv024198 for ; Thu, 18 Mar 2021 12:11:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id E74CC60CEC; Thu, 18 Mar 2021 16:11:53 +0000 (UTC) Received: from nautilus.redhat.com (unknown [10.40.192.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 427D760CD7; Thu, 18 Mar 2021 16:11:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616083926; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7Qqx+IuMwpZEkuWCbzlmnEsb3NiVzGK2PLCaLgM1ySc=; b=Rd36qc+JH6GtC6Pytnuxo54IZYeKxw5fjFSPdswVZoWBqrtQzF3DcVtpHHe4tlFlet6/Lr qFt4f9ruhS+f1BYlYF79IBRG0v79O2jnoSXYtyGvBH9r/uIl96h2rkwfa/vJQFVIH+k5yD srPFVh1wywMIAANNadQhWHuvVXH9jAc= X-MC-Unique: 5-TVzPSnNbSSRBsIA44VEg-1 From: Erik Skultety To: libvir-list@redhat.com Subject: [libvirt PATCH v4 3/6] ci: Introduce a util module Date: Thu, 18 Mar 2021 17:11:43 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: eskultet@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" With the gradual rewrite of the Makefile to the 'helper' script will require helper functions that would better live in a separate util module. Signed-off-by: Erik Skultety Reviewed-by: Andrea Bolognani --- ci/util.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 ci/util.py diff --git a/ci/util.py b/ci/util.py new file mode 100644 index 0000000000..f9f8320276 --- /dev/null +++ b/ci/util.py @@ -0,0 +1,40 @@ +import json +import urllib.request +import urllib.parse + +from typing import Dict, List + + +def get_registry_uri(namespace: str, + gitlab_uri: str =3D "https://gitlab.com") -> str: + """ + Construct a v4 API URI pointing the namespaced project's image registr= y. + + :param namespace: GitLab project namespace, e.g. "libvirt/libvirt" + :param gitlab_uri: GitLab base URI, can be a private deployment + :param api_version: GitLab REST API version number + :return: URI pointing to a namespaced project's image registry + """ + + # this converts something like "libvirt/libvirt" to "libvirt%2Flibvirt" + namespace_urlenc =3D urllib.parse.quote_plus(namespace) + + project_uri =3D f"{gitlab_uri}/api/v4/projects/{namespace_urlenc}" + + uri =3D project_uri + "/registry/repositories" + return uri + + +def get_registry_images(uri: str) -> List[Dict]: + """ + List all container images that are currently available in the given Gi= tLab + project. + + :param uri: URI pointing to a GitLab instance's image registry + :return: list of container image names + """ + + r =3D urllib.request.urlopen(uri + "?per_page=3D100") + + # read the HTTP response and load the JSON part of it + return json.loads(r.read().decode()) --=20 2.30.2