Class: ContainersController

Inherits:
ApplicationController
  • Object
show all
Includes:
ForemanDocker::FindContainer
Defined in:
app/controllers/containers_controller.rb

Instance Method Summary collapse

Methods included from ForemanDocker::FindContainer

#allowed_resources, #find_container

Instance Method Details

#commitObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/containers_controller.rb', line 42

def commit
  ForemanDocker::Docker.get_container(@container).commit(:author  => params[:commit][:author],
                                                         :repo => params[:commit][:repo],
                                                         :tag => params[:commit][:tag],
                                                         :comment => params[:commit][:comment])

  process_success :success_redirect => :back,
                  :success_msg      => _("%{container} commit was successful") %
                    { :container => @container }
rescue => e
  process_error :redirect => :back, :error_msg => _("Failed to commit %{container}: %{e}") %
    { :container => @container, :e => e }
end

#destroyObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/containers_controller.rb', line 22

def destroy
  if (deleted_identifier = container_deletion)
    process_success(:success_redirect => containers_path,
                    :success_msg => (_("Container %s is being deleted.") %
                                     deleted_identifier))
  else
    error(_('Your container could not be deleted in Docker'))
    if @container.present?
      process_error(:redirect => containers_path)
    else
      redirect_back(:fallback_location => containers_path)
    end
  end
rescue ActiveRecord::RecordNotFound
  not_found
end

#indexObject



6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/containers_controller.rb', line 6

def index
  @container_resources = allowed_resources
  if @container_resources.empty?
    warning('You need a Compute Resource of type Docker to start managing containers')
    redirect_to new_compute_resource_path
  end
# This should only rescue Fog::Errors, but Fog returns all kinds of errors...
rescue
  process_error
end

#newObject



17
18
19
20
# File 'app/controllers/containers_controller.rb', line 17

def new
  redirect_to wizard_state_step_path(:wizard_state_id => DockerContainerWizardState.create.id,
                                     :id => :preliminary)
end

#powerObject



56
57
58
59
60
# File 'app/controllers/containers_controller.rb', line 56

def power
  compute_resource = @container.compute_resource
  @docker_container = compute_resource.find_vm_by_uuid(@container.uuid)
  run_container_action(@docker_container.ready? ? :stop : :start)
end

#run_container_action(action) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/containers_controller.rb', line 62

def run_container_action(action)
  if @docker_container.send(action)
    @docker_container.reload
    notice _("%{vm} is now %{vm_state}") %
      { :vm => @docker_container, :vm_state => @docker_container.state.capitalize }
    redirect_to containers_path(:id => @container.id)
  else
    error _("failed to %{action} %{vm}") % { :action => _(action), :vm => @docker_container }
    redirect_back(:fallback_location => containers_path)
  end
  # This should only rescue Fog::Errors, but Fog returns all kinds of errors...
rescue => e
  error _("Error - %{message}") % { :message => _(e.message) }
  redirect_back(:fallback_location => containers_path)
end

#showObject



39
40
# File 'app/controllers/containers_controller.rb', line 39

def show
end