mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Added self.class_for(key) method. This allows us to inspect the requirements without having to create an instance of the service.
This commit is contained in:
parent
3fc3df03d8
commit
b9315bf7fe
11 changed files with 149 additions and 78 deletions
|
@ -1,35 +1,45 @@
|
|||
class AWS < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :cdn
|
||||
Fog::AWS::CDN
|
||||
when :compute, :ec2
|
||||
Fog::AWS::Compute
|
||||
when :elb
|
||||
Fog::AWS::ELB
|
||||
when :iam
|
||||
Fog::AWS::IAM
|
||||
when :sdb
|
||||
Fog::AWS::SimpleDB
|
||||
when :eu_storage, :s3, :storage
|
||||
Fog::AWS::Storage
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
klazz = class_for(key)
|
||||
hash[key] = case key
|
||||
when :cdn
|
||||
Fog::AWS::CDN.new
|
||||
when :compute
|
||||
Fog::AWS::Compute.new
|
||||
when :ec2
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] AWS[:ec2] is deprecated, use AWS[:compute] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::AWS::Compute.new
|
||||
when :elb
|
||||
Fog::AWS::ELB.new
|
||||
klazz.new
|
||||
when :eu_storage
|
||||
Fog::AWS::Storage.new(:region => 'eu-west-1')
|
||||
when :iam
|
||||
Fog::AWS::IAM.new
|
||||
when :sdb
|
||||
Fog::AWS::SimpleDB.new
|
||||
klazz.new(:region => 'eu-west-1')
|
||||
when :s3
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] AWS[:s3] is deprecated, use AWS[:storage] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::AWS::Storage.new
|
||||
when :storage
|
||||
Fog::AWS::Storage.new
|
||||
klazz.new
|
||||
else
|
||||
klazz.new
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
class Bluebox < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :blocks, :compute
|
||||
Fog::Bluebox::Compute
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :blocks
|
||||
if key == :blocks
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] Bluebox[:blocks] is deprecated, use Bluebox[:compute] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::Bluebox::Compute.new
|
||||
when :compute
|
||||
Fog::Bluebox::Compute.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
class Brightbox < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute
|
||||
Fog::Brightbox::Compute
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :compute
|
||||
Fog::Brightbox::Compute.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
|
|
@ -34,16 +34,20 @@ module Fog
|
|||
availability = true
|
||||
for service in services
|
||||
begin
|
||||
service = eval(self[service].class.to_s.split('::')[0...-1].join('::'))
|
||||
service = self.class_for(service)
|
||||
availability &&= service.requirements.all? { |requirement| Fog.credentials.include?(requirement) }
|
||||
rescue
|
||||
rescue ArgumentError => e
|
||||
warning = "[yellow][WARN] #{e.message}[/]"
|
||||
Formatador.display_line(warning)
|
||||
availability = false
|
||||
rescue => e
|
||||
availability = false
|
||||
end
|
||||
end
|
||||
|
||||
if availability
|
||||
for service in services
|
||||
for collection in self[service].collections
|
||||
for collection in self.class_for(service).collections
|
||||
unless self.respond_to?(collection)
|
||||
self.class_eval <<-EOS, __FILE__, __LINE__
|
||||
def self.#{collection}
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
class GoGrid < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute, :servers
|
||||
Fog::GoGrid::Compute
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :compute
|
||||
Fog::GoGrid::Compute.new
|
||||
when :servers
|
||||
if key == :servers
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] GoGrid[:servers] is deprecated, use GoGrid[:compute] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::GoGrid::Compute.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
|
|
@ -1,12 +1,18 @@
|
|||
class Google < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :storage
|
||||
Fog::Google::Storage
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :storage
|
||||
Fog::Google::Storage.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
@ -16,5 +22,4 @@ class Google < Fog::Bin
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
class Linode < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute, :linode
|
||||
Fog::Linode::Compute
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :compute
|
||||
Fog::Linode::Compute.new
|
||||
when :linode
|
||||
if key == :linode
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] Linode[:linode] is deprecated, use Linode[:compute] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::Linode::Compute.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
class Local < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :files, :storage
|
||||
Fog::Local::Storage
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :files
|
||||
if key == :files
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] Local[:files] is deprecated, use Local[:storage] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::Local::Storage.new
|
||||
when :storage
|
||||
Fog::Local::Storage.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
class NewServers < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute, :new_servers
|
||||
Fog::NewServers::Compute
|
||||
else
|
||||
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :compute
|
||||
Fog::NewServers::Compute.new
|
||||
when :new_servers
|
||||
if key == :new_servers
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] NewServers[:servers] is deprecated, use NewServers[:compute] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::NewServers::Compute.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
|
|
@ -1,27 +1,37 @@
|
|||
class Rackspace < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :cdn
|
||||
Fog::Rackspace::CDN
|
||||
when :compute, :servers
|
||||
Fog::Rackspace::Compute
|
||||
when :files, :storage
|
||||
Fog::Rackspace::Storage
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
klazz = class_for(key)
|
||||
hash[key] = case key
|
||||
when :cdn
|
||||
Fog::Rackspace::CDN.new
|
||||
when :compute
|
||||
Fog::Rackspace::Compute.new
|
||||
when :files
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] Rackspace[:files] is deprecated, use Rackspace[:storage] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::Rackspace::Storage.new
|
||||
klazz.new
|
||||
when :servers
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] Rackspace[:servers] is deprecated, use Rackspace[:compute] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::Rackspace::Compute.new
|
||||
when :storage
|
||||
Fog::Rackspace::Storage.new
|
||||
klazz.new
|
||||
else
|
||||
klazz.new
|
||||
end
|
||||
end
|
||||
@@connections[service]
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
class Slicehost < Fog::Bin
|
||||
class << self
|
||||
|
||||
def class_for(key)
|
||||
case key
|
||||
when :compute, :slices
|
||||
Fog::Slicehost::Compute
|
||||
else
|
||||
raise ArgumentError, "Unrecognized service: #{key}"
|
||||
end
|
||||
end
|
||||
|
||||
def [](service)
|
||||
@@connections ||= Hash.new do |hash, key|
|
||||
hash[key] = case key
|
||||
when :compute
|
||||
Fog::Slicehost::Compute.new
|
||||
when :slices
|
||||
if key == :slices
|
||||
location = caller.first
|
||||
warning = "[yellow][WARN] Slicehost[:blocks] is deprecated, use Bluebox[:compute] instead[/]"
|
||||
warning << " [light_black](" << location << ")[/] "
|
||||
Formatador.display_line(warning)
|
||||
Fog::Slicehost::Compute.new
|
||||
end
|
||||
hash[key] = class_for(key).new
|
||||
end
|
||||
@@connections[service]
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue