deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject [1/2] git commit: Instance states: settle on fixed set of possible states/actions
Date Thu, 05 Apr 2012 20:53:01 GMT
Updated Branches:
  refs/heads/master 452ca54f2 -> 09bfd939d


Instance states: settle on fixed set of possible states/actions

We now enforce that each driver only uses instance states and actions that
come from the approved list of such entities. This helps guard against
simple mistakes in writing drivers.


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

Branch: refs/heads/master
Commit: 09bfd939db278978d87539534ceda3465737acc3
Parents: 546fd64
Author: David Lutterkort <lutter@redhat.com>
Authored: Thu Mar 1 15:56:43 2012 -0800
Committer: David Lutterkort <lutter@redhat.com>
Committed: Thu Apr 5 13:52:17 2012 -0700

----------------------------------------------------------------------
 server/lib/deltacloud/base_driver/base_driver.rb   |    7 +++++-
 .../lib/deltacloud/drivers/condor/condor_driver.rb |    2 +-
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    3 +-
 .../drivers/opennebula/opennebula_driver.rb        |    4 +-
 .../drivers/openstack/openstack_driver.rb          |    4 +-
 .../drivers/rackspace/rackspace_driver.rb          |    4 +-
 .../drivers/rimuhosting/rimuhosting_driver.rb      |    4 +-
 .../drivers/terremark/terremark_driver.rb          |    4 +-
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |    4 +-
 server/lib/deltacloud/state_machine.rb             |   18 ++++++++++++++-
 site/content/api.mdown                             |    6 ++--
 site/content/developers.mdown                      |    6 ++--
 12 files changed, 44 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/base_driver/base_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
index dcc3b9a..01dd5e7 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -22,6 +22,11 @@ module Deltacloud
 
     include ExceptionHandler
 
+    STATE_MACHINE_OPTS = {
+      :all_states => [:start, :pending, :running, :stopping, :stopped, :finish],
+      :all_actions => [:create, :reboot, :stop, :start, :destroy]
+    }
+
     def name
       self.class.name.split('::').last.gsub('Driver', '').downcase
     end
@@ -90,7 +95,7 @@ module Deltacloud
     end
 
     def self.define_instance_states(&block)
-      machine = ::Deltacloud::StateMachine.new(&block)
+      machine = ::Deltacloud::StateMachine.new(STATE_MACHINE_OPTS, &block)
       @instance_state_machine = machine
     end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/condor/condor_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/condor/condor_driver.rb b/server/lib/deltacloud/drivers/condor/condor_driver.rb
index f48c9d3..f5cb741 100644
--- a/server/lib/deltacloud/drivers/condor/condor_driver.rb
+++ b/server/lib/deltacloud/drivers/condor/condor_driver.rb
@@ -175,7 +175,7 @@ module Deltacloud
           pending.to( :running )        .automatically
           pending.to( :finish )         .on(:destroy)
           running.to( :running )        .on( :reboot )
-          running.to( :shutting_down )  .on( :destroy )
+          running.to( :stopping )       .on( :destroy )
           pending.to( :finish )         .automatically
         end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 7b1cc8c..60e86e8 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -127,7 +127,8 @@ module Deltacloud
           stopped.to( :running )        .on( :start )
           running.to( :running )        .on( :reboot )
           running.to( :stopping )       .on( :stop )
-          shutting_down.to( :stopped )  .automatically
+          stopping.to(:stopped)         .automatically
+          stopping.to(:finish)          .automatically
           stopped.to( :finish )         .automatically
         end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
index 3ffdd12..371e170 100644
--- a/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
+++ b/server/lib/deltacloud/drivers/opennebula/opennebula_driver.rb
@@ -152,8 +152,8 @@ class OpennebulaDriver < Deltacloud::BaseDriver
     running.to(:running)        .on( :reboot )
     running.to(:stopping)       .on( :stop )
     stopping.to(:stopped)       .automatically
-    running.to(:shutting_down)  .on( :destroy )
-    shutting_down.to(:finish)   .automatically
+    running.to(:stopping)       .on( :destroy )
+    stopping.to(:finish)        .automatically
   end
 
   def instances(credentials, opts=nil)

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
index 4c768c9..c9ec95b 100644
--- a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
+++ b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
@@ -35,8 +35,8 @@ module Deltacloud
           start.to( :pending )          .on( :create )
           pending.to( :running )        .automatically
           running.to( :running )        .on( :reboot )
-          running.to( :shutting_down )  .on( :stop )
-          shutting_down.to( :stopped )  .automatically
+          running.to( :stopping )       .on( :stop )
+          stopping.to( :stopped )       .automatically
           stopped.to( :finish )         .automatically
         end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index feaa646..1b019d4 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -194,8 +194,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
     start.to( :pending )          .on( :create )
     pending.to( :running )        .automatically
     running.to( :running )        .on( :reboot )
-    running.to( :shutting_down )  .on( :stop )
-    shutting_down.to( :stopped )  .automatically
+    running.to( :stopping )       .on( :stop )
+    stopping.to( :stopped )       .automatically
     stopped.to( :finish )         .automatically
   end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
index 6b61b8c..67c415c 100644
--- a/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
+++ b/server/lib/deltacloud/drivers/rimuhosting/rimuhosting_driver.rb
@@ -142,9 +142,9 @@ class RimuHostingDriver < Deltacloud::BaseDriver
     pending.to( :running )        .automatically
 
     running.to( :running )        .on(:reboot)
-    running.to( :shutting_down )  .on(:stop)
+    running.to( :stopping )       .on(:stop)
 
-    shutting_down.to( :stopped )  .automatically
+    stopping.to( :stopped )       .automatically
 
     stopped.to( :finish )         .automatically
   end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
index da58364..2dba02a 100644
--- a/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
+++ b/server/lib/deltacloud/drivers/terremark/terremark_driver.rb
@@ -118,8 +118,8 @@ VAPP_STATE_MAP = { "0" =>  "PENDING", "1" =>  "PENDING", "2" =>
 "STOPPED", "4"
     pending.to(:stopped)          .automatically
     stopped.to(:running)          .on( :start )
     running.to(:running)          .on( :reboot )
-    running.to(:shutting_down)    .on( :stop )
-    shutting_down.to(:stopped)    .automatically
+    running.to(:stopping)         .on( :stop )
+    stopping.to(:stopped)         .automatically
     stopped.to(:finish)           .on( :destroy )
    end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index fdacc10..e16be2f 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -68,8 +68,8 @@ module Deltacloud::Drivers::VSphere
       pending.to(:stopped)        .automatically
       stopped.to(:running)        .on( :start )
       running.to(:running)        .on( :reboot )
-      running.to(:shutting_down)  .on( :stop )
-      shutting_down.to(:stopped)  .automatically
+      running.to(:stopping)       .on( :stop )
+      stopping.to(:stopped)       .automatically
       stopped.to(:finish)         .on( :destroy )
     end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/server/lib/deltacloud/state_machine.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/state_machine.rb b/server/lib/deltacloud/state_machine.rb
index 19fb9f2..facd4ba 100644
--- a/server/lib/deltacloud/state_machine.rb
+++ b/server/lib/deltacloud/state_machine.rb
@@ -18,7 +18,9 @@ module Deltacloud
   class StateMachine
 
     attr_reader :states
-    def initialize(&block)
+    def initialize(opts = {}, &block)
+      @all_states = opts[:all_states]
+      @all_actions = opts[:all_actions]
       @states  = []
       instance_eval &block if block
     end
@@ -32,6 +34,9 @@ module Deltacloud
     end
 
     def state(name)
+      unless valid_state_name?(name)
+        raise "State '#{name}' not in list of allowed states"
+      end
       state = @states.find{|e| e.name == name.to_sym}
       if ( state.nil? )
         state = State.new( self, name.to_sym )
@@ -40,6 +45,14 @@ module Deltacloud
       state
     end
 
+    def valid_state_name?(name)
+      @all_states.nil? || @all_states.include?(name.to_sym)
+    end
+
+    def valid_action_name?(name)
+      @all_actions.nil? || @all_actions.include?(name.to_sym)
+    end
+
     def method_missing(sym,*args)
       return state( sym ) if ( args.empty? )
       super( sym, *args )
@@ -90,6 +103,9 @@ module Deltacloud
       end
 
       def on(action)
+        unless @machine.valid_action_name?(action)
+          raise "Action '#{action}' not in list of allowed actions"
+        end
         @action = action
       end
 

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/site/content/api.mdown
----------------------------------------------------------------------
diff --git a/site/content/api.mdown b/site/content/api.mdown
index eb0114e..8ce2db3 100644
--- a/site/content/api.mdown
+++ b/site/content/api.mdown
@@ -59,7 +59,7 @@ Each Image defines the root partition and initial storage for the Instance
opera
 ##### Instance States
 
 These represent the Instance lifecycle; at any time an Instance will be in one of
- *start, pending, running, stopped, shutting_down, finished*.
+ *start, pending, running, stopped, stopping, finished*.
 
 ##### Keys
 
@@ -929,9 +929,9 @@ machine for ***instances*** from the given cloud.
       </state>
       <state name='running'>
         <transition action='reboot' to='running'></transition>
-        <transition action='stop' to='shutting_down'></transition>
+        <transition action='stop' to='stopping'></transition>
       </state>
-      <state name='shutting_down'>
+      <state name='stopping'>
         <transition auto='true' to='stopped'></transition>
       </state>
       <state name='stopped'>

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/09bfd939/site/content/developers.mdown
----------------------------------------------------------------------
diff --git a/site/content/developers.mdown b/site/content/developers.mdown
index d5ea697..946ea47 100644
--- a/site/content/developers.mdown
+++ b/site/content/developers.mdown
@@ -419,8 +419,8 @@ look like is:
       start.to( :pending )          .on( :create )
       pending.to( :running )        .automatically
       running.to( :running )        .on( :reboot )
-      running.to( :shutting_down )  .on( :stop )
-      shutting_down.to( :stopped )  .automatically
+      running.to( :stopping )  .on( :stop )
+      stopping.to( :stopped )  .automatically
       stopped.to( :finish )         .automatically
     end
 
@@ -432,7 +432,7 @@ Valid states are
 - **`:begin`**
 - **`:pending`**
 - **`:running`**
-- **`:shutting_down`**
+- **`:stopping`**
 - **`:stopped`**
 - **`:end`**
 


Mime
View raw message