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 AWS < Fog::Bin
|
||||||
class << self
|
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)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
klazz = class_for(key)
|
||||||
when :cdn
|
hash[key] = case key
|
||||||
Fog::AWS::CDN.new
|
|
||||||
when :compute
|
|
||||||
Fog::AWS::Compute.new
|
|
||||||
when :ec2
|
when :ec2
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] AWS[:ec2] is deprecated, use AWS[:compute] instead[/]"
|
warning = "[yellow][WARN] AWS[:ec2] is deprecated, use AWS[:compute] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::AWS::Compute.new
|
klazz.new
|
||||||
when :elb
|
|
||||||
Fog::AWS::ELB.new
|
|
||||||
when :eu_storage
|
when :eu_storage
|
||||||
Fog::AWS::Storage.new(:region => 'eu-west-1')
|
klazz.new(:region => 'eu-west-1')
|
||||||
when :iam
|
|
||||||
Fog::AWS::IAM.new
|
|
||||||
when :sdb
|
|
||||||
Fog::AWS::SimpleDB.new
|
|
||||||
when :s3
|
when :s3
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] AWS[:s3] is deprecated, use AWS[:storage] instead[/]"
|
warning = "[yellow][WARN] AWS[:s3] is deprecated, use AWS[:storage] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::AWS::Storage.new
|
klazz.new
|
||||||
when :storage
|
else
|
||||||
Fog::AWS::Storage.new
|
klazz.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
|
|
|
@ -1,25 +1,31 @@
|
||||||
class Bluebox < Fog::Bin
|
class Bluebox < Fog::Bin
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
def [](service)
|
def class_for(key)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
case key
|
||||||
hash[key] = case key
|
when :blocks, :compute
|
||||||
when :blocks
|
Fog::Bluebox::Compute
|
||||||
location = caller.first
|
else
|
||||||
warning = "[yellow][WARN] Bluebox[:blocks] is deprecated, use Bluebox[:compute] instead[/]"
|
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
|
||||||
Formatador.display_line(warning)
|
|
||||||
Fog::Bluebox::Compute.new
|
|
||||||
when :compute
|
|
||||||
Fog::Bluebox::Compute.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@connections[service]
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def services
|
def [](service)
|
||||||
[:compute]
|
@@connections ||= Hash.new do |hash, key|
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
hash[key] = class_for(key).new
|
||||||
end
|
end
|
||||||
|
@@connections[service]
|
||||||
|
end
|
||||||
|
|
||||||
|
def services
|
||||||
|
[:compute]
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
class Brightbox < Fog::Bin
|
class Brightbox < Fog::Bin
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
def class_for(key)
|
||||||
|
case key
|
||||||
|
when :compute
|
||||||
|
Fog::Brightbox::Compute
|
||||||
|
else
|
||||||
|
raise ArgumentError, "Unrecognized service: #{key}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def [](service)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
hash[key] = class_for(key).new
|
||||||
when :compute
|
|
||||||
Fog::Brightbox::Compute.new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,16 +34,20 @@ module Fog
|
||||||
availability = true
|
availability = true
|
||||||
for service in services
|
for service in services
|
||||||
begin
|
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)}
|
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
|
availability = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if availability
|
if availability
|
||||||
for service in services
|
for service in services
|
||||||
for collection in self[service].collections
|
for collection in self.class_for(service).collections
|
||||||
unless self.respond_to?(collection)
|
unless self.respond_to?(collection)
|
||||||
self.class_eval <<-EOS, __FILE__, __LINE__
|
self.class_eval <<-EOS, __FILE__, __LINE__
|
||||||
def self.#{collection}
|
def self.#{collection}
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
class GoGrid < Fog::Bin
|
class GoGrid < Fog::Bin
|
||||||
class << self
|
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)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
if key == :servers
|
||||||
when :compute
|
|
||||||
Fog::GoGrid::Compute.new
|
|
||||||
when :servers
|
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] GoGrid[:servers] is deprecated, use GoGrid[:compute] instead[/]"
|
warning = "[yellow][WARN] GoGrid[:servers] is deprecated, use GoGrid[:compute] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::GoGrid::Compute.new
|
|
||||||
end
|
end
|
||||||
|
hash[key] = class_for(key).new
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,12 +1,18 @@
|
||||||
class Google < Fog::Bin
|
class Google < Fog::Bin
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
def class_for(key)
|
||||||
|
case key
|
||||||
|
when :storage
|
||||||
|
Fog::Google::Storage
|
||||||
|
else
|
||||||
|
raise ArgumentError, "Unsupported #{self} service: #{key}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def [](service)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
hash[key] = class_for(key).new
|
||||||
when :storage
|
|
||||||
Fog::Google::Storage.new
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
@ -16,5 +22,4 @@ class Google < Fog::Bin
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
class Linode < Fog::Bin
|
class Linode < Fog::Bin
|
||||||
class << self
|
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)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
if key == :linode
|
||||||
when :compute
|
|
||||||
Fog::Linode::Compute.new
|
|
||||||
when :linode
|
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] Linode[:linode] is deprecated, use Linode[:compute] instead[/]"
|
warning = "[yellow][WARN] Linode[:linode] is deprecated, use Linode[:compute] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::Linode::Compute.new
|
|
||||||
end
|
end
|
||||||
|
hash[key] = class_for(key).new
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
class Local < Fog::Bin
|
class Local < Fog::Bin
|
||||||
class << self
|
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)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
if key == :files
|
||||||
when :files
|
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] Local[:files] is deprecated, use Local[:storage] instead[/]"
|
warning = "[yellow][WARN] Local[:files] is deprecated, use Local[:storage] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::Local::Storage.new
|
|
||||||
when :storage
|
|
||||||
Fog::Local::Storage.new
|
|
||||||
end
|
end
|
||||||
|
hash[key] = class_for(key).new
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
class NewServers < Fog::Bin
|
class NewServers < Fog::Bin
|
||||||
class << self
|
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)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
if key == :new_servers
|
||||||
when :compute
|
|
||||||
Fog::NewServers::Compute.new
|
|
||||||
when :new_servers
|
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] NewServers[:servers] is deprecated, use NewServers[:compute] instead[/]"
|
warning = "[yellow][WARN] NewServers[:servers] is deprecated, use NewServers[:compute] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::NewServers::Compute.new
|
|
||||||
end
|
end
|
||||||
|
hash[key] = class_for(key).new
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,27 +1,37 @@
|
||||||
class Rackspace < Fog::Bin
|
class Rackspace < Fog::Bin
|
||||||
class << self
|
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)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
|
klazz = class_for(key)
|
||||||
hash[key] = case key
|
hash[key] = case key
|
||||||
when :cdn
|
|
||||||
Fog::Rackspace::CDN.new
|
|
||||||
when :compute
|
|
||||||
Fog::Rackspace::Compute.new
|
|
||||||
when :files
|
when :files
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] Rackspace[:files] is deprecated, use Rackspace[:storage] instead[/]"
|
warning = "[yellow][WARN] Rackspace[:files] is deprecated, use Rackspace[:storage] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::Rackspace::Storage.new
|
klazz.new
|
||||||
when :servers
|
when :servers
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] Rackspace[:servers] is deprecated, use Rackspace[:compute] instead[/]"
|
warning = "[yellow][WARN] Rackspace[:servers] is deprecated, use Rackspace[:compute] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::Rackspace::Compute.new
|
klazz.new
|
||||||
when :storage
|
else
|
||||||
Fog::Rackspace::Storage.new
|
klazz.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
class Slicehost < Fog::Bin
|
class Slicehost < Fog::Bin
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
def class_for(key)
|
||||||
|
case key
|
||||||
|
when :compute, :slices
|
||||||
|
Fog::Slicehost::Compute
|
||||||
|
else
|
||||||
|
raise ArgumentError, "Unrecognized service: #{key}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def [](service)
|
def [](service)
|
||||||
@@connections ||= Hash.new do |hash, key|
|
@@connections ||= Hash.new do |hash, key|
|
||||||
hash[key] = case key
|
if key == :slices
|
||||||
when :compute
|
|
||||||
Fog::Slicehost::Compute.new
|
|
||||||
when :slices
|
|
||||||
location = caller.first
|
location = caller.first
|
||||||
warning = "[yellow][WARN] Slicehost[:blocks] is deprecated, use Bluebox[:compute] instead[/]"
|
warning = "[yellow][WARN] Slicehost[:blocks] is deprecated, use Bluebox[:compute] instead[/]"
|
||||||
warning << " [light_black](" << location << ")[/] "
|
warning << " [light_black](" << location << ")[/] "
|
||||||
Formatador.display_line(warning)
|
Formatador.display_line(warning)
|
||||||
Fog::Slicehost::Compute.new
|
|
||||||
end
|
end
|
||||||
|
hash[key] = class_for(key).new
|
||||||
end
|
end
|
||||||
@@connections[service]
|
@@connections[service]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue