def ExpandKonletCosImageFlag(compute_client):
    'Select a COS image to run Konlet.\n\n  This function scans three families in order:\n  - stable\n  - beta\n  - dev\n  looking for the first image with version at least _MIN_PREFERRED_COS_VERSION.\n\n  Args:\n    compute_client: ClientAdapter, The Compute API client adapter\n\n  Returns:\n    COS image at version _MIN_PREFERRED_COS_VERSION or later.\n\n  Raises:\n    NoCosImageException: No COS image at version at least\n    _MIN_PREFERRED_COS_VERSION was found. This should not happen if backend is\n    healthy.\n  '
    compute = compute_client.apitools_client
    images = compute_client.MakeRequests([(compute.images, 'List', compute_client.messages.ComputeImagesListRequest(project=COS_PROJECT))])
    name_re_template = 'cos-{}-(\\d+)-.*'
    image_families = ['stable', 'beta', 'dev']
    for family in image_families:
        name_re = name_re_template.format(family)

        def MakeCreateComparisonKey(name_re):

            def CreateComparisonKey(image):
                version = int(re.match(name_re, image.name).group(1))
                timestamp = times.ParseDateTime(image.creationTimestamp)
                return (version, timestamp)
            return CreateComparisonKey
        cos_images = sorted([image for image in images if re.match(name_re, image.name)], key=MakeCreateComparisonKey(name_re))
        if (cos_images and (MakeCreateComparisonKey(name_re)(cos_images[(- 1)])[0] >= _MIN_PREFERRED_COS_VERSION)):
            return cos_images[(- 1)].selfLink
    raise NoCosImageException()
Select a COS image to run Konlet.

This function scans three families in order:
- stable
- beta
- dev
looking for the first image with version at least _MIN_PREFERRED_COS_VERSION.

Args:
  compute_client: ClientAdapter, The Compute API client adapter

Returns:
  COS image at version _MIN_PREFERRED_COS_VERSION or later.

Raises:
  NoCosImageException: No COS image at version at least
  _MIN_PREFERRED_COS_VERSION was found. This should not happen if backend is
  healthy.
def ExpandKonletCosImageFlag(compute_client):
    'Select a COS image to run Konlet.\n\n  This function scans three families in order:\n  - stable\n  - beta\n  - dev\n  looking for the first image with version at least _MIN_PREFERRED_COS_VERSION.\n\n  Args:\n    compute_client: ClientAdapter, The Compute API client adapter\n\n  Returns:\n    COS image at version _MIN_PREFERRED_COS_VERSION or later.\n\n  Raises:\n    NoCosImageException: No COS image at version at least\n    _MIN_PREFERRED_COS_VERSION was found. This should not happen if backend is\n    healthy.\n  '
    compute = compute_client.apitools_client
    images = compute_client.MakeRequests([(compute.images, 'List', compute_client.messages.ComputeImagesListRequest(project=COS_PROJECT))])
    name_re_template = 'cos-{}-(\\d+)-.*'
    image_families = ['stable', 'beta', 'dev']
    for family in image_families:
        name_re = name_re_template.format(family)

        def MakeCreateComparisonKey(name_re):

            def CreateComparisonKey(image):
                version = int(re.match(name_re, image.name).group(1))
                timestamp = times.ParseDateTime(image.creationTimestamp)
                return (version, timestamp)
            return CreateComparisonKey
        cos_images = sorted([image for image in images if re.match(name_re, image.name)], key=MakeCreateComparisonKey(name_re))
        if (cos_images and (MakeCreateComparisonKey(name_re)(cos_images[(- 1)])[0] >= _MIN_PREFERRED_COS_VERSION)):
            return cos_images[(- 1)].selfLink
    raise NoCosImageException()