From: marios <[email protected]>
Signed-off-by: marios <[email protected]> --- 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(-) 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 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 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 -- 1.7.6.5
