From e400c50860c9e9f50acd61d5f4b787c7b74e7cd2 Mon Sep 17 00:00:00 2001 From: geemus Date: Tue, 7 Sep 2010 12:21:16 -0700 Subject: [PATCH] add a provider module, working toward conistency and discoverability from top down --- lib/fog.rb | 1 + lib/fog/aws.rb | 13 ++++++++----- lib/fog/provider.rb | 18 ++++++++++++++++++ lib/fog/rackspace.rb | 9 ++++++--- 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 lib/fog/provider.rb diff --git a/lib/fog.rb b/lib/fog.rb index bab485f7c..4eb9f939a 100644 --- a/lib/fog.rb +++ b/lib/fog.rb @@ -24,6 +24,7 @@ require 'fog/errors' require 'fog/hmac' require 'fog/model' require 'fog/parser' +require 'fog/provider' require 'fog/service' require 'fog/ssh' diff --git a/lib/fog/aws.rb b/lib/fog/aws.rb index 223c99720..9a52bd0e6 100644 --- a/lib/fog/aws.rb +++ b/lib/fog/aws.rb @@ -1,11 +1,14 @@ -require 'fog/aws/ec2.rb' -require 'fog/aws/elb.rb' -require 'fog/aws/s3' -require 'fog/aws/simpledb' - module Fog module AWS + extend Fog::Provider + + service_path 'fog/aws' + service 'ec2' + service 'elb' + service 's3' + service 'simpledb' + def self.indexed_param(key, values, offset = 0) params = {} unless key.include?('%d') diff --git a/lib/fog/provider.rb b/lib/fog/provider.rb new file mode 100644 index 000000000..484a80415 --- /dev/null +++ b/lib/fog/provider.rb @@ -0,0 +1,18 @@ +module Fog + module Provider + + def service_path(new_path) + @service_path = new_path + end + + def service(new_service) + services << new_service + require File.join(@service_path, new_service.to_s) + end + + def services + @services ||= [] + end + + end +end diff --git a/lib/fog/rackspace.rb b/lib/fog/rackspace.rb index 0ba76819e..3fa850d9a 100644 --- a/lib/fog/rackspace.rb +++ b/lib/fog/rackspace.rb @@ -1,9 +1,12 @@ -require 'fog/rackspace/files' -require 'fog/rackspace/servers' - module Fog module Rackspace + extend Fog::Provider + + service_path 'fog/rackspace' + service 'files' + service 'servers' + def self.authenticate(options) rackspace_auth_url = options[:rackspace_auth_url] || "auth.api.rackspacecloud.com" connection = Fog::Connection.new("https://" + rackspace_auth_url)