deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [1/11] git commit: CIMI: Adds VSP status change methods and mock driver implementation
Date Wed, 11 Apr 2012 15:33:08 GMT
Updated Branches:
  refs/heads/master 124b2d058 -> 84d3c9909


CIMI: Adds VSP status change methods and mock driver implementation


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

Branch: refs/heads/master
Commit: 88cf41a02f8224140426bb3532d87ccb366b9b02
Parents: 3242e16
Author: marios <marios@redhat.com>
Authored: Fri Apr 6 13:18:39 2012 +0300
Committer: marios <marios@redhat.com>
Committed: Wed Apr 11 18:32:08 2012 +0300

----------------------------------------------------------------------
 server/lib/cimi/model/vsp.rb                       |   13 +++++
 server/lib/cimi/server.rb                          |   36 +++++++++++++++
 .../drivers/mock/mock_driver_cimi_methods.rb       |   28 ++++++++---
 3 files changed, 69 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/88cf41a0/server/lib/cimi/model/vsp.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/model/vsp.rb b/server/lib/cimi/model/vsp.rb
index 9507dd5..40a526f 100644
--- a/server/lib/cimi/model/vsp.rb
+++ b/server/lib/cimi/model/vsp.rb
@@ -68,6 +68,19 @@ class CIMI::Model::VSP < CIMI::Model::Base
     context.driver.delete_vsp(context.credentials, id)
   end
 
+  def perform(action, context, &block)
+    begin
+      if context.driver.send(:"#{action.name}_vsp", context.credentials, self.name)
+        block.callback :success
+      else
+        raise "Operation #{action.name} failed to execute on the VSP #{self.name} "
+      end
+    rescue => e
+      block.callback :failure, e.message
+    end
+  end
+
+
   private
 
   def self.get_by_reference(input, context)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/88cf41a0/server/lib/cimi/server.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index 63523ba..60f9a3b 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -774,6 +774,42 @@ global_collection :vsps do
     end
   end
 
+  operation :start, :method => :post, :member => true do
+    description "Start specific VSP."
+    param :id,          :string,    :required
+    control do
+      vsp = VSP.find(params[:id], self)
+      report_error(404) unless vsp
+      if request.content_type.end_with?("json")
+        action = Action.from_json(request.body.read)
+      else
+        action = Action.from_xml(request.body.read)
+      end
+      vsp.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 VSP."
+    param :id,          :string,    :required
+    control do
+      vsp = VSP.find(params[:id], self)
+      report_error(404) unless vsp
+      if request.content_type.end_with?("json")
+        action = Action.from_json(request.body.read)
+      else
+        action = Action.from_xml(request.body.read)
+      end
+      vsp.perform(action, self) do |operation|
+        no_content_with_status(202) if operation.success?
+        # Handle errors using operation.failure?
+      end
+    end
+  end
+
 end
 
 global_collection :vsp_configurations do

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/88cf41a0/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
index fdd501a..2dec66b 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver_cimi_methods.rb
@@ -62,17 +62,17 @@ module Deltacloud::Drivers::Mock
 
     def start_network(credentials, id)
       check_credentials(credentials)
-      update_network_state(id, "STARTED")
+      update_object_state(id, "Network", "STARTED")
     end
 
     def stop_network(credentials, id)
       check_credentials(credentials)
-      update_network_state(id, "STOPPED")
+      update_object_state(id, "Network", "STOPPED")
     end
 
     def suspend_network(credentials, id)
       check_credentials(credentials)
-      update_network_state(id, "SUSPENDED")
+      update_object_state(id, "Network", "SUSPENDED")
     end
 
     def network_configurations(credentials, opts={})
@@ -152,6 +152,16 @@ module Deltacloud::Drivers::Mock
       vsp
     end
 
+    def start_vsp(credentials, id)
+      check_credentials(credentials)
+      update_object_state(id, "VSP", "STARTED")
+    end
+
+    def stop_vsp(credentials, id)
+      check_credentials(credentials)
+      update_object_state(id, "VSP", "STOPPED")
+    end
+
     def delete_vsp(credentials, id)
       check_credentials(credentials)
       @client.destroy_cimi(:vsp, id)
@@ -260,11 +270,13 @@ module Deltacloud::Drivers::Mock
       end
     end
 
-    def update_network_state(id, new_state)
-      network = CIMI::Model::Network.from_json(@client.load_cimi(:network, id))
-      network.state = new_state
-      @client.store_cimi(:network, network)
-      network
+    def update_object_state(id, object, new_state)
+      klass = CIMI::Model.const_get("#{object}")
+      symbol = object.to_s.downcase.singularize.intern
+      obj = klass.from_json(@client.load_cimi(symbol, id))
+      obj.state = new_state
+      @client.store_cimi(symbol, obj)
+      obj
     end
 
   end


Mime
View raw message