Skip to content

Commit

Permalink
Merge pull request #40 from opscode/adamed-oc-9430
Browse files Browse the repository at this point in the history
OC-9430: Knife cloud should support endpoint config and cli option
  • Loading branch information
Adam Edwards committed Sep 18, 2013
2 parents df218df + 1ceab73 commit d5967ba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/chef/knife/cloud/fog/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lib/chef/knife/cloud/fog/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/support/shared_examples_for_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/unit/fog_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d5967ba

Please sign in to comment.