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

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

Constant Summary collapse

@@is_created =
false

Instance Method Summary collapse

Methods inherited from AbstractAction

#call

Constructor Details

#initialize(app, _env) ⇒ CreateStack

Returns a new instance of CreateStack.



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

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

Instance Method Details

#execute(env) ⇒ Object



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

def execute(env)
  if @@is_created
    @app.call(env)
    return
  end

  @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?

  @@is_created = true
  @app.call(env)
end