15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/vagrant-openstack-plugin/action/create_orchestration_stack.rb', line 15
def call(env)
config = env[:machine].provider_config
if not config.orchestration_stack_name
return @app.call(env)
end
env[:openstack_orchestration] = Fog::Orchestration.new(
env[:fog_openstack_params])
env[:openstack_orchestration].list_stacks.body['stacks'].each do |stack|
if config.orchestration_stack_name == stack['stack_name']
return @app.call(env)
end
end
if [config.orchestration_cfn_template,
config.orchestration_cfn_template_file,
config.orchestration_cfn_template_url].count(nil) != 2
raise Errors::OrchestrationTemplateError,
:err => 'One source for orchestration template should be specified.'
end
stack_params = {
:disable_rollback => false,
:timeout_in_minutes => 5,
}
if config.orchestration_cfn_template
stack_params[:template] = config.orchestration_cfn_template
elsif config.orchestration_cfn_template_file
if not File.exist?(config.orchestration_cfn_template_file)
raise Errors::OrchestrationNoTemplateFileError,
:fname => config.orchestration_cfn_template_file
end
stack_params[:template] = ''
File.open(config.orchestration_cfn_template_file) { |file|
file.each_line do |line|
stack_params[:template] << line
end
}
else
stack_params[:template_url] = config.orchestration_cfn_template_url
end
stack_params[:parameters] = config.orchestration_cfn_template_parameters
env[:ui].info(I18n.t("vagrant_openstack.creating_orchestration_stack"))
stack = env[:openstack_orchestration].create_stack(
config.orchestration_stack_name, stack_params)
created_stacks_fname = env[:machine].data_dir + 'orchestration_stacks'
message = 'Saving information about created orchestration stack '
message << "#{config.orchestration_stack_name}, "
message << "UUID=#{stack.body['stack']['id']} "
message << "to file #{created_stacks_fname}."
@logger.info(message)
File.open(created_stacks_fname, 'a') do |file|
file.puts stack.body['stack']['id']
end
@app.call(env)
end
|