Skip to content

Commit

Permalink
[GH105] Use generic code for service abstraction
Browse files Browse the repository at this point in the history
Clearing out the copypasta, and handling the two require and two class
name combinations allows us to eliminate most of the provider specific
rubbish.

Version abstraction options have also been disabled.

The remaining errors appear to be related to providers who changed the
form of their names. To compensate there is a little look up table to
correct this for the moment.
  • Loading branch information
tokengeek committed Dec 21, 2014
1 parent 932bff5 commit cb6b8af
Show file tree
Hide file tree
Showing 15 changed files with 0 additions and 250 deletions.
12 changes: 0 additions & 12 deletions lib/fog/account.rb
@@ -1,17 +1,5 @@
module Fog
module Account
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym

if provider == :stormondemand
require "fog/account/storm_on_demand"
Fog::Account::StormOnDemand.new(attributes)
else
raise ArgumentError, "#{provider} has no account service"
end
end
end
end
11 changes: 0 additions & 11 deletions lib/fog/billing.rb
@@ -1,16 +1,5 @@
module Fog
module Billing
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand
require "fog/billing/storm_on_demand"
Fog::Billing::StormOnDemand.new(attributes)
else
raise ArgumentError, "#{provider} has no billing service"
end
end
end
end
10 changes: 0 additions & 10 deletions lib/fog/cdn.rb
@@ -1,15 +1,5 @@
module Fog
module CDN
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym
if providers.include?(provider)
require "fog/#{provider}/cdn"
return Fog::CDN.const_get(Fog.providers[provider]).new(attributes)
end
raise ArgumentError, "#{provider} is not a recognized cdn provider"
end
end
end
64 changes: 0 additions & 64 deletions lib/fog/compute.rb
Expand Up @@ -2,70 +2,6 @@ module Fog
module Compute
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym

case provider
when :gogrid
require "fog/go_grid/compute"
Fog::Compute::GoGrid.new(attributes)
when :hp
version = attributes.delete(:version)
version = version.to_s.downcase.to_sym unless version.nil?
if version == :v2
require "fog/hp/compute_v2"
Fog::Compute::HPV2.new(attributes)
else
Fog::Logger.deprecation "HP Cloud Compute V1 service will be soon deprecated. Please use `:version => v2` attribute to use HP Cloud Compute V2 service."
require "fog/hp/compute"
Fog::Compute::HP.new(attributes)
end
when :new_servers
require "fog/bare_metal_cloud/compute"
Fog::Logger.deprecation "`new_servers` is deprecated. Please use `bare_metal_cloud` instead."
Fog::Compute::BareMetalCloud.new(attributes)
when :baremetalcloud
require "fog/bare_metal_cloud/compute"
Fog::Compute::BareMetalCloud.new(attributes)
when :rackspace
version = attributes.delete(:version)
version = version.to_s.downcase.to_sym unless version.nil?
if version == :v1
Fog::Logger.deprecation "First Gen Cloud Servers are deprecated. Please use `:version => :v2` attribute to use Next Gen Cloud Servers."
require "fog/rackspace/compute"
Fog::Compute::Rackspace.new(attributes)
else
require "fog/rackspace/compute_v2"
Fog::Compute::RackspaceV2.new(attributes)
end
when :stormondemand
require "fog/compute/storm_on_demand"
Fog::Compute::StormOnDemand.new(attributes)
when :vcloud
require "fog/vcloud/compute"
Fog::Vcloud::Compute.new(attributes)
when :vclouddirector
require "fog/vcloud_director/compute"
Fog::Compute::VcloudDirector.new(attributes)
else
if providers.include?(provider)
begin
require "fog/#{provider}/compute"
rescue LoadError
require "fog/compute/#{provider}"
end
begin
Fog::Compute.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Compute
end.new(attributes)
else
raise ArgumentError, "#{provider} is not a recognized compute provider"
end
end
end

def self.servers
servers = []
providers.each do |provider|
Expand Down
20 changes: 0 additions & 20 deletions lib/fog/dns.rb
Expand Up @@ -2,26 +2,6 @@ module Fog
module DNS
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
case provider = attributes.delete(:provider).to_s.downcase.to_sym
when :stormondemand
require "fog/dns/storm_on_demand"
Fog::DNS::StormOnDemand.new(attributes)
else
if providers.include?(provider)
require "fog/#{provider}/dns"
begin
Fog::DNS.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::DNS
end.new(attributes)
else
raise ArgumentError, "#{provider} is not a recognized dns provider"
end
end
end

def self.zones
zones = []
providers.each do |provider|
Expand Down
16 changes: 0 additions & 16 deletions lib/fog/identity.rb
@@ -1,21 +1,5 @@
module Fog
module Identity
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # Prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym

unless providers.include?(provider)
raise ArgumentError, "#{provider} has no identity service"
end

require "fog/#{provider}/identity"
begin
Fog::Identity.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Identity
end.new(attributes)
end
end
end
10 changes: 0 additions & 10 deletions lib/fog/image.rb
@@ -1,15 +1,5 @@
module Fog
module Image
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # Prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym
if providers.include?(provider)
require "fog/#{provider}/image"
return Fog::Image.const_get(Fog.providers[provider]).new(attributes)
end
raise ArgumentError, "#{provider} has no image service"
end
end
end
11 changes: 0 additions & 11 deletions lib/fog/metering.rb
@@ -1,16 +1,5 @@
module Fog
module Metering
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # Prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym
if providers.include?(provider)
require "fog/#{provider}/metering"
return Fog::Metering.const_get(Fog.providers[provider]).new(attributes)
end

raise ArgumentError, "#{provider} has no identity service"
end
end
end
11 changes: 0 additions & 11 deletions lib/fog/monitoring.rb
@@ -1,16 +1,5 @@
module Fog
module Monitoring
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym
if provider == :stormondemand
require "fog/monitoring/storm_on_demand"
Fog::Monitoring::StormOnDemand.new(attributes)
else
raise ArgumentError, "#{provider} has no monitoring service"
end
end
end
end
15 changes: 0 additions & 15 deletions lib/fog/network.rb
@@ -1,20 +1,5 @@
module Fog
module Network
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # Prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym

if provider == :stormondemand
require "fog/network/storm_on_demand"
return Fog::Network::StormOnDemand.new(attributes)
elsif providers.include?(provider)
require "fog/#{provider}/network"
return Fog::Network.const_get(Fog.providers[provider]).new(attributes)
end

raise ArgumentError, "#{provider} has no network service"
end
end
end
12 changes: 0 additions & 12 deletions lib/fog/orchestration.rb
@@ -1,17 +1,5 @@
module Fog
module Orchestration
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # Prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym

if providers.include?(provider)
require "fog/#{provider}/orchestration"
return Fog::Orchestration.const_get(Fog.providers[provider]).new(attributes)
end

raise ArgumentError, "#{provider} has no orchestration service"
end
end
end
23 changes: 0 additions & 23 deletions lib/fog/storage.rb
Expand Up @@ -4,29 +4,6 @@ module Fog
module Storage
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # prevent delete from having side effects
case provider = attributes.delete(:provider).to_s.downcase.to_sym
when :internetarchive
require "fog/internet_archive/storage"
Fog::Storage::InternetArchive.new(attributes)
when :stormondemand
require "fog/storage/storm_on_demand"
Fog::Storage::StormOnDemand.new(attributes)
else
if providers.include?(provider)
require "fog/#{provider}/storage"
begin
Fog::Storage.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Storage
end.new(attributes)
else
raise ArgumentError, "#{provider} is not a recognized storage provider"
end
end
end

def self.directories
directories = []
providers.each do |provider|
Expand Down
12 changes: 0 additions & 12 deletions lib/fog/support.rb
@@ -1,17 +1,5 @@
module Fog
module Support
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym

if provider == :stormondemand
require "fog/support/storm_on_demand"
Fog::Support::StormOnDemand.new(attributes)
else
raise ArgumentError, "#{provider} has no support service"
end
end
end
end
11 changes: 0 additions & 11 deletions lib/fog/volume.rb
@@ -1,16 +1,5 @@
module Fog
module Volume
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup # Prevent delete from having side effects
provider = attributes.delete(:provider).to_s.downcase.to_sym
if providers.include?(provider)
require "fog/#{provider}/volume"
return Fog::Volume.const_get(Fog.providers[provider]).new(attributes)
end

raise ArgumentError, "#{provider} has no identity service"
end
end
end
12 changes: 0 additions & 12 deletions lib/fog/vpn.rb
@@ -1,17 +1,5 @@
module Fog
module VPN
extend Fog::Core::ServiceAbstraction

def self.new(attributes)
attributes = attributes.dup
provider = attributes.delete(:provider).to_s.downcase.to_sym

if provider == :stormondemand
require "fog/vpn/storm_on_demand"
Fog::VPN::StormOnDemand.new(attributes)
else
raise ArgumentError, "#{provider} has no vpn service"
end
end
end
end

0 comments on commit cb6b8af

Please sign in to comment.