Revision e54016da
Added by Marek Hulán over 8 years ago
app/controllers/api/v2/hosts_controller.rb | ||
---|---|---|
param_group :search_and_pagination, ::Api::V2::BaseController
|
||
|
||
def index
|
||
@hosts = resource_scope_for_index
|
||
@hosts = resource_scope_for_index.includes([ :host_statuses, :compute_resource, :hostgroup, :operatingsystem, :interfaces])
|
||
# SQL optimizations queries
|
||
@last_report_ids = Report.where(:host_id => @hosts.map(&:id)).group(:host_id).maximum(:id)
|
||
@last_reports = Report.where(:id => @last_report_ids.values)
|
||
end
|
||
|
||
api :GET, "/hosts/:id/", N_("Show a host")
|
||
... | ... | |
process_response @host.destroy
|
||
end
|
||
|
||
api :GET, "/hosts/:id/status", N_("Get status of host")
|
||
api :GET, "/hosts/:id/status", N_("Get configuration status of host")
|
||
param :id, :identifier_dottable, :required => true
|
||
description <<-eos
|
||
Return value may either be one of the following:
|
||
... | ... | |
eos
|
||
|
||
def status
|
||
render :json => { :status => @host.host_status }.to_json if @host
|
||
Foreman::Deprecation.api_deprecation_warning('The /status route is deprecated, please use the new /status/configuration instead')
|
||
render :json => { :status => @host.get_status(HostStatus::ConfigurationStatus).to_label }.to_json if @host
|
||
end
|
||
|
||
api :GET, "/hosts/:id/status/:type", N_("Get status of host")
|
||
param :id, :identifier_dottable, :required => true
|
||
param :type, [ HostStatus::Global ] + HostStatus.status_registry.to_a.map { |s| s.humanized_name }, :required => true, :desc => N_(<<-eos
|
||
status type, can be one of
|
||
* global
|
||
* configuration
|
||
* build
|
||
eos
|
||
)
|
||
description N_('Returns string representing a host status of a given type')
|
||
def get_status
|
||
case params[:type]
|
||
when 'global'
|
||
@status = @host.build_global_status
|
||
else
|
||
@status = @host.get_status(HostStatus.find_status_by_humanized_name(params[:type]))
|
||
end
|
||
end
|
||
|
||
api :GET, "/hosts/:id/vm_compute_attributes", N_("Get vm attributes of host")
|
||
... | ... | |
:console
|
||
when 'disassociate'
|
||
:edit
|
||
when 'vm_compute_attributes'
|
||
when 'vm_compute_attributes', 'get_status'
|
||
:view
|
||
else
|
||
super
|
Also available in: Unified diff
Fixes #10782 - global host status
Introduce new global host status that is composed of host substatuses.Each substatus defines a mapping to the global one which can result in
three values
Plugins can add their own substatuses. These are automatically
propagated also to API.
Thanks to Tomas Strachota who wrote the original code.