Skip to content

Provider based case statements in services #16

@tokengeek

Description

@tokengeek

The factories for services appear to have the same problem based on a case statement around some providers.

So when Fog::Compute[:provider] or Fog::Compute.new(:provider => "provider") is called in almost all cases we require fog/provider/service then return a new instance of Fog::Provider::Service

I'm pretty sure that we can scrap most of this stuff.

  • Some providers are just there but have no special behaviour.
  • new_servers is just a wrapper around bare_metal_cloud and can probably go.
  • Rackspace and HP use the factory to switch on version. I think this can probably be pushed down to a factory for each provider. Fog::Compute[:hp] => Fog::HP::Compute.new(:version => "v1") => Fog::HP::ComputeV1.new
  • Anyone missing from Fog.providers can be added.
  • Might be some cases where symbol and class name are awkward to constantize vclouddirector => VcloudDirector

The behaviour is so similar / copy pasted that I think we can eliminate most of this.

We could even add something and enumerate over all providers asking if they recognise the symbol and use that.

Fog::Brightbox.recognise_provider?(:new_servers) # => false
Fog::BareMetalCloud.recognise_provider?(:new_servers) # => true
Fog::VcloudDirector.recognise_provider?(:vclouddirector) # => true

module Fog
  def self.new(options)
    provider_key = get_provider_from(options)
    provider_server = Fog.providers.detect { |prov| prov.recognise_provider?(provider_key)
   require "fog/{provider_service.name}/service"
   Fog::{Provider}.new(remaining_options...)
  end
end

Basically we don't want anything in core that doesn't need to be there or needs updating when a new provider is added.

Examples:

https://github.com/fog/fog-core/blob/master/lib/fog/compute.rb#L13-L62
https://github.com/fog/fog-core/blob/master/lib/fog/storage.rb#L10-L27

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions