Skip to content

Commit

Permalink
Allow to get ouput for multiple nodes at once
Browse files Browse the repository at this point in the history
Signed-off-by: Kirill Shirinkin <fodojyko@gmail.com>
  • Loading branch information
Kirill Shirinkin committed Nov 28, 2016
1 parent 894afe3 commit 3619651
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
28 changes: 24 additions & 4 deletions lib/chef/knife/job_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,46 @@
# under the License.
#

require "chef/knife/job_helpers"

class Chef
class Knife
class JobOutput < Chef::Knife

include JobHelpers

banner "knife job output <job id> <node> [<node> ...]"

option :channel,
:long => "--channel stdout|stderr",
: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)
Expand Down

0 comments on commit 3619651

Please sign in to comment.