Class: VirtualBox::Vm::IoBus
- Inherits:
-
Object
- Object
- VirtualBox::Vm::IoBus
- Defined in:
- lib/virtual_box/vm/io_bus.rb
Overview
Specification for a IO controller attached to a virtual machine.
Instance Attribute Summary collapse
-
#bootable ⇒ Boolean
True if the VM BIOS considers this controller bootable.
-
#bus ⇒ Symbol
The kind of bus used by this controller.
-
#chip ⇒ Symbol
The chipset simulated by the IO controller.
-
#disks ⇒ Hash<Array<Integer>, VirtualBox::Vm::Disk>
The disks connected to this controller’s bus.
-
#max_ports ⇒ Integer
The maximum number of I/O devices supported by this controller.
-
#name ⇒ String
A user-friendly name for the I/O controller.
-
#no_cache ⇒ Boolean
True if the controller’s I/O bypasses the host OS cache.
Instance Method Summary collapse
-
#add_bus_to(vm) ⇒ VirtualBox::Vm::IoBus
Adds this IO bus to a virtual machine.
-
#add_to(vm) ⇒ VirtualBox::Vm::IoBus
Adds this IO bus and all its disks to a virtual machine.
-
#first_free_port ⇒ Integer
Finds an unused port on this IO controller’s bus.
-
#from_params(params, bus_id) ⇒ VirtualBox::Vm::IoBus
Parses “VBoxManage showvminfo –machinereadable” output into this instance.
-
#initialize(options = {}) ⇒ IoBus
constructor
Creates a new IO controller specification based on the given attributes.
-
#remove_from(vm) ⇒ VirtualBox::Vm::IoBus
Removes this IO bus from a virtual machine.
-
#to_hash ⇒ Hash<Symbol, Object>
Hash capturing this specification.
-
#to_params ⇒ Array<String>
Parameters for “VBoxManage storagectl” to add this IO bus to a VM.
Constructor Details
#initialize(options = {}) ⇒ IoBus
Creates a new IO controller specification based on the given attributes.
232 233 234 235 |
# File 'lib/virtual_box/vm/io_bus.rb', line 232 def initialize( = {}) @disks = {} .each { |k, v| self.send :"#{k}=", v } end |
Instance Attribute Details
#bootable ⇒ Boolean
True if the VM BIOS considers this controller bootable.
33 34 35 |
# File 'lib/virtual_box/vm/io_bus.rb', line 33 def bootable @bootable end |
#bus ⇒ Symbol
The kind of bus used by this controller.
The following bus types are recognized: :ide, :sata, :sas, :scsi, :floppy.
18 19 20 |
# File 'lib/virtual_box/vm/io_bus.rb', line 18 def bus @bus end |
#chip ⇒ Symbol
The chipset simulated by the IO controller
The following chipsets are recogniezd:
- IDE
-
:piix3, :piix4, and :ich6
- SATA
-
:ahci (Intel AHCI)
- SCSI
-
:lsi_logic and :bus_logic
- SAS
-
lsi_logic_sas
- Floppy
-
:i82078
29 30 31 |
# File 'lib/virtual_box/vm/io_bus.rb', line 29 def chip @chip end |
#disks ⇒ Hash<Array<Integer>, VirtualBox::Vm::Disk>
The disks connected to this controller’s bus.
45 46 47 |
# File 'lib/virtual_box/vm/io_bus.rb', line 45 def disks @disks end |
#max_ports ⇒ Integer
The maximum number of I/O devices supported by this controller.
41 42 43 |
# File 'lib/virtual_box/vm/io_bus.rb', line 41 def max_ports @max_ports end |
#name ⇒ String
A user-friendly name for the I/O controller.
I/O controller names must be unique within the scope of a virtual machine. VirtualBox uses “IDE Controller” and “SATA Controller” as default names.
12 13 14 |
# File 'lib/virtual_box/vm/io_bus.rb', line 12 def name @name end |
#no_cache ⇒ Boolean
True if the controller’s I/O bypasses the host OS cache.
37 38 39 |
# File 'lib/virtual_box/vm/io_bus.rb', line 37 def no_cache @no_cache end |
Instance Method Details
#add_bus_to(vm) ⇒ VirtualBox::Vm::IoBus
Adds this IO bus to a virtual machine.
222 223 224 225 226 |
# File 'lib/virtual_box/vm/io_bus.rb', line 222 def add_bus_to(vm) VirtualBox.run_command! ['VBoxManage', '--nologo', 'storagectl', vm.uid].concat(to_params) self end |
#add_to(vm) ⇒ VirtualBox::Vm::IoBus
Adds this IO bus and all its disks to a virtual machine.
198 199 200 201 202 203 204 |
# File 'lib/virtual_box/vm/io_bus.rb', line 198 def add_to(vm) add_bus_to vm disks.each do |port_device, disk| disk.add_to vm, self, port_device.first, port_device.last end self end |
#first_free_port ⇒ Integer
Finds an unused port on this IO controller’s bus.
252 253 254 |
# File 'lib/virtual_box/vm/io_bus.rb', line 252 def first_free_port disks.empty? ? 0 : disks.keys.min.first + 1 end |
#from_params(params, bus_id) ⇒ VirtualBox::Vm::IoBus
Parses “VBoxManage showvminfo –machinereadable” output into this instance.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/virtual_box/vm/io_bus.rb', line 132 def from_params(params, bus_id) self.name = params["storagecontrollername#{bus_id}"] self.bootable = params["storagecontrollerbootable#{bus_id}"] == 'on' self.max_ports = params["storagecontrollermaxportcount#{bus_id}"].to_i case params["storagecontrollertype#{bus_id}"] when 'PIIX3' self.chip = :piix3 when 'PIIX4' self.chip = :piix4 when 'ICH6' self.chip = :ich6 when 'IntelAhci' self.chip = :ahci when 'LsiLogic' self.chip = :lsi_logic when 'BusLogic' self.chip = :bus_logic when 'LSILogicSAS' self.chip = :lsi_logic_sas when 'I82078' self.chip = :i82078 end self.no_cache = nil image_re = /\A#{name}-(\d+)-(\d+)\Z/ @disks = {} params.each do |key, value| next unless match = image_re.match(key) next if value == 'none' port, device = match[1].to_i, match[2].to_i @disks[[port, device]] = VirtualBox::Vm::Disk.new :file => value end self end |
#remove_from(vm) ⇒ VirtualBox::Vm::IoBus
Removes this IO bus from a virtual machine.
211 212 213 214 215 |
# File 'lib/virtual_box/vm/io_bus.rb', line 211 def remove_from(vm) VirtualBox.run_command! ['VBoxManage', '--nologo', 'storagectl', vm.uuid, '--name', name, '--remove'] self end |
#to_hash ⇒ Hash<Symbol, Object>
Hash capturing this specification. Can be passed to IoBus#new.
241 242 243 244 245 246 247 248 |
# File 'lib/virtual_box/vm/io_bus.rb', line 241 def to_hash disk_hashes = disks.map do |port_device, disk| disk.to_hash.merge! :port => port_device.first, :device => port_device.last end { :name => name, :bus => bus, :chip => chip, :bootable => bootable, :no_cache => no_cache, :max_ports => max_ports, :disks => disk_hashes } end |
#to_params ⇒ Array<String>
Parameters for “VBoxManage storagectl” to add this IO bus to a VM.
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/virtual_box/vm/io_bus.rb', line 171 def to_params params = [] params.push '--name', name params.push '--add', bus.to_s params.push '--controller', case chip when :piix3, :piix4, :ich6, :i82078 chip.to_s.upcase when :ahci 'IntelAhci' when :lsi_logic 'LsiLogic' when :bus_logic 'BusLogic' when :lsi_logic_sas 'LSILogicSAS' end params.push '--sataportcount', max_ports.to_s params.push '--hostiocache', (no_cache ? 'off' : 'on') params.push '--bootable', (bootable ? 'on' : 'off') end |