Class: Chef::Knife::GoiardiJobStream

Inherits:
Chef::Knife show all
Defined in:
lib/chef/knife/goiardi_job_stream.rb

Instance Method Summary collapse

Instance Method Details

#runObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/chef/knife/goiardi_job_stream.rb', line 27

def run
	job_id = @name_args[0]
	if job_id.nil?
	  ui.error "No job id specified"
	  show_usage
	  exit 1
	end
	node_name = @name_args[1]
	if node_name.nil?
	  ui.error "No node specified"
	  show_usage
	  exit 1
	end
	rest = Chef::REST.new(Chef::Config[:chef_server_url])
	outseq = 0
	errseq = 0
	outdone = false
	errdone = false
	loop do
	  if !outdone
	    outres = rest.get_rest("shovey/stream/#{job_id}/#{node_name}?sequence=#{outseq}&output_type=stdout")
	    if !outres["last_seq"].nil?
 seq = outres["last_seq"] + 1
	    end
	    if outres["output"] != ""
 stdout.print(outres["output"])
	    end
	    if outres["is_last"]
 outdone = true
	    end
	  end
	  if !errdone
	    errres = rest.get_rest("shovey/stream/#{job_id}/#{node_name}?sequence=#{errseq}&output_type=stderr")
	    if !errres["last_seq"].nil?
 seq = errres["last_seq"] + 1
	    end
	    if errres["output"] != ""
 stderr.print(ui.color(errres["output"], :red))
	    end
	    if errres["is_last"]
 errdone = true
	    end
	  end
	  break if outdone && errdone
	  sleep 0.25
	end
	ui.msg(ui.color("\nDone!", :blue))
	ui.pretty_print("\nFinished streaming output for job #{job_id} on node #{node_name}")
end