Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OC-9430: Knife cloud should support endpoint config and cli option #40

Merged
merged 2 commits into from
Sep 18, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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