You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2016/01/21 01:03:39 UTC
[15/19] jclouds git commit: JCLOUDS-1052: Fix DigitalOcean2
deleteImage
JCLOUDS-1052: Fix DigitalOcean2 deleteImage
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/1ac6fa84
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/1ac6fa84
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/1ac6fa84
Branch: refs/heads/master
Commit: 1ac6fa8426d645d74409801464101d85bff03625
Parents: 575d39e
Author: Ignasi Barrera <na...@apache.org>
Authored: Tue Dec 22 23:05:29 2015 +0100
Committer: Ignasi Barrera <na...@apache.org>
Committed: Tue Dec 22 23:12:59 2015 +0100
----------------------------------------------------------------------
.../extensions/DigitalOcean2ImageExtension.java | 24 ++++++++++++--------
1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/1ac6fa84/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java
----------------------------------------------------------------------
diff --git a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java
index 524e4d1..56e67de 100644
--- a/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java
+++ b/providers/digitalocean2/src/main/java/org/jclouds/digitalocean2/compute/extensions/DigitalOcean2ImageExtension.java
@@ -118,17 +118,21 @@ public class DigitalOcean2ImageExtension implements ImageExtension {
@Override
public boolean deleteImage(String id) {
- try {
- // The id of the image can be an id or a slug. Use the corresponding method of the API depending on what is
- // provided. If it can be parsed as a number, use the method to destroy by ID. Otherwise, destroy by slug.
- Integer imageId = Ints.tryParse(id);
- if (imageId != null) {
- logger.debug(">> image does not have a slug. Using the id to delete the image...");
- api.imageApi().delete(imageId);
+ String imageId = ImageInRegion.extractImageId(id);
+ Integer numericId = Ints.tryParse(imageId); // User images don't have a slug, so we expect a numeric id here
+
+ if (numericId != null) {
+ try {
+ logger.debug(">> deleting image %s...", id);
+ api.imageApi().delete(numericId);
+ return true;
+ } catch (Exception ex) {
+ logger.error(ex, ">> error deleting image %s", id);
}
- return true;
- } catch (Exception ex) {
- return false;
+ } else {
+ logger.warn(">> image %s is not a user image and cannot be deleted", id);
}
+
+ return false;
}
}