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
|
# File 'lib/vagrant-openstack-plugin/action/delete_orchestration_stack.rb', line 15
def call(env)
config = env[:machine].provider_config
created_stacks_fname = env[:machine].data_dir + 'orchestration_stacks'
if not config.orchestration_stack_destroy or not File.exist?(created_stacks_fname)
env[:machine].id = nil
return @app.call(env)
end
env[:openstack_orchestration] = Fog::Orchestration.new(
env[:fog_openstack_params])
available_stacks = env[:openstack_orchestration].list_stacks.body['stacks']
stacks_to_delete = []
File.open(created_stacks_fname) { |file|
file.each_line do |stack_id|
stack = find_stack(available_stacks, stack_id.chomp!)
next if not stack
stacks_to_delete << stack
end
}
if stacks_to_delete.length > 0
env[:ui].info(I18n.t("vagrant_openstack.deleting_orchestration_stacks"))
end
stacks_to_delete.each do |stack|
@logger.info("Removing orchestration stack #{stack['stack_name']} (#{stack['id']}).")
env[:openstack_orchestration].delete_stack(
stack['stack_name'], stack['id'])
stacks_from_file.delete(stack)
end
@logger.info("Deleting file #{created_stacks_fname}.")
File.delete(created_stacks_fname)
env[:machine].id = nil
@app.call(env)
end
|