From feeb3806493fdbec09ecd185350203d3d554dc35 Mon Sep 17 00:00:00 2001 From: Alexis Camilleri <7473485+acamilleri@users.noreply.github.com> Date: Mon, 24 Feb 2020 06:38:14 +0100 Subject: [PATCH] scaleway_compute: check image on get instead of list (#67655) * fix scaleway_compute: check image on get instead of list * add changelog Signed-off-by: Alexis Camilleri --- ...caleway_compute-get-image-instead-loop-on-list.yml | 2 ++ .../modules/cloud/scaleway/scaleway_compute.py | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 changelogs/fragments/67655-scaleway_compute-get-image-instead-loop-on-list.yml diff --git a/changelogs/fragments/67655-scaleway_compute-get-image-instead-loop-on-list.yml b/changelogs/fragments/67655-scaleway_compute-get-image-instead-loop-on-list.yml new file mode 100644 index 00000000000..47fcb065d0e --- /dev/null +++ b/changelogs/fragments/67655-scaleway_compute-get-image-instead-loop-on-list.yml @@ -0,0 +1,2 @@ +bugfixes: +- 'scaleway_compute(check_image_id): use get image instead loop on first page of images results' diff --git a/lib/ansible/modules/cloud/scaleway/scaleway_compute.py b/lib/ansible/modules/cloud/scaleway/scaleway_compute.py index 15870b8dd79..261e9410a4a 100644 --- a/lib/ansible/modules/cloud/scaleway/scaleway_compute.py +++ b/lib/ansible/modules/cloud/scaleway/scaleway_compute.py @@ -178,14 +178,11 @@ SCALEWAY_TRANSITIONS_STATES = ( def check_image_id(compute_api, image_id): - response = compute_api.get(path="images") + response = compute_api.get(path="images/%s" % image_id) - if response.ok and response.json: - image_ids = [image["id"] for image in response.json["images"]] - if image_id not in image_ids: - compute_api.module.fail_json(msg='Error in getting image %s on %s' % (image_id, compute_api.module.params.get('api_url'))) - else: - compute_api.module.fail_json(msg="Error in getting images from: %s" % compute_api.module.params.get('api_url')) + if not response.ok: + msg = 'Error in getting image %s on %s : %s' % (image_id, compute_api.module.params.get('api_url'), response.json) + compute_api.module.fail_json(msg=msg) def fetch_state(compute_api, server):