2010-10-29 19:24:34 -04:00
|
|
|
module Fog
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
|
|
|
|
def self.[](provider)
|
|
|
|
self.new(:provider => provider)
|
|
|
|
end
|
2010-10-29 19:24:34 -04:00
|
|
|
|
|
|
|
def self.new(attributes)
|
2010-12-13 20:51:16 -05:00
|
|
|
attributes = attributes.dup # prevent delete from having side effects
|
2012-07-30 16:01:23 -04:00
|
|
|
provider = attributes.delete(:provider).to_s.downcase.to_sym
|
2012-08-10 17:12:54 -04:00
|
|
|
|
2013-02-16 06:28:38 -05:00
|
|
|
|
2012-07-30 16:01:23 -04:00
|
|
|
case provider
|
2011-06-16 19:28:54 -04:00
|
|
|
when :gogrid
|
2011-08-24 21:27:03 -04:00
|
|
|
require 'fog/go_grid/compute'
|
2011-06-16 19:28:54 -04:00
|
|
|
Fog::Compute::GoGrid.new(attributes)
|
2012-03-04 00:27:43 -05:00
|
|
|
when :new_servers
|
|
|
|
require 'fog/bare_metal_cloud/compute'
|
2013-01-21 12:31:15 -05:00
|
|
|
Fog::Logger.deprecation "`new_servers` is deprecated. Please use `bare_metal_cloud` instead."
|
2012-03-04 00:27:43 -05:00
|
|
|
Fog::Compute::BareMetalCloud.new(attributes)
|
2012-03-01 21:54:49 -05:00
|
|
|
when :baremetalcloud
|
|
|
|
require 'fog/bare_metal_cloud/compute'
|
|
|
|
Fog::Compute::BareMetalCloud.new(attributes)
|
2011-06-16 19:28:54 -04:00
|
|
|
when :rackspace
|
2012-09-07 20:57:08 -04:00
|
|
|
version = attributes.delete(:version)
|
|
|
|
version = version.to_s.downcase.to_sym unless version.nil?
|
2012-12-20 16:26:06 -05:00
|
|
|
if version == :v2
|
2012-07-30 16:01:23 -04:00
|
|
|
require 'fog/rackspace/compute_v2'
|
2012-12-20 16:26:06 -05:00
|
|
|
Fog::Compute::RackspaceV2.new(attributes)
|
|
|
|
else
|
2013-01-21 12:31:15 -05:00
|
|
|
Fog::Logger.deprecation "First Gen Cloud Servers are deprecated. Please use `:version => :v2` attribute to use Next Gen Cloud Servers."
|
2012-12-20 16:26:06 -05:00
|
|
|
require 'fog/rackspace/compute'
|
|
|
|
Fog::Compute::Rackspace.new(attributes)
|
2012-07-30 16:01:23 -04:00
|
|
|
end
|
2011-06-16 19:28:54 -04:00
|
|
|
when :stormondemand
|
2011-08-24 21:14:00 -04:00
|
|
|
require 'fog/storm_on_demand/compute'
|
2011-07-22 13:02:34 -04:00
|
|
|
Fog::Compute::StormOnDemand.new(attributes)
|
2013-03-07 16:49:42 -05:00
|
|
|
when :vcloud
|
|
|
|
require 'fog/vcloud/compute'
|
|
|
|
Fog::Vcloud::Compute.new(attributes)
|
2010-10-29 19:24:34 -04:00
|
|
|
else
|
2013-02-16 06:28:38 -05:00
|
|
|
if self.providers.include?(provider)
|
|
|
|
require "fog/#{provider}/compute"
|
|
|
|
return Fog::Compute.const_get(Fog.providers[provider]).new(attributes)
|
|
|
|
end
|
2010-11-08 11:58:02 -05:00
|
|
|
raise ArgumentError.new("#{provider} is not a recognized compute provider")
|
2010-10-29 19:24:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-07-27 10:30:49 -04:00
|
|
|
def self.providers
|
|
|
|
Fog.services[:compute]
|
|
|
|
end
|
|
|
|
|
2011-06-16 19:28:54 -04:00
|
|
|
def self.servers
|
|
|
|
servers = []
|
2011-07-27 10:30:49 -04:00
|
|
|
for provider in self.providers
|
2011-06-16 19:28:54 -04:00
|
|
|
begin
|
|
|
|
servers.concat(self[provider].servers)
|
|
|
|
rescue # ignore any missing credentials/etc
|
|
|
|
end
|
|
|
|
end
|
|
|
|
servers
|
|
|
|
end
|
|
|
|
|
2010-10-29 19:24:34 -04:00
|
|
|
end
|
2011-01-07 19:52:09 -05:00
|
|
|
end
|