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:
parent
71e4f64024
commit
07dbdf6952
12 changed files with 246 additions and 362 deletions
11
bin/fog
11
bin/fog
|
@ -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)
|
||||
|
|
|
@ -1,12 +1,6 @@
|
|||
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
|
||||
|
@ -39,29 +33,5 @@ module AWS
|
|||
[: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
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
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|
|
||||
|
@ -26,12 +21,5 @@ module GoGrid
|
|||
[:compute]
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def initialized?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
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|
|
||||
|
@ -26,12 +21,5 @@ module Linode
|
|||
[:compute]
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def initialized?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
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|
|
||||
|
@ -26,20 +21,5 @@ module Local
|
|||
[: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
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
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|
|
||||
|
@ -26,12 +21,5 @@ module NewServers
|
|||
[:compute]
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def initialized?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
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|
|
||||
|
@ -34,28 +29,5 @@ module Rackspace
|
|||
[: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
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
module Slicehost
|
||||
class Slicehost < Fog::Bin
|
||||
class << self
|
||||
if Fog.credentials[:slicehost_password]
|
||||
|
||||
def initialized?
|
||||
true
|
||||
|
@ -26,20 +25,5 @@ module Slicehost
|
|||
[: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
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
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
|
||||
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)
|
||||
|
@ -33,12 +32,5 @@ module Terremark
|
|||
@@connections[service]
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
def initialized?
|
||||
false
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue