From ae2ae6d03907bdd6d5ad814d07b3d5b93f51b3f9 Mon Sep 17 00:00:00 2001 From: Vladimir Khlyunev Date: Mon, 25 Apr 2022 21:21:33 +0400 Subject: [PATCH] Cycle all attachments while cleaninig up volumes Change-Id: I12f6dffae4b3daaab0c7055588d49ae0390bba8b --- os_cloud_cleaner/os_connector.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/os_cloud_cleaner/os_connector.py b/os_cloud_cleaner/os_connector.py index d45779e..2277014 100644 --- a/os_cloud_cleaner/os_connector.py +++ b/os_cloud_cleaner/os_connector.py @@ -122,6 +122,10 @@ class OpenStackActions(object): def get_volume(self, uuid): return self.cinder.volumes.get(uuid) + def get_volume_attachments(self, volume_uuid): + volume = self.cinder.volumes.get(volume_uuid) + return volume.attachments + def get_keypairs(self): keypairs = self.nova.keypairs.list() resp = [] @@ -381,8 +385,9 @@ class OpenStackActions(object): existing_volumes.append(uuid) for uuid in existing_volumes: if self.check_volume_attached(uuid): - logger.info("Detaching volume {}".format(uuid)) - self.cinder.volumes.detach(uuid) + for attachment in self.get_volume_attachments(uuid): + logger.info("Detaching volume {}".format(uuid)) + self.cinder.volumes.detach(uuid, attachment['attachment_id']) try: helpers.wait_false(self.check_any_volume_attached, interval=3, -- 2.45.2