Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to get ouput for multiple nodes at once #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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 @@ -119,12 +123,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