Initial import
[deltacloud-devel:deltacloud-virtualbox-driver.git] / drivers.rb
1
2 DRIVERS = {
3   :ec2 => { :name => "EC2" },
4   :rackspace => { :name => "Rackspace" },
5   :gogrid => { :name => "Gogrid" },
6   :rhevm => { :name => "RHEVM" },
7   :rimu => { :name => "Rimu", :class => "RimuHostingDriver"},
8   :opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
9   :vbox => { :name => "Vbox", :class => "VboxDriver" },
10   :mock => { :name => "Mock" }
11 }
12
13 def driver_name
14   DRIVERS[DRIVER][:name]
15 end
16
17 def driver_class_name
18   basename = DRIVERS[DRIVER][:class] || "#{driver_name}Driver"
19   "Deltacloud::Drivers::#{driver_name}::#{basename}"
20 end
21
22 def driver_source_name
23   "deltacloud/drivers/#{DRIVER}/#{DRIVER}_driver.rb"
24 end
25
26 def driver_mock_source_name
27   return "deltacloud/drivers/#{DRIVER}/#{DRIVER}_driver.rb" if driver_name.eql? 'Mock'
28   "deltacloud/drivers/#{DRIVER}/#{DRIVER}_mock_driver.rb"
29 end
30
31 def driver
32   require driver_source_name
33
34   begin
35     if Sinatra::Application.environment.eql? :test
36       require driver_mock_source_name
37     end
38   rescue
39   end
40
41   @driver ||= eval( driver_class_name ).new
42 end
43