deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/4] git commit: CIMI: Adds create/destroy for volume_image collection+model
Date Wed, 09 Jan 2013 13:58:22 GMT
CIMI: Adds create/destroy for volume_image collection+model


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/657237f5
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/657237f5
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/657237f5

Branch: refs/heads/master
Commit: 657237f538e3fa1e422b6fca1d3f445d13b2ec20
Parents: 12a2543
Author: marios <marios@redhat.com>
Authored: Tue Jan 8 18:55:58 2013 +0200
Committer: marios <marios@redhat.com>
Committed: Wed Jan 9 15:53:45 2013 +0200

----------------------------------------------------------------------
 server/lib/cimi/collections/volume_images.rb |   22 ++++++++++++++++++++-
 server/lib/cimi/models/volume_image.rb       |   16 +++++++++++++-
 2 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/657237f5/server/lib/cimi/collections/volume_images.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volume_images.rb b/server/lib/cimi/collections/volume_images.rb
index 2a7e1af..259a25a 100644
--- a/server/lib/cimi/collections/volume_images.rb
+++ b/server/lib/cimi/collections/volume_images.rb
@@ -42,8 +42,28 @@ module CIMI::Collections
           end
         end
       end
-    end
 
+      operation :create, :with_capability => :create_storage_snapshot do
+        description "Create a new volume image."
+        control do
+          volume_image = CIMI::Model::VolumeImage.create(request.body, self)
+          headers_for_create volume_image
+          respond_to do |format|
+            format.xml { volume_image.to_xml }
+            format.json { volume_image.to_json }
+          end
+        end
+      end
+
+      operation :destroy, :with_capability => :destroy_storage_snapshot do
+        description "Delete a specified VolumeImage"
+        control do
+          CIMI::Model::VolumeImage.delete!(params[:id], self)
+          no_content_with_status 200
+        end
+      end
+
+    end
 
   end
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/657237f5/server/lib/cimi/models/volume_image.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_image.rb b/server/lib/cimi/models/volume_image.rb
index 29f8188..2dc04b5 100644
--- a/server/lib/cimi/models/volume_image.rb
+++ b/server/lib/cimi/models/volume_image.rb
@@ -38,12 +38,24 @@ class CIMI::Model::VolumeImage < CIMI::Model::Base
 
   def self.all(context); find(:all, context); end
 
+  def self.create(request_body, context)
+    type = context.grab_content_type(context.request.content_type, request_body)
+    input = (type == :xml)? XmlSimple.xml_in(request_body.read, {"ForceArray"=>false,"NormaliseSpace"=>2})
: JSON.parse(request_body.read)
+    params = {:volume_id => context.href_id(input["imageLocation"]["href"], :volumes),
:name=>input["name"], :description=>input["description"]}
+    vol_image = context.driver.create_storage_snapshot(context.credentials, params)
+    from_storage_snapshot(vol_image, context)
+  end
+
+  def self.delete!(vol_image_id, context)
+    context.driver.destroy_storage_snapshot(context.credentials, {:id=>vol_image_id})
+  end
+
   private
 
   def self.from_storage_snapshot(snapshot, context)
     self.new( {
-               :name => snapshot.id,
-               :description => snapshot.id,
+               :name => snapshot.name || snapshot.id,
+               :description => snapshot.description || snapshot.id,
                :created => snapshot.created.nil? ? nil : Time.parse(snapshot.created).xmlschema,
                :id => context.volume_image_url(snapshot.id),
                :image_location => {:href=>context.volume_url(snapshot.storage_volume_id)},


Mime
View raw message