1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

providers abstraction, more consolidated bin stuff between providers

This commit is contained in:
geemus 2010-09-21 11:11:15 -07:00
parent 71e4f64024
commit 07dbdf6952
12 changed files with 246 additions and 362 deletions

11
bin/fog
View file

@ -24,14 +24,15 @@ else
@irb.context.prompt_mode = :FOG
@irb.context.workspace = IRB::WorkSpace.new(binding)
modules = Fog.modules.map{|_module_| _module_.to_s}
modules = if modules.length > 1
modules[0...-1].join(', ') << ' and ' << modules[-1]
providers = Fog.providers.map{|provider| provider.to_s}
providers = if providers.length > 1
providers[0...-1].join(', ') << ' and ' << providers[-1]
else
modules.first
providers.first
end
Formatador.display_line('Welcome to fog interactive!')
Formatador.display_line(":#{Fog.credential.to_s} credentials provide #{modules}")
Formatador.display_line(":#{Fog.credential.to_s} credentials provide #{providers}")
providers = Fog.providers
Fog.modules.each do |_module_|
if _module_.respond_to?(:startup_notice)
_module_.send(:startup_notice)

View file

@ -1,67 +1,37 @@
module AWS
class AWS < Fog::Bin
class << self
if Fog.credentials[:aws_access_key_id] && Fog.credentials[:aws_secret_access_key]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
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
when :simpledb
Fog::AWS::SimpleDB.new
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
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
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
when :simpledb
Fog::AWS::SimpleDB.new
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
end
@@connections[service]
end
def services
[:compute, :elb, :simpledb, :storage]
end
for collection in Fog::AWS::Compute.collections
module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:compute].#{collection}
end
EOS
end
for collection in Fog::AWS::Storage.collections
module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:storage].#{collection}
end
EOS
end
else
def initialized?
false
end
@@connections[service]
end
end
def services
[:compute, :elb, :simpledb, :storage]
end
end
end

View file

@ -1,20 +1,9 @@
require 'fog/credentials'
require 'fog/aws/bin'
require 'fog/go_grid/bin'
require 'fog/linode/bin'
require 'fog/local/bin'
require 'fog/new_servers/bin'
require 'fog/rackspace/bin'
require 'fog/slicehost/bin'
require 'fog/terremark/bin'
require 'fog/vcloud/bin'
require 'fog/bluebox/bin'
module Fog
class << self
def modules
def providers
[
::AWS,
::Bluebox,
@ -24,10 +13,63 @@ module Fog
::NewServers,
::Rackspace,
::Slicehost,
::Terremark,
::Terremark
].select {|provider| provider.available?}
end
def modules
[
::Vcloud
].select {|_module_| _module_.initialized?}
end
end
class Bin
class << self
def available?
availability = true
for service in services
begin
service = eval(self[service].class.to_s.split('::')[0...-1].join('::'))
availability &&= service.requirements.all? {|requirement| Fog.credentials.include?(requirement)}
rescue
availability = false
end
end
if availability
for service in services
for collection in self[service].collections
self.class_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:#{service}].#{collection}
end
EOS
end
end
end
availability
end
def collections
services.map {|service| self[service].collections}.flatten.sort_by {|service| service.to_s}
end
end
end
end
require 'fog/aws/bin'
require 'fog/bluebox/bin'
require 'fog/go_grid/bin'
require 'fog/linode/bin'
require 'fog/local/bin'
require 'fog/new_servers/bin'
require 'fog/rackspace/bin'
require 'fog/slicehost/bin'
require 'fog/terremark/bin'
require 'fog/vcloud/bin'

View file

@ -1,12 +1,6 @@
module Bluebox
class Bluebox < Fog::Bin
class << self
if Fog.credentials[:bluebox_api_key]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
@ -27,20 +21,5 @@ module Bluebox
[:compute]
end
for collection in Fog::Bluebox::Compute.collections
module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:compute].#{collection}
end
EOS
end
else
def initialized?
false
end
end
end
end

View file

@ -1,37 +1,25 @@
module GoGrid
class GoGrid < Fog::Bin
class << self
if Fog.credentials[:go_grid_api_key] && Fog.credentials[:go_grid_shared_secret]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::GoGrid::Compute.new
when :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
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::GoGrid::Compute.new
when :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
@@connections[service]
end
def services
[:compute]
end
else
def initialized?
false
end
@@connections[service]
end
def services
[:compute]
end
end
end

View file

@ -1,37 +1,25 @@
module Linode
class Linode < Fog::Bin
class << self
if Fog.credentials[:linode_api_key]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::Linode::Compute.new
when :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
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::Linode::Compute.new
when :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
@@connections[service]
end
def services
[:compute]
end
else
def initialized?
false
end
@@connections[service]
end
def services
[:compute]
end
end
end

View file

@ -1,45 +1,25 @@
module Local
class Local < Fog::Bin
class << self
if Fog.credentials[:local_root]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :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
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :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
@@connections[service]
end
def services
[:storage]
end
for collection in Fog::Local::Storage.collections
module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:storage].#{collection}
end
EOS
end
else
def initialized?
false
end
@@connections[service]
end
def services
[:storage]
end
end
end

View file

@ -1,37 +1,25 @@
module NewServers
class NewServers < Fog::Bin
class << self
if Fog.credentials[:new_servers_password] && Fog.credentials[:new_servers_username]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::NewServers::Compute.new
when :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
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::NewServers::Compute.new
when :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
@@connections[service]
end
def services
[:compute]
end
else
def initialized?
false
end
@@connections[service]
end
def services
[:compute]
end
end
end

View file

@ -1,61 +1,33 @@
module Rackspace
class Rackspace < Fog::Bin
class << self
if Fog.credentials[:rackspace_api_key] && Fog.credentials[:rackspace_username]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
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
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
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
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
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
end
@@connections[service]
end
def services
[:compute, :storage]
end
for collection in Fog::Rackspace::Compute.collections
module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:compute].#{collection}
end
EOS
end
for collection in Fog::Rackspace::Storage.collections
module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:storage].#{collection}
end
EOS
end
else
def initialized?
false
end
@@connections[service]
end
def services
[:compute, :storage]
end
end
end

View file

@ -1,45 +1,29 @@
module Slicehost
class Slicehost < Fog::Bin
class << self
if Fog.credentials[:slicehost_password]
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::Slicehost::Compute.new
when :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
end
@@connections[service]
end
def services
[:compute]
end
for collection in Fog::Slicehost::Compute.collections
module_eval <<-EOS, __FILE__, __LINE__
def #{collection}
self[:compute].#{collection}
end
EOS
end
else
def initialized?
false
end
def initialized?
true
end
def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Fog::Slicehost::Compute.new
when :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
end
@@connections[service]
end
def services
[:compute]
end
end
end

View file

@ -1,44 +1,36 @@
module Terremark
class Terremark < Fog::Bin
class << self
if (Fog::Terremark::ECLOUD_OPTIONS.all? { |option| Fog.credentials.has_key?(option) } ) ||
(Fog::Terremark::VCLOUD_OPTIONS.all? { |option| Fog.credentials.has_key?(option) } )
def initialized?
true
end
def terremark_service(service)
case service
when :ecloud
Fog::Terremark::Ecloud
when :vcloud
Fog::Terremark::Vcloud
else
raise "Unsupported Terremark Service"
end
end
def [](service)
@@connections ||= Hash.new do |hash, key|
credentials = Fog.credentials.reject do |k,v|
case key
when :ecloud
!Fog::Terremark::ECLOUD_OPTIONS.include?(k)
when :vcloud
!Fog::Terremark::VCLOUD_OPTIONS.include?(k)
end
end
hash[key] = terremark_service(key).new(credentials)
end
@@connections[service]
end
else
def initialized?
false
end
def available?
Fog::Terremark::ECLOUD_OPTIONS.all? {|requirement| Fog.credentials.include?(requirement)} ||
Fog::Terremark::VCLOUD_OPTIONS.all? {|requirement| Fog.credentials.include?(requirement)}
end
def terremark_service(service)
case service
when :ecloud
Fog::Terremark::Ecloud
when :vcloud
Fog::Terremark::Vcloud
else
raise "Unsupported Terremark Service"
end
end
def [](service)
@@connections ||= Hash.new do |hash, key|
credentials = Fog.credentials.reject do |k,v|
case key
when :ecloud
!Fog::Terremark::ECLOUD_OPTIONS.include?(k)
when :vcloud
!Fog::Terremark::VCLOUD_OPTIONS.include?(k)
end
end
hash[key] = terremark_service(key).new(credentials)
end
@@connections[service]
end
end
end

View file

@ -32,7 +32,7 @@ module Vcloud
end
def startup_notice
puts "You have access to the following vCloud services: #{Vcloud.registered_services}."
Formatador.display_line("You have access to the following Vcloud services: #{Vcloud.registered_services}.")
end
def [](service)