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/error.rb,
lib/virtual_box/vm/nic.rb,
lib/virtual_box/version.rb,
lib/virtual_box/vm/disk.rb,
lib/virtual_box/net/dhcp.rb,
lib/virtual_box/vm/board.rb,
lib/virtual_box/vm/io_bus.rb
Overview
VirtualBox version detection.
Defined Under Namespace
Class Method Summary collapse
-
.ose? ⇒ Boolean
True if the installed VirtualBox is the open-source edition.
-
.reset_version_info! ⇒ NilObject
Removes the cached information on the VirtualBox package version.
-
.run_command(args) ⇒ Hash<Symbol, String>
Runs a command in a sub-shell, waiting until the command completes.
-
.run_command!(args) ⇒ String
Runs a command in a sub-shell, waiting until the command completes.
-
.version ⇒ Hash<Symbol, Object>, Boolean
Version information about the VirtualBox package installed on this machine.
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.
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.
56 57 58 |
# File 'lib/virtual_box/version.rb', line 56 def self.reset_version_info! @version_info = nil end |
.run_command(args) ⇒ Hash<Symbol, String>
Runs a command in a sub-shell, waiting until the command completes.
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/virtual_box/cli.rb', line 14 def self.run_command(args) begin output = Kernel.`(Shellwords.shelljoin(args) + ' 2>&1') { :status => $CHILD_STATUS.exitstatus, :output => output } # TODO(pwnall): this should work, but it makes VirtualBox slow as hell # child = POSIX::Spawn::Child.new(*args) # Hashie::Mash.new :status => child.status.exitstatus, :output => child.out rescue SystemCallError { :status => -1, :output => '' } end end |
.run_command!(args) ⇒ String
Runs a command in a sub-shell, waiting until the command completes.
32 33 34 35 36 |
# File 'lib/virtual_box/cli.rb', line 32 def self.run_command!(args) result = run_command args raise VirtualBox::Error, result unless result[:status] == 0 result[:output] end |
.version ⇒ Hash<Symbol, Object>, Boolean
Version information about the VirtualBox package installed on this machine.
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 = {} 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 = { :release => output, :svn => revision, :edition => edition } end |