From 4dc970d5713f43b5e8c1370013c9dc3b93b97e4d Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Wed, 4 Dec 2024 10:54:30 +0000 Subject: [PATCH] Add cinder volume attachment cleanup script --- tools/cleanup-cinder-attachments.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 tools/cleanup-cinder-attachments.sh diff --git a/tools/cleanup-cinder-attachments.sh b/tools/cleanup-cinder-attachments.sh new file mode 100755 index 00000000..84521bf9 --- /dev/null +++ b/tools/cleanup-cinder-attachments.sh @@ -0,0 +1,11 @@ +#!/bin/bash -u +for vol in $(openstack volume list| grep juju| grep in-use| awk '{print $2}'); do + echo "Finding attachments for in-use volume $vol" + for server in $(openstack volume attachment list --os-volume-api-version 3.27 --volume-id $vol -c 'Server ID' -f value); do + openstack server show $server && continue + echo "Deleting attachments for volume $vol from (non-existent) server $server" + for id in $(openstack volume attachment list --os-volume-api-version 3.27 --volume-id $vol -c 'ID' -f value); do + openstack volume attachment delete --os-volume-api-version 3.27 $id + done + done +done