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

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

Instance Method Summary collapse

Methods inherited from AbstractAction

#call

Constructor Details

#initialize(app, _env, resolver = ConfigResolver.new, utils = Utils.new) ⇒ CreateServer

Returns a new instance of CreateServer.



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

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

Instance Method Details

#execute(env) ⇒ Object



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

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

  config = env[:machine].provider_config

  fail Errors::MissingBootOption if config.image.nil? && config.volume_boot.nil?
  fail Errors::ConflictBootOption unless config.image.nil? || config.volume_boot.nil?

  options = {
    flavor: @resolver.resolve_flavor(env),
    image: @resolver.resolve_image(env),
    volume_boot: @resolver.resolve_volume_boot(env),
    networks: @resolver.resolve_networks(env),
    volumes: @resolver.resolve_volumes(env),
    keypair_name: @resolver.resolve_keypair(env),
    availability_zone: env[:machine].provider_config.availability_zone,
    scheduler_hints: env[:machine].provider_config.scheduler_hints,
    security_groups: @resolver.resolve_security_groups(env),
    user_data: env[:machine].provider_config.user_data,
    metadata: env[:machine].provider_config.
  }

  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_built(env, server_id)
  assign_floating_ip(env, server_id)
  waiting_for_floating_ip_to_be_assigned(env, server_id)
  attach_volumes(env, server_id, options[:volumes]) unless options[:volumes].empty?

  @app.call(env)
end