61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/chef/knife/cssh-summon.rb', line 61
def run
if name_args.length < 1
puts 'Missing argument QUERY!'
show_usage
exit 1
end
query = name_args[0]
q = Chef::Search::Query.new
escaped_query = URI.escape(query, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
result_items = []
begin
q.search('node', escaped_query, 'X_CHEF_id_CHEF_X asc', 0, 100) do |item|
remote_host = item
result_items.push remote_host if not remote_host.nil?
end
rescue Net::HTTPServerException => e
msg = Chef::JSONCompat.from_json(e.response.body)["error"].first
ui.error("search failed: #{msg}")
exit 1
end
call_cssh result_items
end
|