|
37 | 37 | import compute.deleteprotection.SetDeleteProtection; |
38 | 38 | import compute.disks.DeleteDisk; |
39 | 39 | import compute.disks.DeleteSnapshot; |
| 40 | +import compute.disks.RegionalDelete; |
40 | 41 | import compute.reservation.DeleteReservation; |
41 | 42 | import java.io.IOException; |
42 | 43 | import java.nio.charset.StandardCharsets; |
@@ -231,6 +232,23 @@ && isCreatedBeforeThresholdTime(snapshot.getCreationTimestamp())) { |
231 | 232 | } |
232 | 233 | } |
233 | 234 |
|
| 235 | + |
| 236 | + // Delete regional disks which starts with the given prefixToDelete and |
| 237 | + // has creation timestamp >24 hours. |
| 238 | + public static void cleanUpExistingRegionalDisks( |
| 239 | + String prefixToDelete, String projectId, String region) |
| 240 | + throws IOException, ExecutionException, InterruptedException, TimeoutException { |
| 241 | + try (RegionDisksClient disksClient = RegionDisksClient.create()) { |
| 242 | + for (Disk disk : disksClient.list(projectId, region).iterateAll()) { |
| 243 | + if (disk.getName().contains(prefixToDelete) |
| 244 | + && disk.getRegion().equals(region) |
| 245 | + && isCreatedBeforeThresholdTime(disk.getCreationTimestamp())) { |
| 246 | + RegionalDelete.deleteRegionalDisk(projectId, region, disk.getName()); |
| 247 | + } |
| 248 | + } |
| 249 | + } |
| 250 | + } |
| 251 | + |
234 | 252 | // Delete storagePools which starts with the given prefixToDelete and |
235 | 253 | // has creation timestamp >24 hours. |
236 | 254 | public static void cleanUpExistingStoragePool( |
|
0 commit comments