Class: VagrantPlugins::HYPERKIT::Action::Boot

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-hyperkit/action/boot.rb

Overview

This runs the configured instance.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Boot

Returns a new instance of Boot.



18
19
20
# File 'lib/vagrant-hyperkit/action/boot.rb', line 18

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/vagrant-hyperkit/action/boot.rb', line 22

def call(env)
  env[:ui].info(" About to launch vm...")
  # Initialize metrics if they haven't been
  env[:metrics] ||= {}

  machine_info_path = File.join(env[:machine].data_dir, "xhyve.json")
  env[:ui].info("machine_info_path #{machine_info_path}")
  if File.exist?(machine_info_path)
    machine_json = File.read(machine_info_path)
    machine_options = JSON.parse(machine_json, :symbolize_names => true)
    log.debug "Machine Options: #{JSON.pretty_generate(machine_options)}"
    machine_uuid = machine_options[:uuid]
    pid = machine_options[:pid]
    mac = machine_options[:mac]
  else
    machine_uuid = uuid(env)
  end

  guest_config = {
    pid: pid,
    mac: mac,
    uuid: machine_uuid,
    cmdline: kernel_command(env),
    memory: memory(env),
    processors: cpus(env),
    binary: xhyve_binary(env),
  }

  xhyve_guest = start_guest(env, guest_config)
  # Immediately save the ID since it is created at this point.
  env[:machine].id = xhyve_guest.uuid

  save_guest_status(env, xhyve_guest)
  # Terminate the instance if we were interrupted
  terminate(env) if env[:interrupted]

  100.times do |i|
    begin
      ssh_try(xhyve_guest.ip, "accanto", "accanto")
    rescue StandardError => e
      env[:ui].error("SSL error: #{e.inspect}")
      redo
    end
  end

  @app.call(env)
end

#recover(env) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/vagrant-hyperkit/action/boot.rb', line 77

def recover(env)
  return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)

  if env[:machine].provider.state.id != :not_created
    # Undo the import
    terminate(env)
  end
end

#ssh_try(host, user, pass) ⇒ Object



70
71
72
73
74
75
# File 'lib/vagrant-hyperkit/action/boot.rb', line 70

def ssh_try(host, user, pass)
  Net::SSH.start( host.to_s, user.to_s, :password => pass.to_s ) do |ssh|
    ssh.exec!('date')
    ssh.close
  end
end

#terminate(env) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/vagrant-hyperkit/action/boot.rb', line 86

def terminate(env)
  destroy_env = env.dup
  destroy_env.delete(:interrupted)
  destroy_env[:config_validate] = false
  destroy_env[:force_confirm_destroy] = true
  env[:action_runner].run(Action.action_destroy, destroy_env)
end