From: marios <[email protected]>

Signed-off-by: marios <[email protected]>
---
 server/lib/cimi/collections/volume_images.rb | 22 +++++++++++++++++++++-
 server/lib/cimi/models/volume_image.rb       | 16 ++++++++++++++--
 2 files changed, 35 insertions(+), 3 deletions(-)

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
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)},
-- 
1.7.11.7

Reply via email to