From a03949fd1a77936bf1c862e91c1bfd74e1ddf42e Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Mon, 11 Dec 2023 22:28:39 +0100 Subject: [PATCH] In the mirror script first connect with the S3 API Signed-off-by: Christian Berendt --- openstack_image_manager/mirror.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/openstack_image_manager/mirror.py b/openstack_image_manager/mirror.py index 52d1cc1f..2aff5750 100644 --- a/openstack_image_manager/mirror.py +++ b/openstack_image_manager/mirror.py @@ -51,6 +51,18 @@ def main( logger.remove() logger.add(sys.stderr, format=log_fmt, level=level, colorize=True) + client = Minio( + minio_server, + access_key=minio_access_key, + secret_key=minio_secret_key, + ) + + result = client.bucket_exists(minio_bucket) + if not result: + logger.error(f"Create bucket '{minio_bucket}' first") + if not dry_run: + sys.exit(1) + onlyfiles = [] for f in listdir(images): if isfile(join(images, f)): @@ -58,23 +70,14 @@ def main( onlyfiles.append(f) all_images = [] - for file in onlyfiles: + for file in [x for x in onlyfiles if x.endswith(".yml")]: + logger.info(f"Processing file {file}") with open(join(images, file)) as fp: data = yaml.load(fp, Loader=yaml.SafeLoader) for image in data.get("images"): logger.debug(f"Adding {image['name']} to the list of images") all_images.append(image) - client = Minio( - minio_server, - access_key=minio_access_key, - secret_key=minio_secret_key, - ) - - result = client.bucket_exists(minio_bucket) - if not result: - logger.error(f"Create bucket '{minio_bucket}' first") - for image in all_images: if "versions" not in image: continue