You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by lu...@apache.org on 2010/09/21 00:02:36 UTC

svn commit: r999134 - /incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb

Author: lutter
Date: Mon Sep 20 22:02:36 2010
New Revision: 999134

URL: http://svn.apache.org/viewvc?rev=999134&view=rev
Log:
Update the mock driver to properly setup the states.

In particular, make sure we always fill in the "actions"
part of the hash so that we properly create the action
links when fetching an individual instance.

Signed-off-by: Chris Lalancette <cl...@redhat.com>

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb?rev=999134&r1=999133&r2=999134&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb Mon Sep 20 22:02:36 2010
@@ -185,34 +185,28 @@ class MockDriver < Deltacloud::BaseDrive
     Instance.new( instance )
   end
 
-  def start_instance(credentials, id)
+  def update_instance_state(credentials, id, state)
     instance_file = "#{@storage_root}/instances/#{id}.yml"
     instance_yml  = YAML.load( File.read( instance_file ) )
-    instance_yml[:state] = 'RUNNING'
+    instance_yml[:id] = id
+    instance_yml[:state] = state
+    instance_yml[:actions] = instance_actions_for( instance_yml[:state] )
     File.open( instance_file, 'w' ) do |f|
       f << YAML.dump( instance_yml )
     end
     Instance.new( instance_yml )
   end
 
+  def start_instance(credentials, id)
+    update_instance_state(credentials, id, 'RUNNING')
+  end
+
   def reboot_instance(credentials, id)
-    instance_file = "#{@storage_root}/instances/#{id}.yml"
-    instance_yml  = YAML.load( File.read( instance_file ) )
-    instance_yml[:state] = 'RUNNING'
-    File.open( instance_file, 'w' ) do |f|
-      f << YAML.dump( instance_yml )
-    end
-    Instance.new( instance_yml )
+    update_instance_state(credentials, id, 'RUNNING')
   end
 
   def stop_instance(credentials, id)
-    instance_file = "#{@storage_root}/instances/#{id}.yml"
-    instance_yml  = YAML.load( File.read( instance_file ) )
-    instance_yml[:state] = 'STOPPED'
-    File.open( instance_file, 'w' ) do |f|
-      f << YAML.dump( instance_yml )
-    end
-    Instance.new( instance_yml )
+    update_instance_state(credentials, id, 'STOPPED')
   end