deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [4/11] git commit: CIMI: Adds status change actions for CIMI::Network to server and Network model
Date Wed, 11 Apr 2012 15:33:08 GMT
CIMI: Adds status change actions for CIMI::Network to server and Network model


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

Branch: refs/heads/master
Commit: a96745c9119222a3a9fff1e7a3999eb613216139
Parents: 2a47c78
Author: marios <marios@redhat.com>
Authored: Mon Apr 2 14:01:27 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Wed Apr 11 18:32:07 2012 +0300

----------------------------------------------------------------------
 server/lib/cimi/model/action.rb  |    2 +-
 server/lib/cimi/model/network.rb |   13 ++++++-
 server/lib/cimi/server.rb        |   56 ++++++++++++++++++++++++++++++++-
 3 files changed, 67 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a96745c9/server/lib/cimi/model/action.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/model/action.rb b/server/lib/cimi/model/action.rb
index 627e673..c1c9908 100644
--- a/server/lib/cimi/model/action.rb
+++ b/server/lib/cimi/model/action.rb
@@ -18,7 +18,7 @@ class CIMI::Model::Action < CIMI::Model::Base
   text :action
 
   def name
-    action.split('/').last.intern
+    action.split('/').last.strip.intern
   end
 
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a96745c9/server/lib/cimi/model/network.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/model/network.rb b/server/lib/cimi/model/network.rb
index 8ecc8a1..cf03412 100644
--- a/server/lib/cimi/model/network.rb
+++ b/server/lib/cimi/model/network.rb
@@ -72,8 +72,17 @@ class CIMI::Model::Network < CIMI::Model::Base
     context.driver.delete_network(context.credentials, id)
   end
 
-#FIXME
-#actions - needs method(s) to facilitate stop/start/suspend/delete
+  def perform(action, context, &block)
+    begin
+      if context.driver.send(:"#{action.name}_network", context.credentials, self.name)
+        block.callback :success
+      else
+        raise "Operation #{action.name} failed to execute on the Network #{self.name} "
+      end
+    rescue => e
+      block.callback :failure, e.message
+    end
+  end
 
   private
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a96745c9/server/lib/cimi/server.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index c58bf87..7ba18d1 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -523,7 +523,7 @@ global_collection :networks do
   operation :create do
     description "Create a new Network"
     control do
-      if request.content_type.end_with?("+json")
+      if request.content_type.end_with?("json")
         network = Network.create(request.body.read, self, :json)
       else
         network = Network.create(request.body.read, self, :xml)
@@ -544,6 +544,60 @@ global_collection :networks do
     end
   end
 
+  operation :start, :method => :post, :member => true do
+    description "Start specific network."
+    param :id,          :string,    :required
+    control do
+      network = Network.find(params[:id], self)
+      report_error(404) unless network
+      if request.content_type.end_with?("json")
+        action = Action.from_json(request.body.read)
+      else
+        action = Action.from_xml(request.body.read)
+      end
+      network.perform(action, self) do |operation|
+        no_content_with_status(202) if operation.success?
+        # Handle errors using operation.failure?
+      end
+    end
+  end
+
+  operation :stop, :method => :post, :member => true do
+    description "Stop specific network."
+    param :id,          :string,    :required
+    control do
+      network = Network.find(params[:id], self)
+      report_error(404) unless network
+      if request.content_type.end_with?("json")
+        action = Action.from_json(request.body.read)
+      else
+        action = Action.from_xml(request.body.read)
+      end
+      network.perform(action, self) do |operation|
+        no_content_with_status(202) if operation.success?
+        # Handle errors using operation.failure?
+      end
+    end
+  end
+
+  operation :suspend, :method => :post, :member => true do
+    description "Suspend specific network."
+    param :id,          :string,    :required
+    control do
+      network = Network.find(params[:id], self)
+      report_error(404) unless network
+      if request.content_type.end_with?("json")
+        action = Action.from_json(request.body.read)
+      else
+        action = Action.from_xml(request.body.read)
+      end
+      network.perform(action, self) do |operation|
+        no_content_with_status(202) if operation.success?
+        # Handle errors using operation.failure?
+      end
+    end
+  end
+
 end
 
 global_collection :network_configurations do


Mime
View raw message