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/07/09 01:29:22 UTC

svn commit: r962155 - in /incubator/deltacloud/trunk/server: app/controllers/ app/helpers/ app/views/instance_states/ app/views/layouts/ app/views/root/ config/ lib/deltacloud/ lib/deltacloud/drivers/ec2/ lib/deltacloud/drivers/mock/ lib/deltacloud/dri...

Author: lutter
Date: Thu Jul  8 23:29:21 2010
New Revision: 962155

URL: http://svn.apache.org/viewvc?rev=962155&view=rev
Log:
Correct DeltaCloud to Deltacloud spelling everywhere.
Add literate state-machine definition to BaseDriver.
Adjust all 4 drivers to use the new FSM definition.
Adjust all RESTful representations to extract from FSM config.
Adjust pathing for rhevm_config.yaml.
Adjust extention of rhevm_config.yaml to .yml to conform to other config/ items.

Added:
    incubator/deltacloud/trunk/server/config/.gitignore
    incubator/deltacloud/trunk/server/config/rhevm_config.yml.EXAMPLE
    incubator/deltacloud/trunk/server/lib/deltacloud/state_machine.rb
Modified:
    incubator/deltacloud/trunk/server/app/controllers/instance_states_controller.rb
    incubator/deltacloud/trunk/server/app/helpers/driver_helper.rb
    incubator/deltacloud/trunk/server/app/views/instance_states/show.html.erb
    incubator/deltacloud/trunk/server/app/views/instance_states/show.xml.haml
    incubator/deltacloud/trunk/server/app/views/layouts/application.html.erb
    incubator/deltacloud/trunk/server/app/views/root/index.html.erb
    incubator/deltacloud/trunk/server/config/environment.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/base_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/mock/mock_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb

Modified: incubator/deltacloud/trunk/server/app/controllers/instance_states_controller.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/app/controllers/instance_states_controller.rb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/app/controllers/instance_states_controller.rb (original)
+++ incubator/deltacloud/trunk/server/app/controllers/instance_states_controller.rb Thu Jul  8 23:29:21 2010
@@ -23,7 +23,8 @@ class InstanceStatesController < Applica
   around_filter :catch_auth
 
   def show
-    @states = driver.instance_states()
+    #@states = driver.instance_states()
+    @machine = driver.instance_state_machine()
     respond_to do |format|
       format.html
       format.json

Modified: incubator/deltacloud/trunk/server/app/helpers/driver_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/app/helpers/driver_helper.rb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/app/helpers/driver_helper.rb (original)
+++ incubator/deltacloud/trunk/server/app/helpers/driver_helper.rb Thu Jul  8 23:29:21 2010
@@ -28,7 +28,7 @@ module DriverHelper
   def catch_auth
     begin
       yield
-    rescue DeltaCloud::AuthException => e
+    rescue Deltacloud::AuthException => e
       authenticate_or_request_with_http_basic() do |n,p|
       end
     end

Modified: incubator/deltacloud/trunk/server/app/views/instance_states/show.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/app/views/instance_states/show.html.erb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/app/views/instance_states/show.html.erb (original)
+++ incubator/deltacloud/trunk/server/app/views/instance_states/show.html.erb Thu Jul  8 23:29:21 2010
@@ -13,15 +13,13 @@
       Destination
     </th>
   </tr>
-  <% @states.each do |state| %>
-    <% origin      = state.first %>
-    <% transitions = state.last %>
+  <% @machine.states.each do |state| %>
     <tr>
-      <td rowspan="<%= transitions.empty? ? 2 : transitions.size + 1 %>" class="origin">
-        <%= origin %>
+      <td rowspan="<%= state.transitions.empty? ? 2 : state.transitions.size + 1 %>" class="origin">
+        <%= state %>
       </td>
     </tr>
-    <% if ( transitions.empty? ) %>
+    <% if ( state.transitions.empty? ) %>
       <tr> 
         <td>
           --
@@ -31,17 +29,17 @@
         </td>
       </tr> 
     <% else %>
-      <% transitions.each do |destination, action| %>
+      <% state.transitions.each do |transition| %>
         <tr>
           <td>
-            <% if ( action == :_auto_ ) %>
+            <% if ( transition.automatically? ) %>
               <em>auto</em>
             <% else %>
-              <%= action %>
+              <%= transition.action %>
             <% end %>
           </td>
           <td>
-            <%= destination %>
+            <%= transition.destination %>
           </td>
         </tr>
       <% end %>

Modified: incubator/deltacloud/trunk/server/app/views/instance_states/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/app/views/instance_states/show.xml.haml?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/app/views/instance_states/show.xml.haml (original)
+++ incubator/deltacloud/trunk/server/app/views/instance_states/show.xml.haml Thu Jul  8 23:29:21 2010
@@ -1,8 +1,8 @@
 %states
-  - for state in @states
-    %state{ :name=>state.first }
-      - state.last.each do |destination, action|
-        - if ( action == :_auto_ )
-          %transition{ :to=>destination, :auto=>'true'}
+  - for state in @machine.states
+    %state{ :name=>state }
+      - for transition in state.transitions
+        - if ( transition.automatically? )
+          %transition{ :to=>transition.destination, :auto=>'true'}
         - else
-          %transition{ :to=>destination, :action=>action }
+          %transition{ :to=>transition.destination, :action=>transition.action }

Modified: incubator/deltacloud/trunk/server/app/views/layouts/application.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/app/views/layouts/application.html.erb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/app/views/layouts/application.html.erb (original)
+++ incubator/deltacloud/trunk/server/app/views/layouts/application.html.erb Thu Jul  8 23:29:21 2010
@@ -3,7 +3,7 @@
 
 <html>
   <head>
-    <title>DeltaCloud Framework</title>
+    <title>Deltacloud Foundation</title>
     <%= stylesheet_link_tag '/yui/reset-fonts-grids/reset-fonts-grids.css' %>
     <%= stylesheet_link_tag 'application.css' %>
   </head>
@@ -22,7 +22,7 @@
       </div>
       <div id="ft">
         <div style="float: right; text-align: right; font-size: 90%;">
-          DeltaCloud Driver: <%= DRIVER %><br/>
+          Driver <%= DRIVER %><br/>
           Copyright 2009 <%= link_to 'Red Hat', 'http://redhat.com' %> <br />
         </div>
       </div>

Modified: incubator/deltacloud/trunk/server/app/views/root/index.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/app/views/root/index.html.erb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/app/views/root/index.html.erb (original)
+++ incubator/deltacloud/trunk/server/app/views/root/index.html.erb Thu Jul  8 23:29:21 2010
@@ -1,5 +1,5 @@
 
-<!-- <h1>&#x3B4;-cloud-framework</h1> -->
-<h1>DeltaCloud: <%= DRIVER.to_s.titlecase %></h1>
+<!-- <h1>&#x3B4;-cloud-foundation</h1> -->
+<h1>Deltacloud: <%= DRIVER.to_s.titlecase %></h1>
 
 <%= link_to 'API', api_url %>

Added: incubator/deltacloud/trunk/server/config/.gitignore
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/config/.gitignore?rev=962155&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/config/.gitignore (added)
+++ incubator/deltacloud/trunk/server/config/.gitignore Thu Jul  8 23:29:21 2010
@@ -0,0 +1 @@
+rhevm_config.yml

Modified: incubator/deltacloud/trunk/server/config/environment.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/config/environment.rb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/config/environment.rb (original)
+++ incubator/deltacloud/trunk/server/config/environment.rb Thu Jul  8 23:29:21 2010
@@ -92,7 +92,7 @@ $: << DRIVER_ROOT+'/lib'
 
 case DRIVER
   when :mock
-    DRIVER_CLASS_NAME = "Deltacloud::Drivers::MockDriver"
+    DRIVER_CLASS_NAME = "Deltacloud::Drivers::Mock::MockDriver"
     MOCK_STORAGE_ROOT = File.dirname( __FILE__ ) + "/../../client-ruby/specs/data"
   when :ec2
     DRIVER_CLASS_NAME = "Deltacloud::Drivers::EC2::EC2Driver"

Added: incubator/deltacloud/trunk/server/config/rhevm_config.yml.EXAMPLE
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/config/rhevm_config.yml.EXAMPLE?rev=962155&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/config/rhevm_config.yml.EXAMPLE (added)
+++ incubator/deltacloud/trunk/server/config/rhevm_config.yml.EXAMPLE Thu Jul  8 23:29:21 2010
@@ -0,0 +1 @@
+domain: demo
\ No newline at end of file

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/base_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/base_driver.rb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/base_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/base_driver.rb Thu Jul  8 23:29:21 2010
@@ -16,17 +16,26 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 
-module DeltaCloud
+module Deltacloud
 
   class AuthException < Exception
   end
 
   class BaseDriver
 
-    def instance_states()
-      []
+    def self.define_instance_states(&block)
+      machine = ::Deltacloud::StateMachine.new(&block)
+      @instance_state_machine = machine
+    end
+
+    def self.instance_state_machine
+      @instance_state_machine
     end
 
+    def instance_state_machine
+      self.class.instance_state_machine
+    end
+    
     def instance_actions_for(state)
       actions = []
       state_key = state.downcase.to_sym

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/ec2/ec2_driver.rb Thu Jul  8 23:29:21 2010
@@ -22,7 +22,7 @@ require 'right_aws'
 module Deltacloud
   module Drivers
     module EC2
-class EC2Driver < DeltaCloud::BaseDriver
+class EC2Driver < Deltacloud::BaseDriver
 
   #
   # Flavors
@@ -60,28 +60,17 @@ class EC2Driver < DeltaCloud::BaseDriver
     } ),
   ]
 
-  INSTANCE_STATES = [
-    [ :begin, { 
-        :pending=>:create,
-    } ],
-    [ :pending, { 
-        :running=>:_auto_,
-        :stopped=>:stop, 
-    } ],
-    [ :running, { 
-        :running=>:reboot, 
-        :shutting_down=>:stop,
-    } ],
-    [ :shutting_down, { 
-        :stopped=>:_auto_,
-    } ],
-    [ :stopped, {
-        :end=>:_auto_,
-    } ],
-  ]
+  define_instance_states do
+    start.to( :pending )         .automatically
+
+    pending.to( :running )       .automatically
+    pending.to( :stopped )       .on( :stop )
+
+    running.to( :running )       .on( :reboot )
+    running.to( :shutting_down ) .on( :stop )
 
-  def instance_states()
-    INSTANCE_STATES 
+    shutting_down.to( :stopped ) .automatically
+    stopped.to( :finish )        .automatically
   end
 
   def flavors(credentials, opts=nil)
@@ -249,7 +238,7 @@ class EC2Driver < DeltaCloud::BaseDriver
 
   def new_client(credentials)
     if ( credentials[:name].nil? || credentials[:password].nil? || credentials[:name] == '' || credentials[:password] == '' )
-      raise DeltaCloud::AuthException.new
+      raise Deltacloud::AuthException.new
     end
     RightAws::Ec2.new(credentials[:name], credentials[:password], :cache=>false )
   end
@@ -316,9 +305,9 @@ class EC2Driver < DeltaCloud::BaseDriver
       block.call
     rescue RightAws::AwsError => e
       if ( e.include?( /SignatureDoesNotMatch/ ) )
-        raise DeltaCloud::AuthException.new
+        raise Deltacloud::AuthException.new
       elsif ( e.include?( /InvalidClientTokenId/ ) )
-        raise DeltaCloud::AuthException.new
+        raise Deltacloud::AuthException.new
       else
         e.errors.each do |error|
           puts "ERROR #{error.inspect}"

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=962155&r1=962154&r2=962155&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 Thu Jul  8 23:29:21 2010
@@ -21,7 +21,7 @@ require 'deltacloud/base_driver'
 module Deltacloud
   module Drivers
     module Mock
-class MockDriver < DeltaCloud::BaseDriver
+class MockDriver < Deltacloud::BaseDriver
 
   ( STORAGE_ROOT = MOCK_STORAGE_ROOT ) unless defined?( STORAGE_ROOT )
 
@@ -77,26 +77,16 @@ class MockDriver < DeltaCloud::BaseDrive
     }),
   ] ) unless defined?( REALMS )
 
-  ( INSTANCE_STATES = [
-    [ :begin, {
-       :pending=>:create
-     } ],
-    [ :pending, {
-       :running=>:_auto_
-     } ],
-     [ :running, {
-       :running=>:reboot,
-       :stopped=>:stop
-     } ],
-     [ :stopped, {
-       :running=>:start,
-       :end=>:destroy
-     } ],
-  ] ) unless defined?( STATES )
+  define_instance_states do
+    start.to( :pending )       .on( :create )
 
+    pending.to( :running )     .automatically
 
-  def instance_states()
-    return INSTANCE_STATES
+    running.to( :running )     .on( :reboot )
+    running.to( :stopped )     .on( :stop )
+
+    stopped.to( :running )     .on( :start )
+    stopped.to( :finish )      .on( :destroy )
   end
 
   def flavors(credentials, opts=nil)
@@ -272,11 +262,11 @@ class MockDriver < DeltaCloud::BaseDrive
 
   def check_credentials(credentials)
     if ( credentials[:name] != 'mockuser' )
-      raise DeltaCloud::AuthException.new
+      raise Deltacloud::AuthException.new
     end
 
     if ( credentials[:password] != 'mockpassword' )
-      raise DeltaCloud::AuthException.new
+      raise Deltacloud::AuthException.new
     end
   end
 

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb Thu Jul  8 23:29:21 2010
@@ -16,13 +16,13 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
 require 'deltacloud/base_driver'
-require 'rackspace_client'
+require 'deltacloud/drivers/rackspace/rackspace_client'
 
 module Deltacloud
   module Drivers
     module Rackspace
 
-class RackspaceDriver < DeltaCloud::BaseDriver
+class RackspaceDriver < Deltacloud::BaseDriver
 
   def flavors(credentials, opts=nil)
     racks = new_client( credentials )
@@ -128,38 +128,23 @@ class RackspaceDriver < DeltaCloud::Base
 
   def new_client(credentials)
     if ( credentials[:name].nil? || credentials[:password].nil? || credentials[:name] == '' || credentials[:password] == '' )
-      raise DeltaCloud::AuthException.new
+      raise Deltacloud::AuthException.new
     end
     RackspaceClient.new(credentials[:name], credentials[:password])
   end
 
-  @@INSTANCE_STATES = [
-    [ :begin, { 
-        :pending=>:create,
-    } ],
-    [ :pending, { 
-        :running=>:_auto_, 
-    } ],
-    [ :running, { 
-        :running=>:reboot, 
-        :shutting_down=>:stop
-    } ],
-    [ :shutting_down, { 
-        :stopped=>:_auto_,
-    } ],
-    [ :stopped, {
-        :end=>:_auto_,
-    } ],
-  ]
-
-  def instance_states()
-    @@INSTANCE_STATES 
-  end
+  define_instance_states do 
+    start.to( :pending )          .on( :create )
+
+    pending.to( :running )        .automatically
 
+    running.to( :running )        .on( :reboot )
+    running.to( :shutting_down )  .on( :stop )
 
-#PENDING
-#STOPPED
-#RUNNING
+    shutting_down.to( :stopped )  .automatically
+
+    stopped.to( :finish )         .automatically
+  end
 
 end
 

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb?rev=962155&r1=962154&r2=962155&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb Thu Jul  8 23:29:21 2010
@@ -22,10 +22,10 @@ module Deltacloud
   module Drivers
     module RHEVM
 
-class RHEVMDriver < DeltaCloud::BaseDriver
+class RHEVMDriver < Deltacloud::BaseDriver
 
   SCRIPT_DIR = File.dirname(__FILE__) + '/../scripts'
-  CONFIG = YAML.load_file(File.dirname(__FILE__) + '/../config/rhevm_config.yaml')
+  CONFIG = YAML.load_file(RAILS_ROOT + '/config/rhevm_config.yml')
   SCRIPT_DIR_ARG = '"' + SCRIPT_DIR + '"'
   DELIM_BEGIN="<_OUTPUT>"
   DELIM_END="</_OUTPUT>"
@@ -60,7 +60,7 @@ class RHEVMDriver < DeltaCloud::BaseDriv
 
   def genArgString(credentials, args)
     if ( credentials[:name].nil? || credentials[:password].nil? || credentials[:name] == '' || credentials[:password] == '' )
-      raise DeltaCloud::AuthException.new
+      raise Deltacloud::AuthException.new
     end
     puts CONFIG["domain"]
     commonArgs = [SCRIPT_DIR_ARG, credentials[:name], credentials[:password], CONFIG["domain"]]
@@ -166,26 +166,19 @@ class RHEVMDriver < DeltaCloud::BaseDriv
   #
   # Instances
   #
-
-  STATE_ACTIONS = [
-    [ :begin, {
-        :stopped => :create}],
-    [ :pending, {
-        :shutting_down=>:stop,
-        :running=>:_auto_ } ],
-    [ :running, {
-        :pending=>:reboot,
-        :shutting_down=>:stop } ],
-    [ :shutting_down, {
-        :stopped=>:_auto_ } ],
-    [ :stopped, {
-        :pending=>:start,
-        :end=>:destroy }],
-  ]
-
-
-  def instance_states()
-    STATE_ACTIONS
+  
+  define_instance_states do
+    start.to(:stopped)            .on( :create )
+
+    pending.to(:shutting_down)    .on( :stop )
+    pending.to(:running)          .automatically
+
+    running.to(:pending)          .on( :reboot )
+    running.to(:shutting_down)    .on( :stop )
+
+    shutting_down.to(:stopped)    .automatically
+    stopped.to(:pending)          .on( :start )
+    stopped.to(:finish)           .on( :destroy )
   end
 
   def instances(credentials, opts=nil)

Added: incubator/deltacloud/trunk/server/lib/deltacloud/state_machine.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/state_machine.rb?rev=962155&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/state_machine.rb (added)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/state_machine.rb Thu Jul  8 23:29:21 2010
@@ -0,0 +1,84 @@
+
+module Deltacloud
+  class StateMachine
+
+    attr_reader :states
+    def initialize(&block)
+      @states  = []
+      instance_eval &block if block
+    end
+
+    def start()
+      state(:start)
+    end
+
+    def finish()
+      state(:finish)
+    end
+
+    def state(name)
+      state = @states.find{|e| e.name == name.to_sym}
+      if ( state.nil? )
+        state = State.new( self, name.to_sym )
+        @states << state
+      end
+      state
+    end
+
+    def method_missing(sym,*args)
+      return state( sym ) if ( args.empty? )
+      super( sym, *args )  
+    end
+
+    class State
+
+      attr_reader :name
+      attr_reader :transitions
+
+      def initialize(machine, name)
+        @machine = machine
+        @name    = name
+        @transitions = []
+      end
+     
+      def to_s
+        self.name.to_s
+      end
+
+      def to(destination_name)
+        destination = @machine.state(destination_name) 
+        transition = Transition.new( @machine, destination )
+        @transitions << transition
+        transition
+      end
+
+    end
+
+    class Transition
+
+      attr_reader :destination
+      attr_reader :action
+
+      def initialize(machine, destination)
+        @machine = machine
+        @destination = destination
+        @auto   = false
+        @action = nil
+      end
+
+      def automatically
+        @auto = true
+      end
+
+      def automatically?
+        @auto
+      end
+
+      def on(action)
+        @action = action
+      end
+    
+    end
+
+  end
+end