incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962184 - in /incubator/deltacloud/trunk/server/libexec: deltacloud.rb drivers.rb lib/deltacloud/helpers.rb lib/deltacloud/helpers/driver_helper.rb lib/deltacloud/helpers/url_helper.rb
Date Thu, 08 Jul 2010 23:34:46 GMT
Author: lutter
Date: Thu Jul  8 23:34:45 2010
New Revision: 962184

URL: http://svn.apache.org/viewvc?rev=962184&view=rev
Log:
Load current drivers

  * deltacloud.rb: add lib/ to load path
  * drivers.rb: catalog of known drivers
  * lib/deltacloud/helpers.rb: load helpers
  * lib/deltacloud/helpers/driver_helper.rb: load current driver
  * lib/deltacloud/helpers/url_helper.rb: helpers for Rails-like URL
    generation

Added:
    incubator/deltacloud/trunk/server/libexec/deltacloud.rb
    incubator/deltacloud/trunk/server/libexec/drivers.rb
    incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers.rb
    incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/url_helper.rb
Modified:
    incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/driver_helper.rb

Added: incubator/deltacloud/trunk/server/libexec/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/deltacloud.rb?rev=962184&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/deltacloud.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/deltacloud.rb Thu Jul  8 23:34:45 2010
@@ -0,0 +1,16 @@
+# Add ./lib into load path
+$:.unshift File.join(File.dirname(__FILE__), 'lib')
+
+require 'deltacloud/base_driver'
+require 'deltacloud/hardware_profile'
+require 'deltacloud/state_machine'
+
+require 'deltacloud/models/base_model'
+require 'deltacloud/models/flavor'
+require 'deltacloud/models/realm'
+require 'deltacloud/models/image'
+require 'deltacloud/models/instance'
+require 'deltacloud/models/storage_snapshot'
+require 'deltacloud/models/storage_volume'
+
+require 'deltacloud/helpers'

Added: incubator/deltacloud/trunk/server/libexec/drivers.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/drivers.rb?rev=962184&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/drivers.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/drivers.rb Thu Jul  8 23:34:45 2010
@@ -0,0 +1,29 @@
+DRIVERS = {
+  :ec2 => { :name => "EC2" },
+  :rackspace => { :name => "Rackspace" },
+  :gogrid => { :name => "Gogrid" },
+  :rhevm => { :name => "RHEVM" },
+  :rimu => { :name => "Rimu", :class => "RimuHostingDriver"},
+  :opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
+  :mock => { :name => "Mock" }
+}
+
+def driver_name
+  DRIVERS[DRIVER][:name]
+end
+
+def driver_class_name
+  basename = DRIVERS[DRIVER][:class] || "#{driver_name}Driver"
+  "Deltacloud::Drivers::#{driver_name}::#{basename}"
+end
+
+def driver_source_name
+  name = DRIVER.to_s
+  "deltacloud/drivers/#{name}/#{name}_driver.rb"
+end
+
+def driver
+  require driver_source_name
+  @driver ||= eval( driver_class_name ).new
+end
+

Added: incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers.rb?rev=962184&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers.rb Thu Jul  8 23:34:45
2010
@@ -0,0 +1,6 @@
+require 'deltacloud/helpers/application_helper'
+require 'deltacloud/helpers/url_helper'
+require 'deltacloud/helpers/driver_helper'
+require 'deltacloud/helpers/hardware_profiles_helper'
+
+helpers ApplicationHelper, URLHelper, DriverHelper, HardwareProfilesHelper

Modified: incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/driver_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/driver_helper.rb?rev=962184&r1=962183&r2=962184&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/driver_helper.rb (original)
+++ incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/driver_helper.rb Thu
Jul  8 23:34:45 2010
@@ -17,12 +17,14 @@
 
 
 require 'deltacloud/base_driver'
+require 'converters/xml_converter'
 
 module DriverHelper
 
-  def driver
-    load "#{DRIVER_CLASS_NAME.underscore}.rb"
-    @driver ||= eval( DRIVER_CLASS_NAME ).new
+  def convert_to_xml(type, obj)
+    if ( [ :flavor, :account, :image, :realm, :instance, :storage_volume, :storage_snapshot
].include?( type ) )
+      Converters::XMLConverter.new( self, type ).convert(obj)
+    end
   end
 
   def catch_auth
@@ -34,4 +36,13 @@ module DriverHelper
     end
   end
 
+  def safely(&block)
+    begin
+      block.call
+    rescue Deltacloud::AuthException => e
+      @response.status=403
+      "<error>#{e.message}</error>"
+    end
+  end
+
 end

Added: incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/url_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/url_helper.rb?rev=962184&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/url_helper.rb (added)
+++ incubator/deltacloud/trunk/server/libexec/lib/deltacloud/helpers/url_helper.rb Thu Jul
 8 23:34:45 2010
@@ -0,0 +1,5 @@
+module URLHelper
+    def root_url
+        url_for "/"
+    end
+end



Mime
View raw message