Project

General

Profile

Revision e6eb1c48

Added by Dmitri Dolguikh over 8 years ago

fixes #8033: container power on/off redirects to container view now

View differences:

app/controllers/containers_controller.rb
1 1
class ContainersController < ::ApplicationController
2 2
  include ForemanDocker::FindContainer
3 3

  
4
  before_filter :find_container, :only => [:show, :commit]
4
  before_filter :find_container, :only => [:show, :commit, :power]
5 5

  
6 6
  def index
7 7
    @container_resources = allowed_resources
......
48 48
      { :container => @container, :e => e }
49 49
  end
50 50

  
51
  def power
52
    compute_resource = @container.compute_resource
53
    @docker_container = compute_resource.find_vm_by_uuid(@container.uuid)
54
    run_container_action(@docker_container.ready? ? :stop : :start)
55
  end
56

  
57
  def run_container_action(action)
58
    if @docker_container.send(action)
59
      @docker_container.reload
60
      notice _("%{vm} is now %{vm_state}") %
61
        { :vm => @docker_container, :vm_state => @docker_container.state.capitalize }
62
      redirect_to containers_path(:id => @container.id)
63
    else
64
      error _("failed to %{action} %{vm}") % { :action => _(action), :vm => @docker_container }
65
      redirect_to :back
66
    end
67
    # This should only rescue Fog::Errors, but Fog returns all kinds of errors...
68
  rescue => e
69
    error _("Error - %{message}") % { :message => _(e.message) }
70
    redirect_to :back
71
  end
72

  
51 73
  private
52 74

  
53 75
  def action_permission
......
56 78
      :view
57 79
    when 'commit'
58 80
      :commit
81
    when 'power'
82
      :power_compute_resources_vms
83
    else
84
      super
85
    end
86
  end
87

  
88
  def current_permission
89
    if params[:action] == 'power'
90
      :power_compute_resources_vms
59 91
    else
60 92
      super
61 93
    end

Also available in: Unified diff