foreman/app/controllers/fact_values_controller.rb @ 358ec5a3
358ec5a3 | Dominic Cleal | require 'foreman/controller/smart_proxy_auth'
|
|
46ac4aa8 | Ohad Levy | class FactValuesController < ApplicationController
|
|
c76afe1f | Ohad Levy | include Foreman::Controller::AutoCompleteSearch
|
|
358ec5a3 | Dominic Cleal | include Foreman::Controller::SmartProxyAuth
|
|
c76afe1f | Ohad Levy | ||
358ec5a3 | Dominic Cleal | add_puppetmaster_filters :create
|
|
6032a1ff | Ohad Levy | before_filter :setup_search_options, :only => :index
|
|
1ba05a93 | Ohad Levy | ||
b729fb04 | Paul Kelly | def index
|
|
6032a1ff | Ohad Levy | begin
|
|
c9579050 | Greg Sutcliffe | values = FactValue.my_facts.no_timestamp_facts.search_for(params[:search],:order => params[:order])
|
|
6032a1ff | Ohad Levy | rescue => e
|
|
error e.to_s
|
|||
aa729377 | Amos Benari | values = FactValue.no_timestamp_facts.search_for ""
|
|
6032a1ff | Ohad Levy | end
|
|
c76afe1f | Ohad Levy | ||
22712cbd | Ohad Levy | respond_to do |format|
|
|
format.html do
|
|||
5d264a2d | Ohad Levy | @fact_values = values.required_fields.paginate :page => params[:page]
|
|
22712cbd | Ohad Levy | end
|
|
format.json do
|
|||
6032a1ff | Ohad Levy | render :json => FactValue.build_facts_hash(values.all(:include => [:fact_name, :host]))
|
|
22712cbd | Ohad Levy | end
|
|
end
|
|||
46ac4aa8 | Ohad Levy | end
|
|
363141af | Ohad Levy | def create
|
|
2d86bf9e | Ohad Levy | Taxonomy.no_taxonomy_scope do
|
|
imported = Host.importHostAndFacts params.delete("facts")
|
|||
respond_to do |format|
|
|||
format.yml {
|
|||
if imported
|
|||
render :text => "Imported facts", :status => 200 and return
|
|||
else
|
|||
render :text => "Failed to import facts", :status => 400
|
|||
end
|
|||
}
|
|||
end
|
|||
363141af | Ohad Levy | end
|
|
71291a46 | Dmitri Dolguikh | rescue Exception => e
|
|
399dca9e | Ohad Levy | logger.warn "Failed to import facts: #{e}"
|
|
render :text => "Failed to import facts: #{e}", :status => 400
|
|||
363141af | Ohad Levy | end
|
|
46ac4aa8 | Ohad Levy | end
|