Class: Vagrant::Driver::VirtualBox

Inherits:
VirtualBoxBase show all
Extended by:
Forwardable
Defined in:
lib/vagrant/driver/virtualbox.rb

Overview

This class contains the logic to drive VirtualBox.

Read the VirtualBoxBase source for documentation on each method.

Defined Under Namespace

Classes: VMNotFound

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from VirtualBoxBase

#clear_forwarded_ports, #clear_shared_folders, #create_dhcp_server, #create_host_only_network, #delete, #delete_unused_host_only_networks, #discard_saved_state, #enable_adapters, #execute, #execute_command, #export, #forward_ports, #halt, #import, #raw, #read_bridged_interfaces, #read_forwarded_ports, #read_guest_additions_version, #read_host_only_interfaces, #read_mac_address, #read_machine_folder, #read_network_interfaces, #read_state, #read_used_ports, #read_vms, #set_mac_address, #share_folders, #ssh_port, #start, #suspend, #verify!, #verify_image, #vm_exists?

Methods included from Util::Retryable

#retryable

Constructor Details

#initialize(uuid) ⇒ VirtualBox



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
# File 'lib/vagrant/driver/virtualbox.rb', line 26

def initialize(uuid)
  # Setup the base
  super()

  @logger = Log4r::Logger.new("vagrant::driver::virtualbox")
  @uuid = uuid

  # Read and assign the version of VirtualBox we know which
  # specific driver to instantiate.
  begin
    @version = read_version || ""
  rescue Subprocess::LaunchError
    # This means that VirtualBox was not found, so we raise this
    # error here.
    raise Errors::VirtualBoxNotDetected
  end

  # Instantiate the proper version driver for VirtualBox
  @logger.debug("Finding driver for VirtualBox version: #{@version}")
  driver_map   = {
    "4.0" => VirtualBox_4_0,
    "4.1" => VirtualBox_4_1
  }

  driver_klass = nil
  driver_map.each do |key, klass|
    if @version.start_with?(key)
      driver_klass = klass
      break
    end
  end

  if !driver_klass
    supported_versions = driver_map.keys.sort.join(", ")
    raise Errors::VirtualBoxInvalidVersion, :supported_versions => supported_versions
  end

  @logger.info("Using VirtualBox driver: #{driver_klass}")
  @driver = driver_klass.new(@uuid)

  if @uuid
    # Verify the VM exists, and if it doesn't, then don't worry
    # about it (mark the UUID as nil)
    raise VMNotFound if !@driver.vm_exists?(@uuid)
  end
end

Instance Attribute Details

#uuidObject (readonly)

The UUID of the virtual machine we represent



21
22
23
# File 'lib/vagrant/driver/virtualbox.rb', line 21

def uuid
  @uuid
end

#versionObject (readonly)

The version of virtualbox that is running.



24
25
26
# File 'lib/vagrant/driver/virtualbox.rb', line 24

def version
  @version
end