summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2012-08-02 14:46:04 -0700
committerBryan McLellan <btm@opscode.com>2012-08-03 08:51:48 -0700
commitec95e27e66c609782985346fb83b97eae108695c (patch)
tree6c555aaaa2c44352c4831a28008af391564733c6
parent3c52de54beb03a371b06a7b451591c650a79bb8a (diff)
downloadchef-ec95e27e66c609782985346fb83b97eae108695c.tar.gz
CHEF-1554: default to using a cloud attribute
If we have a cloud attribute we should use that, but the user should still be able to override that on the command line. This is a little tricky because we use the same variable for options passed from the user as we do to represent our final choice. Thus we lose any history as it whether our final choice was user requested or a default. Alternately we could refactor the class to use a different variable as a result of #configure_attribute
-rw-r--r--chef/lib/chef/knife/ssh.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/chef/lib/chef/knife/ssh.rb b/chef/lib/chef/knife/ssh.rb
index fb248a596a..495db9717a 100644
--- a/chef/lib/chef/knife/ssh.rb
+++ b/chef/lib/chef/knife/ssh.rb
@@ -124,8 +124,10 @@ class Chef
q = Chef::Search::Query.new
@action_nodes = q.search(:node, @name_args[0])[0]
@action_nodes.each do |item|
- if(item["cloud"])
- i = item["cloud"]["public_hostname"]
+ # if a command line attribute was not passed, and we have a cloud public_hostname, use that.
+ # see #configure_attribute for the source of config[:attribute] and config[:override_attribute]
+ if !config[:override_attribute] && item[:cloud] and item[:cloud][:public_hostname]
+ i = format_for_display(item)[:cloud][:public_hostname]
else
i = format_for_display(item)[config[:attribute]]
end
@@ -338,6 +340,12 @@ class Chef
end
def configure_attribute
+ # Setting 'knife[:ssh_attribute] = "foo"' in knife.rb => Chef::Config[:knife][:ssh_attribute] == 'foo'
+ # Running 'knife ssh -a foo' => both Chef::Config[:knife][:ssh_attribute] && config[:attribute] == foo
+ # Thus we can differentiate between a config file value and a command line override at this point by checking config[:attribute]
+ # We can tell here if fqdn was passed from the command line, rather than being the default, by checking config[:attribute]
+ # However, after here, we cannot tell these things, so we must preserve config[:attribute]
+ config[:override_attribute] = config[:attribute]
config[:attribute] = (Chef::Config[:knife][:ssh_attribute] ||
config[:attribute] ||
"fqdn").strip