Class: ComputeResourcesController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch
Defined in:
app/controllers/compute_resources_controller.rb

Constant Summary collapse

AJAX_REQUESTS =
%w{hardware_profile_selected cluster_selected}

Instance Method Summary collapse

Methods included from Foreman::Controller::AutoCompleteSearch

#auto_complete_search, #invalid_search_query

Methods inherited from ApplicationController

#api_request?, #welcome

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread, included

Instance Method Details

#cluster_selectedObject


104
105
106
107
108
109
# File 'app/controllers/compute_resources_controller.rb', line 104

def cluster_selected
  networks = @compute_resource.networks(:cluster_id => params[:cluster_id])
  respond_to do |format|
    format.json { render :json => networks }
  end
end

#createObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/compute_resources_controller.rb', line 32

def create
  if params[:compute_resource].present? && params[:compute_resource][:provider].present?
    @compute_resource = ComputeResource.new_provider params[:compute_resource]
    if @compute_resource.save
      # Add the new compute resource to the user's filters
      @compute_resource.users << User.current
      process_success :success_redirect => @compute_resource
    else
      process_error
    end
  else
    @compute_resource = ComputeResource.new params[:compute_resource]
    @compute_resource.valid?
    process_error
  end
end

#destroyObject


61
62
63
64
65
66
67
# File 'app/controllers/compute_resources_controller.rb', line 61

def destroy
  if @compute_resource.destroy
    process_success
  else
    process_error
  end
end

#editObject


49
50
# File 'app/controllers/compute_resources_controller.rb', line 49

def edit
end

#hardware_profile_selectedObject


95
96
97
98
99
100
101
102
# File 'app/controllers/compute_resources_controller.rb', line 95

def hardware_profile_selected
  compute = @compute_resource.hardware_profile(params[:hwp_id])
  compute.interfaces
  compute.volumes
  respond_to do |format|
    format.json { render :json => compute }
  end
end

#indexObject


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/compute_resources_controller.rb', line 7

def index
  begin
    values = ComputeResource.my_compute_resources.search_for(params[:search], :order => params[:order])
  rescue => e
    error e.to_s
    values = ComputeResource.my_compute_resources.search_for ""
  end

  respond_to do |format|
    format.html { @compute_resources = values.paginate :page => params[:page] }
    format.json { render :json => values }
  end
end

#newObject


21
22
23
# File 'app/controllers/compute_resources_controller.rb', line 21

def new
  @compute_resource = ComputeResource.new
end

#pingObject


75
76
77
78
79
# File 'app/controllers/compute_resources_controller.rb', line 75

def ping
  respond_to do |format|
    format.json {render :json => errors_hash(@compute_resource.ping)}
  end
end

#provider_selectedObject

ajax methods


70
71
72
73
# File 'app/controllers/compute_resources_controller.rb', line 70

def provider_selected
  @compute_resource = ComputeResource.new_provider :provider => params[:provider]
  render :partial => "compute_resources/form", :locals => { :compute_resource => @compute_resource }
end

#showObject


25
26
27
28
29
30
# File 'app/controllers/compute_resources_controller.rb', line 25

def show
  respond_to do |format|
    format.html
    format.json { render :json => @compute_resource }
  end
end

#test_connectionObject


81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/compute_resources_controller.rb', line 81

def test_connection
  # cr_id is posted from AJAX function. cr_id is nil if new
  Rails.logger.info "CR_ID IS #{params[:cr_id]}"
  if params[:cr_id].present? && params[:cr_id] != 'null'
    @compute_resource = ComputeResource.find(params[:cr_id])
    params[:compute_resource].delete(:password) if params[:compute_resource][:password].blank?
    @compute_resource.attributes = params[:compute_resource]
  else
    @compute_resource = ComputeResource.new_provider(params[:compute_resource])
  end
  @compute_resource.test_connection :force => true
  render :partial => "compute_resources/form", :locals => { :compute_resource => @compute_resource }
end

#updateObject


52
53
54
55
56
57
58
59
# File 'app/controllers/compute_resources_controller.rb', line 52

def update
  params[:compute_resource][:password] = @compute_resource.password if params[:compute_resource][:password].blank?
  if @compute_resource.update_attributes(params[:compute_resource])
    process_success
  else
    process_error
  end
end