Class: VirtualBox::Vm::Nic
- Inherits:
-
Object
- Object
- VirtualBox::Vm::Nic
- Defined in:
- lib/virtual_box/vm/nic.rb
Overview
Configuration for a network card.
Instance Attribute Summary collapse
-
#chip ⇒ Symbol
The NIC controller chip.
-
#mac ⇒ String
MAC address for the network card, as a hexadecimal string.
-
#mode ⇒ Symbol
The kind of network emulation implemented on this card.
-
#net_name ⇒ Symbol
Name of the virtual network that the NIC is connected to.
-
#trace_file ⇒ String
Path to a file that logs a network trace for the VM.
Instance Method Summary collapse
-
#from_params(params, nic_id) ⇒ VirtualBox::Vm::Nic
Parses “VBoxManage showvminfo –machinereadable” output into this instance.
-
#initialize(options = {}) ⇒ Nic
constructor
Creates a NIC with the given attributes.
-
#to_hash ⇒ Hash<Symbol, Object>
Hash capturing this specification.
-
#to_params(nic_id) ⇒ Array<String>
Arguments to “VBoxManage modifyvm” describing the NIC.
Constructor Details
#initialize(options = {}) ⇒ Nic
Creates a NIC with the given attributes.
78 79 80 |
# File 'lib/virtual_box/vm/nic.rb', line 78 def initialize( = {}) .each { |k, v| self.send :"#{k}=", v } end |
Instance Attribute Details
#chip ⇒ Symbol
The NIC controller chip.
Can be one of the following values:
- :amd
-
AMD PCNet FAST III (good default)
- :intel
-
Intel PRO/1000 MT Server (for newer Windows systems)
- :intel_xp
-
Intel PRO/1000 MT Server (for Windows XP)
- :virtio
-
fake card optimized for virtualization (custom drivers needed)
27 28 29 |
# File 'lib/virtual_box/vm/nic.rb', line 27 def chip @chip end |
#mac ⇒ String
MAC address for the network card, as a hexadecimal string.
The format for specifying MACs is ‘0123456789AB’. A random MAC will be generated if one is not assigned.
44 45 46 |
# File 'lib/virtual_box/vm/nic.rb', line 44 def mac @mac end |
#mode ⇒ Symbol
The kind of network emulation implemented on this card.
Can be one of the following values:
- :nat
-
uses VirtualBox internal NAT engine to hide under host OS
- :bridged
-
bypasses host OS, connects directly to a network interface
- :host
-
virtual network connecting guest to host
- :virtual
-
virtual network connecting multiple guests
17 18 19 |
# File 'lib/virtual_box/vm/nic.rb', line 17 def mode @mode end |
#net_name ⇒ Symbol
Name of the virtual network that the NIC is connected to.
The identifier differs depending on the networking mode:
- :nat
-
not applicable
- :bridged
-
name of the bridge network interface on the host
- :host
-
name of the host-only network interface
- :virtual
-
virtual network name
37 38 39 |
# File 'lib/virtual_box/vm/nic.rb', line 37 def net_name @net_name end |
#trace_file ⇒ String
Path to a file that logs a network trace for the VM.
Can be null to disable tracing.
50 51 52 |
# File 'lib/virtual_box/vm/nic.rb', line 50 def trace_file @trace_file end |
Instance Method Details
#from_params(params, nic_id) ⇒ VirtualBox::Vm::Nic
Parses “VBoxManage showvminfo –machinereadable” output into this instance.
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 166 167 168 169 170 |
# File 'lib/virtual_box/vm/nic.rb', line 134 def from_params(params, nic_id) case params["nic#{nic_id}"] when 'nat' self.mode = :nat when 'bridged' self.mode = :bridged self.net_name = params["bridgeadapter#{nic_id}"] when 'intnet' self.mode = :virtual self.net_name = params["intnet#{nic_id}"] when 'hostonly' self.mode = :host self.net_name = params["hostonlyadapter#{nic_id}"] end self.chip = case params["nictype#{nic_id}"] when 'Am79C970A', 'Am79C973', :amd when '82543GC' :intel_xp when '82540OEM', '82545EM' :intel when 'virtio' :virtual else (self.mode == :virtual) ? :virtual : :amd end self.mac = params["macaddress#{nic_id}"] if params["nictrace#{nic_id}"] == 'on' self.trace_file = params["nictracefile#{nic_id}"] else self.trace_file = nil end self end |
#to_hash ⇒ Hash<Symbol, Object>
Hash capturing this specification. Can be passed to Nic#new.
176 177 178 179 |
# File 'lib/virtual_box/vm/nic.rb', line 176 def to_hash { :mode => mode, :chip => chip, :net_name => net_name, :mac => mac, :trace_file => trace_file } end |
#to_params(nic_id) ⇒ Array<String>
Arguments to “VBoxManage modifyvm” describing the NIC.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/virtual_box/vm/nic.rb', line 87 def to_params(nic_id) params = [] params.push "--nic#{nic_id}" case mode when :nat params.push 'nat' when :bridged params.push 'bridged', "--bridgeadapter#{nic_id}", net_name when :virtual params.push 'intnet', "--intnet#{nic_id}", net_name when :host params.push 'hostonly', "--hostonlyadapter#{nic_id}", net_name else params.push 'null' end params.push "--nictype#{nic_id}", case chip when :amd 'Am79C973' when :intel '82545EM' when :intel_xp '82543GC' when :virtual 'virtio' end params.push "--cableconnected#{nic_id}", 'on' params.push "--macaddress#{nic_id}", mac if mac params.push "--nictrace#{nic_id}" if trace_file params.push 'on', "--nictracefile#{nic_id}", trace_file else params.push 'off' end params end |