Class: ComputeResourcesVmsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/compute_resources_vms_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#api_request?, #welcome

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread, included

Instance Method Details

#consoleObject


55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/controllers/compute_resources_vms_controller.rb', line 55

def console
  @console = @compute_resource.console @vm.identity
  render case @console[:type]
           when 'spice'
             "hosts/console/spice"
           when 'vnc'
             "hosts/console/vnc"
           else
             "hosts/console/log"
  end
rescue => e
  process_error :redirect => compute_resource_vm_path(@compute_resource, @vm.identity), :error_msg => (_("Failed to set console: %s") % e), :object => @vm
end

#createObject


19
20
21
22
23
24
25
# File 'app/controllers/compute_resources_vms_controller.rb', line 19

def create
  if @compute_resource.create_vm params[:vm]
    process_success :success_redirect => compute_resource_vms_path(@compute_resource)
  else
    process_error :redirect => new_compute_resource_vm_path(@compute_resource), :object => @compute_resource
  end
end

#destroyObject


47
48
49
50
51
52
53
# File 'app/controllers/compute_resources_vms_controller.rb', line 47

def destroy
  if @compute_resource.destroy_vm params[:id]
    process_success({ :success_redirect => compute_resource_vms_path(@compute_resource) })
  else
    process_error({ :redirect => compute_resource_vms_path(@compute_resource) })
  end
end

#indexObject


5
6
7
8
9
10
11
12
13
# File 'app/controllers/compute_resources_vms_controller.rb', line 5

def index
  @vms = @compute_resource.vms.all(params[:filters] || {})
  respond_to do |format|
    format.html
    format.json { render :json => @vms }
  end
rescue => e
  render :partial => 'compute_resources_vms/error', :locals => { :errors => e.message }
end

#newObject


15
16
17
# File 'app/controllers/compute_resources_vms_controller.rb', line 15

def new
  @vm = @compute_resource.new_vm
end

#powerObject


34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/compute_resources_vms_controller.rb', line 34

def power
  action = @vm.ready? ? :stop : :start

  if (@vm.send(action) rescue false)
    @vm.reload
    notice _("%{vm} is now %{vm_state}") % {:vm => @vm, :vm_state => @vm.state.capitalize}
    redirect_to compute_resource_vm_path(:compute_resource_id => params[:compute_resource_id], :id => @vm.identity)
  else
    error _("failed to %{action} %{vm}") % {:action => action, :vm => @vm}
    redirect_to :back
  end
end

#showObject


27
28
29
30
31
32
# File 'app/controllers/compute_resources_vms_controller.rb', line 27

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