From 96d767fd23fc8b36cfdde7b5fbb5baf4d874ca79 Mon Sep 17 00:00:00 2001 From: Aliaksandr Panasiuk Date: Tue, 13 May 2025 08:54:50 +0200 Subject: [PATCH] #1 - add method delete_orphaned_volumes --- .../common/providers/aws_provider/aws.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/github_actions/common/providers/aws_provider/aws.py b/src/github_actions/common/providers/aws_provider/aws.py index 87edb8a..ac6bebe 100644 --- a/src/github_actions/common/providers/aws_provider/aws.py +++ b/src/github_actions/common/providers/aws_provider/aws.py @@ -131,6 +131,20 @@ def print_orphaned_volumes(self): f"| {vol['Name']} | {vol['State']} | {vol['VolumeType']} | {vol['SizeGiB']}" ) + def delete_orphaned_volumes(self): + volumes = self.list_orphaned_volumes() + if not volumes: + return + + print(f"Found {len(volumes)} orphaned volumes. Deleting...") + for vol in volumes: + vol_id = vol["VolumeId"] + try: + self.ec2_client.delete_volume(VolumeId=vol_id) + print(f"Deleted volume {vol_id}") + except (ClientError, BotoCoreError) as err: + raise ValueError(f"failed to delete volume {vol_id}: {err}") + class S3BucketManager(AWSSessionManager): def __init__(self, region_name: str):