deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/7] git commit: CIMI: CIMI Systems - tidy up way that Action resources are performed
Date Mon, 22 Apr 2013 16:35:09 GMT
Updated Branches:
  refs/heads/master 29b551fa1 -> f6f2599df


CIMI: CIMI Systems - tidy up way that Action resources are performed

Signed-off-by: marios <marios@redhat.com>


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

Branch: refs/heads/master
Commit: ac2495e2f690daa7142ae7b2616bd94464ba6722
Parents: a09d8fa
Author: marios <marios@redhat.com>
Authored: Fri Apr 19 16:13:24 2013 +0300
Committer: marios <marios@redhat.com>
Committed: Mon Apr 22 17:52:40 2013 +0300

----------------------------------------------------------------------
 server/lib/cimi/collections/systems.rb |   34 +++++++-------------------
 server/lib/cimi/service/system.rb      |    9 ++++---
 2 files changed, 14 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ac2495e2/server/lib/cimi/collections/systems.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/systems.rb b/server/lib/cimi/collections/systems.rb
index 179daea..e11ed88 100644
--- a/server/lib/cimi/collections/systems.rb
+++ b/server/lib/cimi/collections/systems.rb
@@ -32,7 +32,7 @@ module CIMI::Collections
         control do
           system = System.find(params[:id], self)
           action = Action.parse(self)
-          system.perform(action, self) do |operation|
+          system.perform(action) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
           end
@@ -44,12 +44,8 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read.gsub("restart", "reboot"))
-          else
-            action = Action.from_xml(request.body.read.gsub("restart", "reboot"))
-          end
-          system.perform(action, self) do |operation|
+          action = Action.parse(self)
+          system.perform(action) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
           end
@@ -61,12 +57,8 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
-          system.perform(action, self) do |operation|
+          action = Action.parse(self)
+          system.perform(action) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
           end
@@ -78,12 +70,8 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
-          system.perform(action, self) do |operation|
+          action = Action.parse(self)
+          system.perform(action) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
           end
@@ -95,12 +83,8 @@ module CIMI::Collections
         param :id,          :string,    :required
         control do
           system = System.find(params[:id], self)
-          if  grab_content_type(request.content_type, request.body) == :json
-            action = Action.from_json(request.body.read)
-          else
-            action = Action.from_xml(request.body.read)
-          end
-          system.perform(action, self) do |operation|
+          action = Action.parse(self)
+          system.perform(action) do |operation|
             no_content_with_status(202) if operation.success?
             # Handle errors using operation.failure?
           end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ac2495e2/server/lib/cimi/service/system.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/service/system.rb b/server/lib/cimi/service/system.rb
index daad428..21a8dfe 100644
--- a/server/lib/cimi/service/system.rb
+++ b/server/lib/cimi/service/system.rb
@@ -14,7 +14,6 @@
 # under the License.
 
 class CIMI::Service::System < CIMI::Service::Base
-
   def self.find(id, context)
     if id == :all
       systems = context.driver.systems(context.credentials, {:env=>context})
@@ -25,14 +24,16 @@ class CIMI::Service::System < CIMI::Service::Base
     end
   end
 
-  def perform(action, context, &block)
+  def perform(action, &block)
     begin
-      if context.driver.send(:"#{action.name}_system", context.credentials, self.id.split("/").last)
+      op = action.operation
+      if context.driver.send(:"#{op}_system", context.credentials, ref_id(id))
         block.callback :success
       else
-        raise "Operation failed to execute on given System"
+        raise "Operation #{op} failed to execute on given System #{ref_id(id)}"
       end
     rescue => e
+      raise
       block.callback :failure, e.message
     end
   end


Mime
View raw message