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
|
if process_resource!(@state).nil?
|
20
|
render_wizard @state
|
21
|
else
|
22
|
params[:start_on_create] ? create_container : create_container(false)
|
23
|
end
|
24
|
else
|
25
|
render_wizard @state
|
26
|
end
|
27
|
end
|
28
|
|
29
|
private
|
30
|
|
31
|
def find_state
|
32
|
@state = DockerContainerWizardState.find(params[:wizard_state_id])
|
33
|
rescue ActiveRecord::RecordNotFound
|
34
|
not_found
|
35
|
end
|
36
|
|
37
|
def build_state
|
38
|
s = @state.send(:"build_#{step}", state_params)
|
39
|
instance_variable_set("@docker_container_wizard_states_#{step}", s)
|
40
|
end
|
41
|
|
42
|
def state_params
|
43
|
attrs = case step
|
44
|
when :preliminary
|
45
|
[:wizard_state, :compute_resource_id]
|
46
|
when :image
|
47
|
[:repository_name, :tag, :wizard_state, :registry_id, :capsule_id, :katello]
|
48
|
when :configuration
|
49
|
[:name, :command, :entrypoint, :cpu_set, :cpu_shares, :memory, :wizard_state]
|
50
|
when :environment
|
51
|
[:tty, :docker_container_wizard_state_id,
|
52
|
:attach_stdin, :attach_stdout, :attach_stderr,
|
53
|
:exposed_ports_attributes => [], :environment_variables_attributes => [],
|
54
|
:dns_attributes => []
|
55
|
]
|
56
|
end
|
57
|
|
58
|
params.require("docker_container_wizard_states_#{step}").permit(*attrs)
|
59
|
end
|
60
|
|
61
|
def set_form
|
62
|
instance_variable_set(
|
63
|
"@docker_container_wizard_states_#{step}",
|
64
|
@state.send(:"#{step}") || @state.send(:"build_#{step}"))
|
65
|
end
|
66
|
|
67
|
def create_container(start = true)
|
68
|
@state.send(:"create_#{step}", state_params)
|
69
|
service = Service::Containers.new
|
70
|
container = if start.is_a? TrueClass
|
71
|
service.start_container!(@state)
|
72
|
else
|
73
|
service.create_container!(@state)
|
74
|
end
|
75
|
if container.present?
|
76
|
process_success(:object => container, :success_redirect => container_path(container))
|
77
|
else
|
78
|
@docker_container_wizard_states_environment = @state.environment
|
79
|
process_error(
|
80
|
:redirect => containers_path,
|
81
|
:error_msg => service.full_messages.join(','),
|
82
|
:object => @state.environment)
|
83
|
end
|
84
|
end
|
85
|
end
|
86
|
end
|