Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2012 01:55
Show Gist options
  • Save anonymous/3984352 to your computer and use it in GitHub Desktop.
Save anonymous/3984352 to your computer and use it in GitHub Desktop.
def configure_session
list = case config[:manual]
when true
@name_args[0].split(" ")
when false
r = Array.new
q = Chef::Search::Query.new
@action_nodes = q.search(:node, @name_args[0])[0]
@action_nodes.each do |item|
next if item.nil?
# 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] && (item[:cloud][:provider] != "rackspace")
i = item[:cloud][:public_hostname]
elsif config[:override_attribute]
i = format_for_display(item)[config[:override_attribute]]
else
i = format_for_display(item)[config[:attribute]]
end
r.push(i) unless i.nil?
end
r
end
if list.length == 0
if @action_nodes.length == 0
ui.fatal("No nodes returned from search!")
else
ui.fatal("#{@action_nodes.length} #{@action_nodes.length > 1 ? "nodes":"node"} found, " +
"but do not have the required attribute to stablish the connection. " +
"Try setting another attribute to open the connection using --attribute.")
end
exit 10
end
session_from_list(list)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment