Skip to content

Commit

Permalink
fix all services to support both implemented ways
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbmina committed Jun 16, 2015
1 parent aa830b6 commit a4ad06d
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 22 deletions.
6 changes: 5 additions & 1 deletion lib/fog/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ def self.new(attributes)
Fog::Account::StormOnDemand.new(attributes)
elsif providers.include?(provider)
require "fog/#{provider}/account"
return Fog::Account.const_get(Fog.providers[provider]).new(attributes)
begin
Fog::Account.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Account
end.new(attributes)
else
raise ArgumentError, "#{provider} has no account service"
end
Expand Down
11 changes: 7 additions & 4 deletions lib/fog/baremetal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ def self.[](provider)
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}/baremetal"
return Fog::Baremetal.const_get(Fog.providers[provider]).new(attributes)
begin
Fog::Baremetal.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Baremetal
end.new(attributes)
else
raise ArgumentError, "#{provider} has no baremetal service"
end

raise ArgumentError, "#{provider} has no baremetal service"
end

def self.providers
Expand Down
7 changes: 7 additions & 0 deletions lib/fog/billing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def self.new(attributes)
if provider == :stormondemand
require "fog/billing/storm_on_demand"
Fog::Billing::StormOnDemand.new(attributes)
elsif providers.include?(provider)
require "fog/#{provider}/billing"
begin
Fog::Account.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Account
end.new(attributes)
else
raise ArgumentError, "#{provider} has no billing service"
end
Expand Down
9 changes: 7 additions & 2 deletions lib/fog/cdn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ def self.new(attributes)
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)
begin
Fog::CDN.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::CDN
end.new(attributes)
else
raise ArgumentError, "#{provider} has no cdn service"
end
raise ArgumentError, "#{provider} is not a recognized cdn provider"
end

def self.providers
Expand Down
9 changes: 7 additions & 2 deletions lib/fog/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ def self.new(attributes)
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)
begin
Fog::Image.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Image
end.new(attributes)
else
raise ArgumentError, "#{provider} has no image service"
end
raise ArgumentError, "#{provider} has no image service"
end

def self.providers
Expand Down
10 changes: 7 additions & 3 deletions lib/fog/metering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ def self.new(attributes)
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)
begin
Fog::Metering.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Metering
end.new(attributes)
else
raise ArgumentError, "#{provider} has no metering service"
end

raise ArgumentError, "#{provider} has no identity service"
end

def self.providers
Expand Down
7 changes: 7 additions & 0 deletions lib/fog/monitoring.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def self.new(attributes)
if provider == :stormondemand
require "fog/monitoring/storm_on_demand"
Fog::Monitoring::StormOnDemand.new(attributes)
elsif providers.include?(provider)
require "fog/#{provider}/monitoring"
begin
Fog::Monitoring.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Monitoring
end.new(attributes)
else
raise ArgumentError, "#{provider} has no monitoring service"
end
Expand Down
10 changes: 7 additions & 3 deletions lib/fog/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ def self.new(attributes)
return Fog::Network::StormOnDemand.new(attributes)
elsif providers.include?(provider)
require "fog/#{provider}/network"
return Fog::Network.const_get(Fog.providers[provider]).new(attributes)
begin
Fog::Network.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Network
end.new(attributes)
else
raise ArgumentError, "#{provider} has no network service"
end

raise ArgumentError, "#{provider} has no network service"
end

def self.providers
Expand Down
11 changes: 7 additions & 4 deletions lib/fog/orchestration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ def self.[](provider)
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)
begin
Fog::Orchestration.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Orchestration
end.new(attributes)
else
raise ArgumentError, "#{provider} has no orchestration service"
end

raise ArgumentError, "#{provider} has no orchestration service"
end

def self.providers
Expand Down
7 changes: 7 additions & 0 deletions lib/fog/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def self.new(attributes)
if provider == :stormondemand
require "fog/support/storm_on_demand"
Fog::Support::StormOnDemand.new(attributes)
elsif providers.include?(provider)
require "fog/#{provider}/support"
begin
Fog::Support.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Support
end.new(attributes)
else
raise ArgumentError, "#{provider} has no support service"
end
Expand Down
10 changes: 7 additions & 3 deletions lib/fog/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ def self.new(attributes)
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)
begin
Fog::Volume.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::Volume
end.new(attributes)
else
raise ArgumentError, "#{provider} has no volume service"
end

raise ArgumentError, "#{provider} has no identity service"
end

def self.providers
Expand Down
7 changes: 7 additions & 0 deletions lib/fog/vpn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def self.new(attributes)
if provider == :stormondemand
require "fog/vpn/storm_on_demand"
Fog::VPN::StormOnDemand.new(attributes)
elsif providers.include?(provider)
require "fog/#{provider}/vpn"
begin
Fog::VPN.const_get(Fog.providers[provider])
rescue
Fog.const_get(Fog.providers[provider])::VPN
end.new(attributes)
else
raise ArgumentError, "#{provider} has no vpn service"
end
Expand Down

0 comments on commit a4ad06d

Please sign in to comment.