deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [2/2] git commit: CIMI: adds create_image (from a running server) + delete
Date Fri, 21 Dec 2012 10:03:05 GMT
CIMI: adds create_image (from a running server) + delete


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

Branch: refs/heads/master
Commit: d1dc608152ef78ebd5a48b788510f527a3ae2f16
Parents: 2084b6b
Author: marios <marios@redhat.com>
Authored: Fri Dec 21 11:59:36 2012 +0200
Committer: marios <marios@redhat.com>
Committed: Fri Dec 21 11:59:36 2012 +0200

----------------------------------------------------------------------
 server/lib/cimi/collections/machine_images.rb |   20 ++++++++++++++++++++
 server/lib/cimi/models/machine_image.rb       |   12 ++++++++++++
 2 files changed, 32 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d1dc6081/server/lib/cimi/collections/machine_images.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/machine_images.rb b/server/lib/cimi/collections/machine_images.rb
index 822a7d5..bafea80 100644
--- a/server/lib/cimi/collections/machine_images.rb
+++ b/server/lib/cimi/collections/machine_images.rb
@@ -43,6 +43,26 @@ module CIMI::Collections
         end
       end
 
+      operation :create, :with_capability => :create_image do
+        description "Create a new machine image."
+        control do
+          machine_image = CIMI::Model::MachineImage.create(request.body, self)
+          headers_for_create machine_image
+          respond_to do |format|
+            format.xml { machine_image.to_xml }
+            format.json { machine_image.to_json }
+          end
+        end
+      end
+
+      operation :destroy, :with_capability => :destroy_image do
+        description "Delete a specified MachineImage"
+        control do
+          CIMI::Model::MachineImage.delete!(params[:id], self)
+          no_content_with_status 200
+        end
+      end
+
     end
 
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/d1dc6081/server/lib/cimi/models/machine_image.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/machine_image.rb b/server/lib/cimi/models/machine_image.rb
index 6034e5b..b10ef7e 100644
--- a/server/lib/cimi/models/machine_image.rb
+++ b/server/lib/cimi/models/machine_image.rb
@@ -49,4 +49,16 @@ class CIMI::Model::MachineImage < CIMI::Model::Base
     )
   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 = {:id => context.href_id(input["imageLocation"], :machines), :name=>input["name"],
:description=>input["description"]}
+    image = context.driver.create_image(context.credentials, params)
+    from_image(image, context)
+  end
+
+  def self.delete!(image_id, context)
+    context.driver.destroy_image(context.credentials, image_id)
+  end
+
 end


Mime
View raw message