Return-Path: X-Original-To: apmail-deltacloud-commits-archive@www.apache.org Delivered-To: apmail-deltacloud-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 11CAB1069B for ; Mon, 22 Apr 2013 16:35:10 +0000 (UTC) Received: (qmail 6515 invoked by uid 500); 22 Apr 2013 16:35:10 -0000 Delivered-To: apmail-deltacloud-commits-archive@deltacloud.apache.org Received: (qmail 6486 invoked by uid 500); 22 Apr 2013 16:35:09 -0000 Mailing-List: contact commits-help@deltacloud.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@deltacloud.apache.org Delivered-To: mailing list commits@deltacloud.apache.org Received: (qmail 6479 invoked by uid 99); 22 Apr 2013 16:35:09 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 22 Apr 2013 16:35:09 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B595781D828; Mon, 22 Apr 2013 16:35:09 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: marios@apache.org To: commits@deltacloud.apache.org Date: Mon, 22 Apr 2013 16:35:09 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/7] git commit: CIMI: CIMI Systems - tidy up way that Action resources are performed Updated Branches: refs/heads/master 29b551fa1 -> f6f2599df CIMI: CIMI Systems - tidy up way that Action resources are performed Signed-off-by: marios 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 Authored: Fri Apr 19 16:13:24 2013 +0300 Committer: marios 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