Class: VagrantPlugins::Openstack::Action::CreateStack

Inherits:
AbstractAction
  • Object
show all
Defined in:
lib/vagrant-openstack-provider/action/create_stack.rb

Instance Method Summary collapse

Methods inherited from AbstractAction

#call

Constructor Details

#initialize(app, _env) ⇒ CreateStack

Returns a new instance of CreateStack.



16
17
18
19
# File 'lib/vagrant-openstack-provider/action/create_stack.rb', line 16

def initialize(app, _env)
  @app = app
  @logger = Log4r::Logger.new('vagrant_openstack::action::create_stack')
end

Instance Method Details

#execute(env) ⇒ Object



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
# File 'lib/vagrant-openstack-provider/action/create_stack.rb', line 21

def execute(env)
  @logger.info 'Start create stacks action'

  config = env[:machine].provider_config

  heat = env[:openstack_client].heat

  config.stacks.each do |stack|
    env[:ui].info(I18n.t('vagrant_openstack.create_stack'))
    env[:ui].info(" -- Stack Name : #{stack[:name]}")
    env[:ui].info(" -- Template   : #{stack[:template]}")

    create_opts = {
      name: stack[:name],
      template: YAML.load_file(stack[:template])
    }

    stack_id = heat.create_stack(env, create_opts)

    file_path = "#{env[:machine].data_dir}/stack_#{stack[:name]}_id"
    File.write(file_path, stack_id)

    waiting_for_stack_to_be_created(env, stack[:name], stack_id)
  end unless config.stacks.nil?

  @app.call(env)
end