From 69294b1215b235204a4e28a9637b3f017decea3d Mon Sep 17 00:00:00 2001
From: Krish Moodbidri <krish94@uab.edu>
Date: Thu, 16 Nov 2023 12:45:02 -0600
Subject: [PATCH] Refactor OpenStack script to handle multiple attached volumes

The original code assumed only one volume is attached to the specified OpenStack instance. This commit modifies the script to correctly handle scenarios where multiple volumes are attached. The updated code uses an array to store all attached volumes, iterates over the array, and performs actions for each volume. This enhances the script's flexibility and ensures accurate detachment messages for all attached volumes.

Changes:
- Modified the extraction of the instance ID to handle potential changes in the output structure.
- Implemented an array to store all attached volumes.
- Added a loop to iterate over the array and print detachment messages for each volume.
---
 .gitlab-ci.yml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6c4d55d..71e6da4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -136,8 +136,11 @@ production-deploy:
   tags: [build]
   script:
     - export prod_instance_id=$(openstack floating ip show $prod_floating_ip -c port_details -f value | awk -F', ' '{print $2}' | awk -F"'" '{print $2}')
-    - export prod_volume=$(openstack server show $prod_instance_id -c volumes_attached -f value | awk -F"'" '{print $4}')
-    - echo "Detaching prod_volume_id=${prod_volume} from prod_instance_id=${prod_instance_id}"
+    - export prod_volumes=($(openstack server show $prod_instance_id -c volumes_attached -f value | awk -F"'" '{print $4}'))    # Iterate over the array and perform actions for each volume
+    - for prod_volume in "${prod_volumes[@]}"; do
+      - echo "Detaching prod_volume_id=${prod_volume} from prod_instance_id=${prod_instance_id}"
+    - done
+
     - |
       eval $(ssh-agent -s)
       chmod 400 "${SSH_PRIV_KEY}"
-- 
GitLab