public void deleteImage(Image image) { String imageId = image.getImageId(); logger.info("delete image, imageId={}", imageId); ec2.deregisterImage(new DeregisterImageRequest(imageId)); // our image always uses EBS as first and only drive List<BlockDeviceMapping> mappings = image.getBlockDeviceMappings(); if (!mappings.isEmpty()) { EbsBlockDevice ebs = mappings.get(0).getEbs(); if (ebs != null) { String snapshotId = ebs.getSnapshotId(); logger.info("delete snapshot, snapshotId={}", snapshotId); ec2.deleteSnapshot(new DeleteSnapshotRequest(snapshotId)); } } }
private void pargeImages(AmazonEC2 ec2, Image image) { String imageId = image.getImageId(); ec2.deregisterImage(new DeregisterImageRequest(imageId)); for (BlockDeviceMapping block : image.getBlockDeviceMappings()) { String snapshotId = block.getEbs().getSnapshotId(); ec2.deleteSnapshot(new DeleteSnapshotRequest().withSnapshotId(snapshotId)); } }
@Override public void deleteSnapshot(DeleteSnapshotRequest deleteSnapshotRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
void pargeSnapshot(AmazonEC2 ec2, String snapshotId) { DeleteSnapshotRequest request = new DeleteSnapshotRequest(snapshotId); ec2.deleteSnapshot(request); }
private void pargeSnapshot(AmazonEC2 ec2, String snapshotId, Context context) { DeleteSnapshotRequest request = new DeleteSnapshotRequest(snapshotId); ec2.deleteSnapshot(request); context.getLogger().log("Parge Snapshot. snapshotId[" + snapshotId + "]"); }
/** * Delete a Snapshot */ public static void deleteSnapshot(AmazonEC2AsyncClient client, String snapshotId) { client.deleteSnapshot(new DeleteSnapshotRequest().withSnapshotId(snapshotId)); }
/** * Find the snap & volumes associated with the AMI we used and delete it. * AWS doesn't help us out much and the only relationship (as of 2/14/2015) * we can leverage is the description field. * * @param ami * to find associated snaps for * @throws ServiceBrokerExceptions */ public void deleteStorageArtifacts(String ami) throws ServiceBrokerException { DescribeSnapshotsResult desc = ec2Client.describeSnapshots(); if (null == desc.getSnapshots()) { return; } List<Snapshot> snapshots = desc.getSnapshots(); // The only way I can find to track the snaps that get created (but not // cleaned up) as part of the ami creation is by the description. This // code is brittle and will probably fail in unexpected and glamorous // ways. String amiDesc = "Created by CreateImage(" + sourceInstanceId + ") for " + ami + " from vol"; // Would be nice if the aws client return optionals... List<Snapshot> matching = snapshots.stream() .filter(s -> safeContains(s::getDescription, amiDesc)) .collect(Collectors.toList()); switch (matching.size()) { case 0: // Should this throw? Might have been manually cleaned up...but it // may orphan the volume. It's done this way to allow people to // create their own instances in AWS and not jack them up by // deleting the volume log.error("No snapshots found for AMI " + ami); break; case 1: String snap = matching.get(0).getSnapshotId(); log.info("Deleting snapshot " + snap); ec2Client.deleteSnapshot(new DeleteSnapshotRequest() .withSnapshotId(snap)); deleteVolumeForSnap(snap); break; default: throw new ServiceBrokerException( "Found too many snapshots for AMI " + ami); } }
@Override public void delete(DeleteSnapshotRequest request) { delete(request, null); }
@Override public void delete(DeleteSnapshotRequest request, ResultCapture<Void> extractor) { resource.performAction("Delete", request, extractor); }
@Override public void delete(ResultCapture<Void> extractor) { DeleteSnapshotRequest request = new DeleteSnapshotRequest(); delete(request, extractor); }
/** unregister EBS snapshot; will fail if snapshot still in use */ public void snapshotDelete(final String snapshotId) throws Exception { final DeleteSnapshotRequest request = new DeleteSnapshotRequest(); request.setSnapshotId(snapshotId); amazonClient.deleteSnapshot(request); logger.info("removed snapshotId = " + snapshotId); }
/** * Performs the <code>Delete</code> action. * * <p> * The following request parameters will be populated from the data of this * <code>Snapshot</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>SnapshotId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see DeleteSnapshotRequest */ void delete(DeleteSnapshotRequest request);
/** * Performs the <code>Delete</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>Snapshot</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>SnapshotId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see DeleteSnapshotRequest */ void delete(DeleteSnapshotRequest request, ResultCapture<Void> extractor);