11#!/usr/bin/env python3
22#
3- # find-img .py
3+ # find_img .py
44#
5- # Searches for an image with distribution and version
5+ # Searches for an image with distribution and version and purpose
66#
77# (c) Kurt Garloff <[email protected] >, 7/2025 88# SPDX-License-Identifier: MIT
@@ -71,17 +71,19 @@ def img_sort_heuristic(images, distro, version, purpose):
7171def find_image (conn , distro , version , purpose = "generic" , strict = False , log = None ):
7272 """Return a sorted list of ID,Name pairs that contain the wanted image.
7373 Empty list indicates no image has been found. The list is sorted such
74- that (on SCS-compliant clouds), it will very likely contain the most
75- vanilla , most recent image as first element.
74+ that (on SCS-compliant clouds), it will very likely contain the best
75+ matching , most recent image as first element.
7676 If strict is set, multiple matches are not allowed.
7777 """
7878 ldistro = distro .lower ()
7979 # FIXME: The image.images() method only passes selected filters
80+ purpose_out = purpose
8081 images = [x for x in conn .image .images (os_distro = ldistro , os_version = version ,
8182 sort = "name:desc,created_at:desc" , visibility = "public" )
8283 if x .properties .get ("os_purpose" ) == purpose ]
8384 if len (images ) == 0 :
8485 warn (log , f"No image found with os_distro={ ldistro } os_version={ version } os_purpose={ purpose } " )
86+ purpose_out = ""
8587 # images = list(conn.image.images(os_distro=ldistro, os_version=version,
8688 # sort="name:desc,created_at:desc"))
8789 images = [x for x in conn .image .images (os_distro = ldistro , os_version = version ,
@@ -92,8 +94,8 @@ def find_image(conn, distro, version, purpose="generic", strict=False, log=None)
9294 return []
9395 # Now comes sorting magic for best backwards compatibility
9496 if len (images ) > 1 :
95- debug (log , f"Several { purpose } images found with os_distro={ ldistro } os_version={ version } " )
96- if ( strict ) :
97+ debug (log , f"Several { purpose_out } images found with os_distro={ ldistro } os_version={ version } " )
98+ if strict :
9799 return []
98100 return img_sort_heuristic (images , distro , version , purpose )
99101 return [(img .id , img .name ) for img in images ]
0 commit comments