Class: VagrantPlugins::XHYVE::Action::Boot

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-xhyve/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.



17
18
19
# File 'lib/vagrant-xhyve/action/boot.rb', line 17

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

Instance Method Details

#call(env) ⇒ Object



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

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")
  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 = SecureRandom.uuid
  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]

  @app.call(env)
end

#recover(env) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/vagrant-xhyve/action/boot.rb', line 59

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

#terminate(env) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/vagrant-xhyve/action/boot.rb', line 68

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