diff --git a/README.md b/README.md index 47df6f0..195bf94 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,11 @@ The `job output` command is used to view the output of Push jobs. (Push 2.0 and #### Syntax ```shell -knife job output JOBID +knife job output JOBID NODENAME1 NODENAME2 +``` + +```shell +knife job output JOBID -s SEARCH_QUERY ``` #### Examples @@ -115,12 +119,20 @@ knife job output JOBID knife job output 26e98ba162fa7ba6fb2793125553c7ae test --channel stdout ``` +```shell +knife job output 26e98ba162fa7ba6fb2793125553c7ae -s "policy_group:staging" --channel stdout +``` + #### Options --channel [stderr|stdout] The output channel to capture. +--search QUERY + +Solr query for list of nodes that can have job output. + ### job status The `job status` command is used to view the status of Push jobs. diff --git a/lib/chef/knife/job_output.rb b/lib/chef/knife/job_output.rb index df463bb..da4d1e6 100644 --- a/lib/chef/knife/job_output.rb +++ b/lib/chef/knife/job_output.rb @@ -15,9 +15,14 @@ # under the License. # +require "chef/knife/job_helpers" + class Chef class Knife class JobOutput < Chef::Knife + + include JobHelpers + banner "knife job output [ ...]" option :channel, @@ -25,16 +30,31 @@ class JobOutput < Chef::Knife :default => "stdout", :description => "Which output channel to fetch (default stdout)." + option :search, + :short => "-s QUERY", + :long => "--search QUERY", + :required => false, + :description => "Solr query for list of nodes that can have job output." + def run job_id = name_args[0] channel = get_channel(config[:channel]) - node = name_args[1] - uri = "pushy/jobs/#{job_id}/output/#{node}/#{channel}" + node_names = process_search(config[:search], name_args[1, @name_args.length - 1]) + + node_names.each do |node| + uri = "pushy/jobs/#{job_id}/output/#{node}/#{channel}" + begin + job = rest.get_rest(uri, { "Accept" => "application/octet-stream" }) + output(node: node, output: job) + rescue => e + if e.response.code == "404" + ui.warn("Could not find output for node #{node}, server returned 404") + end + end - job = rest.get_rest(uri, { "Accept" => "application/octet-stream" }) + end - output(job) end def get_channel(channel)