Skip to content

Commit 96d767f

Browse files
committed
#1 - add method delete_orphaned_volumes
1 parent 3969f89 commit 96d767f

File tree

1 file changed

+14
-0
lines changed
  • src/github_actions/common/providers/aws_provider

1 file changed

+14
-0
lines changed

src/github_actions/common/providers/aws_provider/aws.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ def print_orphaned_volumes(self):
131131
f"| {vol['Name']} | {vol['State']} | {vol['VolumeType']} | {vol['SizeGiB']}"
132132
)
133133

134+
def delete_orphaned_volumes(self):
135+
volumes = self.list_orphaned_volumes()
136+
if not volumes:
137+
return
138+
139+
print(f"Found {len(volumes)} orphaned volumes. Deleting...")
140+
for vol in volumes:
141+
vol_id = vol["VolumeId"]
142+
try:
143+
self.ec2_client.delete_volume(VolumeId=vol_id)
144+
print(f"Deleted volume {vol_id}")
145+
except (ClientError, BotoCoreError) as err:
146+
raise ValueError(f"failed to delete volume {vol_id}: {err}")
147+
134148

135149
class S3BucketManager(AWSSessionManager):
136150
def __init__(self, region_name: str):

0 commit comments

Comments
 (0)