Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixes #1890 api host status

  • Loading branch information...
commit 8dc8a9acf0d12e8ad9e57ffbfc981d47707c9f0a 1 parent 9f9effa
@isratrade isratrade authored ohadlevy committed
View
20 app/controllers/api/v1/hosts_controller.rb
@@ -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
View
24 app/helpers/hosts_helper.rb
@@ -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
20 app/models/host.rb
@@ -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"]
View
1  config/routes/api/v1.rb
@@ -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]
View
3,187 doc/apipie_examples.yml
1,799 additions, 1,388 deletions not shown
View
5 test/functional/api/v1/hosts_controller_test.rb
@@ -58,4 +58,9 @@ def valid_attrs
assert_response :success
end
+ test "should show status hosts" do
+ get :status, { :id => hosts(:one).to_param }
+ assert_response :success
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.