Class: VagrantPlugins::Vultr::Action::Create

Inherits:
Object
  • Object
show all
Includes:
Helpers::Client
Defined in:
lib/vagrant-vultr/action/create.rb

Instance Method Summary collapse

Methods included from Helpers::Client

#client

Constructor Details

#initialize(app, env) ⇒ Create

Returns a new instance of Create.



9
10
11
12
13
14
# File 'lib/vagrant-vultr/action/create.rb', line 9

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @client = client
  @logger = Log4r::Logger.new('vagrant::vultr::create')
end

Instance Method Details

#call(env) ⇒ Object



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
64
65
66
67
68
69
70
71
72
# File 'lib/vagrant-vultr/action/create.rb', line 16

def call(env)
  region   = env[:machine].provider_config.region
  plan     = env[:machine].provider_config.plan
  os       = env[:machine].provider_config.os
  snapshot = env[:machine].provider_config.snapshot
  enable_ipv6 = env[:machine].provider_config.enable_ipv6
  enable_private_network = env[:machine].provider_config.enable_private_network
  label    = env[:machine].provider_config.label
  tag      = env[:machine].provider_config.tag
  hostname = env[:machine].provider_config.hostname
  ssh_key = env[:machine].provider_config.ssh_key
  startup_script = env[:machine].provider_config.startup_script

  @logger.info "Creating server with:"
  @logger.info "  -- Region: #{region}"
  @logger.info "  -- OS: #{os}"
  @logger.info "  -- Plan: #{plan}"
  @logger.info "  -- Snapshot: #{snapshot}"
  @logger.info "  -- Enable IPv6: #{enable_ipv6}"
  @logger.info "  -- Enable Private Network: #{enable_private_network}"
  @logger.info "  -- Label: #{label}"
  @logger.info "  -- Tag: #{tag}"
  @logger.info "  -- Hostname: #{hostname}"
  @logger.info "  -- Ssh key: #{ssh_key}"
  @logger.info "  -- Startup script: #{startup_script}"

  attributes = {
    region: region,
    os: os,
    plan: plan,
    snapshot: snapshot,
    enable_ipv6: enable_ipv6,
    enable_private_network: enable_private_network,
    label: label,
    tag: tag,
    hostname: hostname,
    ssh_key_name: ssh_key,
    startup_script_name: startup_script,
  }
  @machine.id = @client.create_server(attributes)

  env[:ui].info 'Waiting for subscription to become active...'
  @client.wait_to_activate(@machine.id)

  env[:ui].info 'Waiting for creating ssh config...'
  @client.create_ssh_config(@machine)

  env[:ui].info 'Waiting for server to start...'
  @client.wait_to_power_on(@machine.id)

  env[:ui].info 'Waiting for SSH to become active...'
  @client.wait_for_ssh(@machine)

  env[:ui].info 'Machine is booted and ready to use!'

  @app.call(env)
end