summaryrefslogtreecommitdiff
path: root/lib/chef/knife
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2018-01-29 18:44:20 +0000
committerGitHub <noreply@github.com>2018-01-29 18:44:20 +0000
commit3fd9735e3ab43ea0b50c7dffc0c5524931a89a0c (patch)
treec41d29a391237f78d7a7bc4c46c497497322408d /lib/chef/knife
parentfb600d596d998c91188f9b6ac412aaebd34465cc (diff)
parent519cc87236585b0e5e0f1636d72fe90052552814 (diff)
downloadchef-3fd9735e3ab43ea0b50c7dffc0c5524931a89a0c.tar.gz
Merge pull request #6756 from cramaechi/CHEF-3287
Update error handling for "knife status" #3287
Diffstat (limited to 'lib/chef/knife')
-rw-r--r--lib/chef/knife/core/status_presenter.rb39
1 files changed, 22 insertions, 17 deletions
diff --git a/lib/chef/knife/core/status_presenter.rb b/lib/chef/knife/core/status_presenter.rb
index bb6766c6ac..1e2d9b41b6 100644
--- a/lib/chef/knife/core/status_presenter.rb
+++ b/lib/chef/knife/core/status_presenter.rb
@@ -101,27 +101,32 @@ class Chef
fqdn = (node[:ec2] && node[:ec2][:public_hostname]) || node[:fqdn]
name = node["name"] || node.name
- hours, minutes, seconds = time_difference_in_hms(node["ohai_time"])
- hours_text = "#{hours} hour#{hours == 1 ? ' ' : 's'}"
- minutes_text = "#{minutes} minute#{minutes == 1 ? ' ' : 's'}"
- seconds_text = "#{seconds} second#{seconds == 1 ? ' ' : 's'}"
run_list = "#{node['run_list']}" if config[:run_list]
- if hours > 24
- color = :red
- text = hours_text
- elsif hours >= 1
- color = :yellow
- text = hours_text
- elsif minutes >= 1
- color = :green
- text = minutes_text
+ line_parts = Array.new
+
+ if node["ohai_time"]
+ hours, minutes, seconds = time_difference_in_hms(node["ohai_time"])
+ hours_text = "#{hours} hour#{hours == 1 ? ' ' : 's'}"
+ minutes_text = "#{minutes} minute#{minutes == 1 ? ' ' : 's'}"
+ seconds_text = "#{seconds} second#{seconds == 1 ? ' ' : 's'}"
+ if hours > 24
+ color = :red
+ text = hours_text
+ elsif hours >= 1
+ color = :yellow
+ text = hours_text
+ elsif minutes >= 1
+ color = :green
+ text = minutes_text
+ else
+ color = :green
+ text = seconds_text
+ end
+ line_parts << @ui.color(text, color) + " ago" << name
else
- color = :green
- text = seconds_text
+ line_parts << "Node #{name} has not yet converged"
end
- line_parts = Array.new
- line_parts << @ui.color(text, color) + " ago" << name
line_parts << fqdn if fqdn
line_parts << ip if ip
line_parts << run_list if run_list