diff --git a/lib/chef/knife/cloud/fog/options.rb b/lib/chef/knife/cloud/fog/options.rb index 0aed189..f11493b 100644 --- a/lib/chef/knife/cloud/fog/options.rb +++ b/lib/chef/knife/cloud/fog/options.rb @@ -15,6 +15,11 @@ def self.included(includer) :description => "Fog gem version to use. Use the ruby gem version strings", :default => "", :proc => Proc.new { |v| Chef::Config[:knife][:cloud_fog_version] = v} + + option :api_endpoint, + :long => "--api-endpoint ENDPOINT", + :description => "Your API endpoint. Eg, for Eucalyptus it can be 'http://ecc.eucalyptus.com:8773/services/Eucalyptus'", + :proc => Proc.new { |endpoint| Chef::Config[:knife][:api_endpoint] = endpoint } end end diff --git a/lib/chef/knife/cloud/fog/service.rb b/lib/chef/knife/cloud/fog/service.rb index 7a9298c..6f3d6df 100644 --- a/lib/chef/knife/cloud/fog/service.rb +++ b/lib/chef/knife/cloud/fog/service.rb @@ -29,6 +29,7 @@ def load_fog_gem end def connection + add_api_endpoint @connection ||= begin connection = Fog::Compute.new(@auth_params) rescue Excon::Errors::Unauthorized => e @@ -116,6 +117,10 @@ def list_images def delete_server_on_failure(server = nil) server.destroy if ! server.nil? end + + def add_api_endpoint + raise Chef::Exceptions::Override, "You must override add_api_endpoint in #{self.to_s} to add endpoint in auth_params for connection" + end end end end diff --git a/spec/support/shared_examples_for_service.rb b/spec/support/shared_examples_for_service.rb index d77eb26..6cdf4de 100644 --- a/spec/support/shared_examples_for_service.rb +++ b/spec/support/shared_examples_for_service.rb @@ -4,6 +4,7 @@ describe "#connection" do it "creates a connection to fog service." do + instance.should_receive(:add_api_endpoint) Fog::Compute.should_receive(:new) instance.connection end diff --git a/spec/unit/fog_service_spec.rb b/spec/unit/fog_service_spec.rb index c183415..6c47e52 100644 --- a/spec/unit/fog_service_spec.rb +++ b/spec/unit/fog_service_spec.rb @@ -17,6 +17,7 @@ end it "creates a connection to fog service with the provided auth params." do + instance.should_receive(:add_api_endpoint) Fog::Compute.should_receive(:new).with({:provider => 'Any Cloud Provider'}) instance.connection end