Skip to content

Commit

Permalink
[compute] refactor provider/service namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
geemus committed Jun 16, 2011
1 parent b4b6375 commit 69407ef
Show file tree
Hide file tree
Showing 535 changed files with 1,694 additions and 1,765 deletions.
1 change: 1 addition & 0 deletions bin/fog
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ else

# FIXME: hacks until we can `include Fog` in bin
CDN = Fog::CDN
Compute = Fog::Compute
DNS = Fog::DNS
Storage = Fog::Storage

Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/aws.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def class_for(key)
when :cloud_formation
Fog::AWS::CloudFormation
when :compute
Fog::AWS::Compute
Fog::Compute::AWS
when :dns
Fog::DNS::AWS
when :elb
Expand Down Expand Up @@ -40,6 +40,7 @@ def [](service)
when :cloud_formation
Fog::AWS::CloudFormation.new
when :compute
Formatador.display_line("[yellow][WARN] AWS[:compute] is deprecated, use Compute[:aws] instead[/]")
Fog::Compute.new(:provider => 'AWS')
when :dns
Formatador.display_line("[yellow][WARN] AWS[:dns] is deprecated, use DNS[:aws] instead[/]")
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/bluebox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::Bluebox::Compute
Fog::Compute::Bluebox
when :dns
Fog::DNS::Bluebox
else
Expand All @@ -16,6 +16,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] Bluebox[:compute] is deprecated, use Compute[:bluebox] instead[/]")
Fog::Compute.new(:provider => 'Bluebox')
when :dns
Formatador.display_line("[yellow][WARN] Bluebox[:storage] is deprecated, use Storage[:bluebox] instead[/]")
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/brightbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::Brightbox::Compute
Fog::Compute::Brightbox
else
raise ArgumentError, "Unrecognized service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] Brightbox[:compute] is deprecated, use Brightbox[:aws] instead[/]")
Fog::Compute.new(:provider => 'Brightbox')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/ecloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::Ecloud::Compute
Fog::Compute::Ecloud
else
raise ArgumentError, "Unrecognized service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] Ecloud[:compute] is deprecated, use Compute[:ecloud] instead[/]")
Fog::Compute.new(:provider => 'Ecloud')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/go_grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::GoGrid::Compute
Fog::Compute::GoGrid
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] GoGrid[:compute] is deprecated, use Compute[:gogrid] instead[/]")
Fog::Compute.new(:provider => 'GoGrid')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/linode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::Linode::Compute
Fog::Compute::Linode
when :dns
Fog::DNS::Linode
else
Expand All @@ -16,6 +16,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] Linode[:compute] is deprecated, use Compute[:linode] instead[/]")
Fog::Compute.new(:provider => 'Linode')
when :dns
Formatador.display_line("[yellow][WARN] Linode[:storage] is deprecated, use Storage[:linode] instead[/]")
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/new_servers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::NewServers::Compute
Fog::Compute::NewServers
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] NewServers[:compute] is deprecated, use Compute[:newservers] instead[/]")
Fog::Compute.new(:provider => 'NewServers')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/ninefold.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::Ninefold::Compute
Fog::Compute::Ninefold
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] Ninefold[:compute] is deprecated, use Compute[:ninefold] instead[/]")
Fog::Compute.new(:provider => 'Ninefold')
else
raise ArgumentError, "Unrecognized service: #{service}"
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/rackspace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def class_for(key)
when :cdn
Fog::CDN::Rackspace
when :compute
Fog::Rackspace::Compute
Fog::Compute::Rackspace
when :storage
Fog::Storage::Rackspace
else
Expand All @@ -21,6 +21,7 @@ def [](service)
Formatador.display_line("[yellow][WARN] Rackspace[:cdn] is deprecated, use CDN[:rackspace] instead[/]")
Fog::CDN.new(:provider => 'Rackspace')
when :compute
Formatador.display_line("[yellow][WARN] Rackspace[:compute] is deprecated, use Compute[:rackspace] instead[/]")
Fog::Compute.new(:provider => 'Rackspace')
when :dns
Fog::DNS.new(:provider => 'Rackspace')
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/slicehost.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::Slicehost::Compute
Fog::Compute::Slicehost
when :dns
Fog::DNS::Slicehost
else
Expand All @@ -16,6 +16,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] Slicehost[:compute] is deprecated, use Compute[:slicehost] instead[/]")
Fog::Compute.new(:provider => 'Slicehost')
when :dns
Formatador.display_line("[yellow][WARN] Slicehost[:dns] is deprecated, use Storage[:slicehost] instead[/]")
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/stormondemand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::StormOnDemand::Compute
Fog::Compute::StormOnDemand
else
raise ArgumentError, "Unsupported #{self} service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] StormOnDemand[:compute] is deprecated, use Compute[:stormondemand] instead[/]")
Fog::Compute.new(:provider => 'StormOnDemand')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/virtual_box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::VirtualBox::Compute
Fog::Compute::VirtualBox
else
raise ArgumentError, "Unrecognized service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] VirtualBox[:compute] is deprecated, use Compute[:virtualbox] instead[/]")
Fog::Compute.new(:provider => 'VirtualBox')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
Expand Down
3 changes: 2 additions & 1 deletion lib/fog/bin/voxel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class << self
def class_for(key)
case key
when :compute
Fog::Voxel::Compute
Fog::Compute::Voxel
else
raise ArgumentError, "Unrecognized service: #{key}"
end
Expand All @@ -14,6 +14,7 @@ def [](service)
@@connections ||= Hash.new do |hash, key|
hash[key] = case key
when :compute
Formatador.display_line("[yellow][WARN] Voxel[:compute] is deprecated, use Compute[:voxel] instead[/]")
Fog::Compute.new(:provider => 'Voxel')
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
Expand Down
71 changes: 43 additions & 28 deletions lib/fog/compute.rb
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
module Fog
class Compute
module Compute

def self.[](provider)
self.new(:provider => provider)
end

def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
case provider = attributes[:provider] # attributes.delete(:provider)
when 'AWS'
case provider = attributes[:provider].to_s.downcase.to_sym
when :aws
require 'fog/compute/aws'
Fog::AWS::Compute.new(attributes)
when 'Bluebox'
Fog::Compute::AWS.new(attributes)
when :bluebox
require 'fog/compute/bluebox'
Fog::Bluebox::Compute.new(attributes)
when 'Brightbox'
Fog::Compute::Bluebox.new(attributes)
when :brightbox
require 'fog/compute/brightbox'
Fog::Brightbox::Compute.new(attributes)
when 'Ecloud'
Fog::Compute::Brightbox.new(attributes)
when :ecloud
require 'fog/compute/ecloud'
Fog::Ecloud::Compute.new(attributes)
when 'GoGrid'
Fog::Compute::Ecloud.new(attributes)
when :gogrid
require 'fog/compute/go_grid'
Fog::GoGrid::Compute.new(attributes)
when 'Linode'
Fog::Compute::GoGrid.new(attributes)
when :linode
require 'fog/compute/linode'
Fog::Linode::Compute.new(attributes)
when 'NewServers'
Fog::Compute::Linode.new(attributes)
when :newservers
require 'fog/compute/new_servers'
Fog::NewServers::Compute.new(attributes)
when 'Ninefold'
Fog::Compute::NewServers.new(attributes)
when :ninefold
require 'fog/compute/ninefold'
Fog::Ninefold::Compute.new(attributes)
when 'Rackspace'
Fog::Compute::Ninefold.new(attributes)
when :rackspace
require 'fog/compute/rackspace'
Fog::Rackspace::Compute.new(attributes)
when 'Slicehost'
Fog::Compute::Rackspace.new(attributes)
when :slicehost
require 'fog/compute/slicehost'
Fog::Slicehost::Compute.new(attributes)
when 'StormOnDemand'
Fog::Compute::Slicehost.new(attributes)
when :stormondemand
require 'fog/compute/storm_on_demand'
Fog::StormOnDemand::Compute.new(attributes)
when 'VirtualBox'
Fog::Compute::StormOnDemand.new(attributes)
when :virtualbox
require 'fog/compute/virtual_box'
Fog::VirtualBox::Compute.new(attributes)
when 'Voxel'
Fog::Compute::VirtualBox.new(attributes)
when :voxel
require 'fog/compute/voxel'
Fog::Voxel::Compute.new(attributes)
Fog::Compute::Voxel.new(attributes)
else
raise ArgumentError.new("#{provider} is not a recognized compute provider")
end
end

def self.servers
servers = []
for provider in [:aws, :bluebox, :brightbox, :ecloud, :gogrid, :linode, :newservers, :ninefold, :rackspace, :slicehost, :stormondemand, :virtualbox, :voxel]
begin
servers.concat(self[provider].servers)
rescue # ignore any missing credentials/etc
end
end
servers
end

end
end
22 changes: 4 additions & 18 deletions lib/fog/compute/aws.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Fog
module AWS
class Compute < Fog::Service
module Compute
class AWS < Fog::Service

requires :aws_access_key_id, :aws_secret_access_key
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent
Expand Down Expand Up @@ -130,13 +130,6 @@ def self.reset
end

def initialize(options={})
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::AWS::Compute.new is deprecated, use Fog::Compute.new(:provider => 'AWS') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end

require 'fog/compute/parsers/aws/basic'

@aws_access_key_id = options[:aws_access_key_id]
Expand Down Expand Up @@ -204,13 +197,6 @@ class Real
# ==== Returns
# * EC2 object with connection to aws.
def initialize(options={})
unless options.delete(:provider)
location = caller.first
warning = "[yellow][WARN] Fog::AWS::Compute.new is deprecated, use Fog::Compute.new(:provider => 'AWS') instead[/]"
warning << " [light_black](" << location << ")[/] "
Formatador.display_line(warning)
end

require 'fog/core/parser'

@aws_access_key_id = options[:aws_access_key_id]
Expand Down Expand Up @@ -282,9 +268,9 @@ def request(params)
if match = error.message.match(/<Code>(.*)<\/Code><Message>(.*)<\/Message>/)
raise case match[1].split('.').last
when 'NotFound'
Fog::AWS::Compute::NotFound.slurp(error, match[2])
Fog::Compute::AWS::NotFound.slurp(error, match[2])
else
Fog::AWS::Compute::Error.slurp(error, "#{match[1]} => #{match[2]}")
Fog::Compute::AWS::Error.slurp(error, "#{match[1]} => #{match[2]}")
end
else
raise error
Expand Down
Loading

0 comments on commit 69407ef

Please sign in to comment.