Permalink
Browse files

fixes #1890 api host status

  • Loading branch information...
1 parent 9f9effa commit 8dc8a9acf0d12e8ad9e57ffbfc981d47707c9f0a @isratrade isratrade committed with ohadlevy Dec 18, 2012
@@ -1,7 +1,7 @@
module Api
module V1
class HostsController < V1::BaseController
- before_filter :find_resource, :only => %w{show update destroy}
+ before_filter :find_resource, :only => %w{show update destroy status}
api :GET, "/hosts/", "List all hosts."
param :search, String, :desc => "Filter results"
@@ -82,6 +82,24 @@ def destroy
process_response @host.destroy
end
+ api :GET, "/hosts/:id/status", "Get status of host"
+ param :id, :identifier_dottable, :required => true
+ description <<-eos
+Return value may either be one of the following:
+
+* missing
+* failed
+* pending
+* changed
+* unchanged
+* unreported
+
+ eos
+
+ def status
+ render :json => { :status => @host.host_status }.to_json if @host
+ end
+
private
# this is required for template generation (such as pxelinux) which is not done via a web request
@@ -22,36 +22,30 @@ def last_report_tooltip record
# method that reformat the hostname column by adding the status icons
def name_column(record)
- if record.build
+ label = record.host_status
+ case label
+ when "Pending Installation"
style ="label-info"
- label = "Pending Installation"
short = "B"
- elsif record.respond_to?(:enabled) && !record.enabled
- label = "Alerts disabled"
+ when "Alerts disabled"
style = ""
short = "D"
- elsif record.respond_to?(:last_report) && record.last_report.nil?
- label = "No reports"
+ when "No reports"
style = ""
short = "N"
- elsif record.no_report
- label = "Out of sync"
+ when "Out of sync"
style = "label-warning"
short = "S"
- elsif record.error?
- label = "Error"
+ when "Error"
style = "label-important"
short = "E"
- elsif record.changes?
- label = "Active"
+ when "Active"
style = "label-info"
short = "A"
- elsif record.pending?
- label = "Pending"
+ when "Pending"
style = "label-warning"
short = "P"
else
- label = "No changes"
style = "label-success"
short = "O"
end
View
@@ -731,6 +731,26 @@ def clone
new
end
+ def host_status
+ if build
+ "Pending Installation"
+ elsif respond_to?(:enabled) && !enabled
+ "Alerts disabled"
+ elsif respond_to?(:last_report) && last_report.nil?
+ "No reports"
+ elsif no_report
+ "Out of sync"
+ elsif error?
+ "Error"
+ elsif changes?
+ "Active"
+ elsif record.pending?
+ "Pending"
+ else
+ "No changes"
+ end
+ end
+
private
def lookup_keys_params
return {} unless Setting["Enable_Smart_Variables_in_ENC"]
@@ -19,6 +19,7 @@
resources :audits ,:only => :index
resources :facts ,:only => :index, :controller => :fact_values
resources :puppetclasses ,:only => :index
+ get :status, :on => :member
end
resources :compute_resources, :except => [:new, :edit] do
resources :images, :except => [:new, :edit]
Oops, something went wrong.

0 comments on commit 8dc8a9a

Please sign in to comment.