Project

General

Profile

Download (1.46 KB) Statistics
| Branch: | Tag: | Revision:

foreman_docker / app / controllers / containers / steps_controller.rb @ f4c209f1

1
module Containers
2
  class StepsController < ::ApplicationController
3
    include Wicked::Wizard
4
    include ForemanDocker::FindContainer
5

    
6
    steps :preliminary, :image, :configuration, :environment
7

    
8
    before_filter :find_state
9
    before_filter :build_state, :only => [:update]
10
    before_filter :set_form, :only => [:show]
11

    
12
    def show
13
      @container_resources = allowed_resources if step == :preliminary
14
      render_wizard
15
    end
16

    
17
    def update
18
      if step == wizard_steps.last
19
        create_container
20
      else
21
        render_wizard @state
22
      end
23
    end
24

    
25
    private
26

    
27
    def find_state
28
      @state = DockerContainerWizardState.find(params[:wizard_state_id])
29
    rescue ActiveRecord::RecordNotFound
30
      not_found
31
    end
32

    
33
    def build_state
34
      @state.send(:"build_#{step}", params[:"docker_container_wizard_states_#{step}"])
35
    end
36

    
37
    def set_form
38
      instance_variable_set(
39
          "@docker_container_wizard_states_#{step}",
40
          @state.send(:"#{step}") || @state.send(:"build_#{step}"))
41
    end
42

    
43
    def create_container
44
      @state.send(:"create_#{step}", params[:"docker_container_wizard_states_#{step}"])
45
      container = Service::Containers.start_container!(@state)
46
      if container.present?
47
        process_success(:object => container, :success_redirect => container_path(container))
48
      else
49
        @environment = @state.environment
50
        process_error(:object => @state.environment, :render => 'environment')
51
      end
52
    end
53
  end
54
end