Class: VagrantPlugins::Openstack::Action::CreateServer

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-openstack-provider/action/create_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ CreateServer



14
15
16
17
# File 'lib/vagrant-openstack-provider/action/create_server.rb', line 14

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

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  @logger.info 'Start create server action'

  nova = env[:openstack_client].nova

  options = {
    flavor: resolve_flavor(env),
    image: resolve_image(env),
    networks: resolve_networks(env),
    keypair_name: resolve_keypair(env),
    availability_zone: env[:machine].provider_config.availability_zone
  }
  server_id = create_server(env, options)

  # Store the ID right away so we can track it
  env[:machine].id = server_id

  waiting_for_server_to_be_build(env, server_id)

  floating_ip = resolve_floating_ip(env)
  if floating_ip && !floating_ip.empty?
    @logger.info "Using floating IP #{floating_ip}"
    env[:ui].info(I18n.t('vagrant_openstack.using_floating_ip', floating_ip: floating_ip))
    nova.add_floating_ip(env, server_id, floating_ip)
  end

  unless env[:interrupted]
    # Clear the line one more time so the progress is removed
    env[:ui].clear_line

    # Wait for SSH to become available
    ssh_timeout = env[:machine].provider_config.ssh_timeout
    unless port_open?(env, floating_ip, 22, ssh_timeout)
      env[:ui].error(I18n.t('vagrant_openstack.timeout'))
      fail Errors::SshUnavailable, host: floating_ip, timeout: ssh_timeout
    end

    @logger.info 'The server is ready'
    env[:ui].info(I18n.t('vagrant_openstack.ready'))
  end

  @app.call(env)
end