foreman/app/controllers/api/v1/hosts_controller.rb @ e54016da
d076d573 | Joseph Mitchell Magen | module Api
|
|
module V1
|
|||
class HostsController < V1::BaseController
|
|||
8dc8a9ac | Joseph Mitchell Magen | before_filter :find_resource, :only => %w{show update destroy status}
|
|
d076d573 | Joseph Mitchell Magen | ||
api :GET, "/hosts/", "List all hosts."
|
|||
param :search, String, :desc => "Filter results"
|
|||
param :order, String, :desc => "Sort results"
|
|||
param :page, String, :desc => "paginate results"
|
|||
param :per_page, String, :desc => "number of entries per request"
|
|||
def index
|
|||
acfbc458 | Marek Hulan | @hosts = Host.
|
|
authorized(:view_hosts, Host).
|
|||
search_for(*search_options).paginate(paginate_options)
|
|||
d076d573 | Joseph Mitchell Magen | end
|
|
api :GET, "/hosts/:id/", "Show a host."
|
|||
25d4ca6d | Joseph Mitchell Magen | param :id, :identifier_dottable, :required => true
|
|
d076d573 | Joseph Mitchell Magen | ||
def show
|
|||
end
|
|||
api :POST, "/hosts/", "Create a host."
|
|||
param :host, Hash, :required => true do
|
|||
param :name, String, :required => true
|
|||
5638cc68 | Joseph Magen | param :location_id, :number, :required => true, :desc => "required if locations are enabled" if SETTINGS[:locations_enabled]
|
|
param :organization_id, :number, :required => true, :desc => "required if organizations are enabled" if SETTINGS[:organizations_enabled]
|
|||
param :environment_id, String, :desc => "required if host is managed and value is not inherited from host group"
|
|||
param :ip, String, :desc => "not required if using a subnet with DHCP proxy"
|
|||
param :mac, String, :desc => "required for managed host that is bare metal, not required if it's a virtual machine"
|
|||
param :architecture_id, :number, :desc => "required if host is managed and value is not inherited from host group"
|
|||
param :domain_id, :number, :desc => "required if host is managed and value is not inherited from host group"
|
|||
param :realm_id, :number
|
|||
74346b1b | Martin Bačovský | param :puppet_proxy_id, :number
|
|
param :puppet_class_ids, Array
|
|||
5638cc68 | Joseph Magen | param :operatingsystem_id, String, :desc => "required if host is managed and value is not inherited from host group"
|
|
param :medium_id, String, :desc => "required if not imaged based provisioning and host is managed and value is not inherited from host group"
|
|||
param :ptable_id, :number, :desc => "required if host is managed and custom partition has not been defined"
|
|||
param :subnet_id, :number, :desc => "required if host is managed and value is not inherited from host group"
|
|||
param :compute_resource_id, :number, :desc => "nil means host is bare metal"
|
|||
param :root_pass, String, :desc => "required if host is managed and value is not inherited from host group or default password in settings"
|
|||
74346b1b | Martin Bačovský | param :model_id, :number
|
|
d076d573 | Joseph Mitchell Magen | param :hostgroup_id, :number
|
|
param :owner_id, :number
|
|||
param :puppet_ca_proxy_id, :number
|
|||
param :image_id, :number
|
|||
param :host_parameters_attributes, Array
|
|||
74346b1b | Martin Bačovský | param :build, :bool
|
|
param :enabled, :bool
|
|||
param :provision_method, String
|
|||
5638cc68 | Joseph Magen | param :managed, :bool, :desc => "True/False flag whether a host is managed or unmanaged. Note: this value also determines whether several parameters are required or not"
|
|
param :progress_report_id, String, :desc => "UUID to track orchestration tasks status, GET /api/orchestration/:UUID/tasks"
|
|||
626e88b9 | Dominic Cleal | param :comment, String, :desc => "Additional information about this host"
|
|
74346b1b | Martin Bačovský | param :capabilities, String
|
|
5638cc68 | Joseph Magen | param :compute_profile_id, :number
|
|
74346b1b | Martin Bačovský | param :compute_attributes, Hash do
|
|
end
|
|||
d076d573 | Joseph Mitchell Magen | end
|
|
def create
|
|||
@host = Host.new(params[:host])
|
|||
@host.managed = true if (params[:host] && params[:host][:managed].nil?)
|
|||
forward_request_url
|
|||
process_response @host.save
|
|||
end
|
|||
api :PUT, "/hosts/:id/", "Update a host."
|
|||
param :id, :identifier, :required => true
|
|||
param :host, Hash, :required => true do
|
|||
73f028b0 | Joseph Mitchell Magen | param :name, String
|
|
param :environment_id, String
|
|||
d076d573 | Joseph Mitchell Magen | param :ip, String, :desc => "not required if using a subnet with dhcp proxy"
|
|
param :mac, String, :desc => "not required if its a virtual machine"
|
|||
73f028b0 | Joseph Mitchell Magen | param :architecture_id, :number
|
|
param :domain_id, :number
|
|||
param :puppet_proxy_id, :number
|
|||
param :operatingsystem_id, String
|
|||
74346b1b | Martin Bačovský | param :puppet_class_ids, Array
|
|
d076d573 | Joseph Mitchell Magen | param :medium_id, :number
|
|
param :ptable_id, :number
|
|||
param :subnet_id, :number
|
|||
74346b1b | Martin Bačovský | param :compute_resource_id, :number
|
|
d076d573 | Joseph Mitchell Magen | param :sp_subnet_id, :number
|
|
74346b1b | Martin Bačovský | param :model_id, :number
|
|
d076d573 | Joseph Mitchell Magen | param :hostgroup_id, :number
|
|
param :owner_id, :number
|
|||
param :puppet_ca_proxy_id, :number
|
|||
param :image_id, :number
|
|||
param :host_parameters_attributes, Array
|
|||
74346b1b | Martin Bačovský | param :build, :bool
|
|
param :enabled, :bool
|
|||
param :provision_method, String
|
|||
param :managed, :bool
|
|||
bb3916d6 | Ohad Levy | param :progress_report_id, String, :desc => 'UUID to track orchestration tasks status, GET /api/orchestration/:UUID/tasks'
|
|
74346b1b | Martin Bačovský | param :capabilities, String
|
|
param :compute_attributes, Hash do
|
|||
end
|
|||
d076d573 | Joseph Mitchell Magen | end
|
|
def update
|
|||
process_response @host.update_attributes(params[:host])
|
|||
end
|
|||
api :DELETE, "/hosts/:id/", "Delete an host."
|
|||
param :id, :identifier, :required => true
|
|||
def destroy
|
|||
process_response @host.destroy
|
|||
end
|
|||
8dc8a9ac | Joseph Mitchell Magen | api :GET, "/hosts/:id/status", "Get status of host"
|
|
param :id, :identifier_dottable, :required => true
|
|||
bfbf7ed8 | Lukas Zapletal | # TRANSLATORS: API documentation - do not translate
|
|
8dc8a9ac | Joseph Mitchell Magen | description <<-eos
|
|
Return value may either be one of the following:
|
|||
* missing
|
|||
* failed
|
|||
* pending
|
|||
* changed
|
|||
* unchanged
|
|||
* unreported
|
|||
eos
|
|||
def status
|
|||
e54016da | Marek Hulan | 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
|
|||
8dc8a9ac | Joseph Mitchell Magen | end
|
|
d076d573 | Joseph Mitchell Magen | private
|
|
453dc693 | Joseph Magen | def resource_class
|
|
Host::Managed
|
|||
acfbc458 | Marek Hulan | end
|
|
d076d573 | Joseph Mitchell Magen | # this is required for template generation (such as pxelinux) which is not done via a web request
|
|
def forward_request_url
|
|||
@host.request_url = request.host_with_port if @host.respond_to?(:request_url)
|
|||
end
|
|||
end
|
|||
end
|
|||
end
|