Module: VirtualBox

Defined in:
lib/virtual_box.rb,
lib/virtual_box/vm.rb,
lib/virtual_box/cli.rb,
lib/virtual_box/net.rb,
lib/virtual_box/dhcp.rb,
lib/virtual_box/vm/nic.rb,
lib/virtual_box/version.rb,
lib/virtual_box/vm/disk.rb,
lib/virtual_box/vm/board.rb,
lib/virtual_box/vm/io_bus.rb

Overview

VirtualBox version detection.

Defined Under Namespace

Classes: Dhcp, Net, Vm

Class Method Summary collapse

Class Method Details

.ose?Boolean

True if the installed VirtualBox is the open-source edition.

The open-source edition of VirtualBox has some limitations, such as no support for RDP and USB devices.

Returns:

  • (Boolean)


10
11
12
13
14
15
# File 'lib/virtual_box/version.rb', line 10

def self.ose?
  unless version.edition
    raise 'VirtualBox is not installed on this machine.'
  end
  version.edition == 'OSE'
end

.reset_version_info!NilObject

Removes the cached information on the VirtualBox package version.

Returns:

  • (NilObject)

    nil



56
57
58
# File 'lib/virtual_box/version.rb', line 56

def self.reset_version_info!
  @version_info = nil
end

.run_command(args) ⇒ Hashie::Mash<Symbol, String>

Runs a command in a sub-shell, waiting until the command completes.

Parameters:

  • args (Array<String>)

    the name and arguments for the command to be run

Returns:

  • (Hashie::Mash<Symbol, String>)

    hash with the following keys / methods:

    :status

    the command’s exit status

    :output

    a string with the command’s output



15
16
17
18
# File 'lib/virtual_box/cli.rb', line 15

def self.run_command(args)
  output = Kernel.`(Shellwords.shelljoin(args))
  Hashie::Mash.new :status => $CHILD_STATUS.exitstatus, :output => output
end

.versionHash<Symbol, Object>, Boolean

Version information about the VirtualBox package installed on this machine.

Returns:

  • (Hash<Symbol, Object>, Boolean)

    false if VirtualBox is not installed; otherwise, a hash with the following keys:

    :svn

    (number) the SVN revision that VirtualBox is built off of

    :edition

    the VirtualBox edition (” for the personal edition, ‘OSE’ for the open-source edition)

    :release

    the public release number (e.g. ‘3.0.4’)



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
# File 'lib/virtual_box/version.rb', line 25

def self.version
  return @version_info unless @version_info.nil?
  
  cmd_result = run_command ['VBoxManage', '--version']
  if cmd_result.status != 0
    @version_info = Hashie::Mash.new
    return @version_info
  end
  
  output = cmd_result.output.strip

  if revision_offset = output.rindex('r')
    revision = output[revision_offset + 1, output.length].to_i
    output.slice! revision_offset..-1
  else
    revision = nil
  end
  
  if edition_offset = output.rindex('_')
    edition = output[edition_offset + 1, output.length]
    output.slice! edition_offset..-1
  else
    edition = ''
  end
  
  @version_info = Hashie::Mash.new :release => output, :svn => revision,
                                   :edition => edition
end