incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] Added destroy method for image for VSphere and EC2
Date Wed, 13 Jul 2011 10:04:59 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    9 +++++++++
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |    3 +++
 server/server.rb                                   |   14 ++++++++++++++
 server/views/images/show.html.haml                 |    1 +
 4 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 4e182a3..7be0c5b 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -169,6 +169,15 @@ module Deltacloud
           end
         end
 
+        def destroy_image(credentials, opts={})
+          ec2 = new_client(credentials)
+          safely do
+            unless ec2.deregister_image(opts[:id])
+              raise "ERROR: Unable to deregister AMI"
+            end
+          end
+        end
+
         def instances(credentials, opts={})
           ec2 = new_client(credentials)
           inst_arr = []
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index 64bfa34..81b5a85 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -257,9 +257,12 @@ module Deltacloud::Drivers::VSphere
     # Destroy an instance, given its id. Note that this will destory all
     # instance data.
     def destroy_instance(credentials, id)
+      id = id[:id] if id.class == Hash
       find_vm(credentials, id)[:instance].Destroy_Task.wait_for_completion
     end
 
+    alias :destroy_image :destroy_instance
+
     exceptions do
 
       on /InvalidLogin/ do
diff --git a/server/server.rb b/server/server.rb
index c28ad03..d472dba 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -214,6 +214,20 @@ END
     end
   end
 
+  operation :destroy do
+    description "Remove specified image from collection"
+    with_capability :destroy_image
+    param :id,    :string,    :required
+    control do
+      driver.destroy_image(credentials, :id => params[:id])
+      respond_to do |format|
+        format.xml { status 204 }
+        format.json { status 204 }
+        format.html { redirect(images_url) }
+      end
+    end
+  end
+
 end
 
 collection :instance_states do
diff --git a/server/views/images/show.html.haml b/server/views/images/show.html.haml
index 752952b..9183588 100644
--- a/server/views/images/show.html.haml
+++ b/server/views/images/show.html.haml
@@ -19,3 +19,4 @@
     %dt
     %dd
       = link_to 'Launch', api_url_for("instances/new?image_id=#{@image.id}")
+      = link_to_action 'Destroy', destroy_image_url(@image.id), :delete
-- 
1.7.4.1


Mime
View raw message