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

Initial implementation for custom_arguments passed to Fog. #7

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def load_fog_gem

def connection
add_api_endpoint
add_custom_arguments
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this gets us -- do you know of cases where initiating the Fog service connection with extra parameters gets us additional functionality?

@connection ||= begin
connection = Fog::Compute.new(@auth_params)
rescue Excon::Errors::Unauthorized => e
Expand Down Expand Up @@ -121,6 +122,10 @@ def delete_server_on_failure(server = nil)
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

def add_custom_arguments
Chef::Config[:knife][:custom_arguments].map{|args| args.map{|k,v| @auth_params.merge!(k.to_sym => v)}} unless Chef::Config[:knife][:custom_arguments].nil?
end
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/chef/knife/cloud/server/create_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ def self.included(includer)
:default => includer.snake_case_name.split('_').first,
:proc => Proc.new { |key| Chef::Config[:knife][:chef_node_name_prefix] = key }

option :custom_arguments,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is along the lines of what I was thinking, but we'd need it for all commands. So should this be done in the options.rb potentially?

:long => "--custom-arguments CUSTOM_ARGUMENTS",
:description => "Custom arguments to be passed to Fog.",
:proc => Proc.new {|args| Chef::Config[:knife][:custom_arguments] = args.split(',').map{|keys| keys.split('=')}.map{|j| Hash[*j.map{|k| k.strip}]}}

end
end

Expand Down