You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/07/13 12:04:59 UTC

[PATCH core] Added destroy method for image for VSphere and EC2

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@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


Re: [PATCH core] Added destroy method for image for VSphere and EC2

Posted by Michal Fojtik <mi...@mifo.sk>.
On Jul 13, 2011, at 11:19 PM, David Lutterkort wrote:

> On Wed, 2011-07-13 at 12:04 +0200, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>> 
>> 
>> Signed-off-by: Michal fojtik <mf...@redhat.com>
> 
> ACK. One nit:
> 
>> 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
> 
> We should have one calling convention for this - either always pass in a
> hash or always pass in just the id.

I would prefer to pass a Hash as we do for other operations and we can then
extend it with additional parameter where there will be need to do that in future.

I can do fix for all other drivers if you all agree :)

 -- Michal


Re: [PATCH core] Added destroy method for image for VSphere and EC2

Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-07-13 at 12:04 +0200, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>

ACK. One nit:

> 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

We should have one calling convention for this - either always pass in a
hash or always pass in just the id.

David