Class: VirtualBox::Nic
- Inherits:
-
AbstractModel
- Object
- AbstractModel
- VirtualBox::Nic
- Defined in:
- lib/virtualbox/nic.rb
Overview
Represents a single NIC (Network Interface Card) of a virtual machine.
Currently, new NICs can't be created, so the only way to get this
object is through a VM's nics
relationship.
Editing a NIC
Nics can be modified directly in their relationship to other virtual machines. When VM#save is called, it will also save any changes to its relationships.
vm = VirtualBox::VM.find("foo") vm.nics[0].macaddress = @new_mac_address vm.save
Attributes
Properties of the model are exposed using standard ruby instance methods which are generated on the fly. Because of this, they are not listed below as available instance methods.
These attributes can be accessed and modified via standard ruby-style
instance.attribute
and instance.attribute=
methods. The attributes are
listed below. If you aren't sure what this means or you can't understand
why the below is listed, please read Attributable.
attribute :parent, :readonly => :readonly attribute :nic attribute :nictype attribute :macaddress attribute :cableconnected attribute :bridgeadapter
Class Method Summary
- + (Array<Nic>) populate_relationship(caller, doc) Populates the nic relationship for anything which is related to it.
- + (Object) save_relationship(caller, data) Saves the relationship.
Instance Method Summary
- - (Nic) initialize(caller, data) constructor Since there is currently no way to create a new nic, this is only used internally.
- - (Object) save_attribute(key, value, vmname) Saves a single attribute of the nic.
Methods inherited from AbstractModel
#destroy, #errors, #existing_record!, #inspect, #lazy_attribute?, #lazy_relationship?, #new_record!, #new_record?, #populate_attributes, #populate_relationship, #populate_relationships, reload!, #reload!, reload?, reloaded!, #save, #set_relationship, #validate, #write_attribute
Methods included from AbstractModel::Attributable
#attributes, #has_attribute?, included, #lazy_attribute?, #loaded_attribute?, #populate_attributes, #read_attribute, #readonly_attribute?, #write_attribute
Methods included from AbstractModel::Dirty
#changed?, #changes, #clear_dirty!, #ignore_dirty, #method_missing, #set_dirty!
Methods included from AbstractModel::Relatable
#destroy_relationship, #destroy_relationships, #has_relationship?, included, #lazy_relationship?, #loaded_relationship?, #populate_relationship, #populate_relationships, #read_relationship, #relationship_data, #save_relationship, #save_relationships, #set_relationship
Methods included from AbstractModel::Validatable
#add_error, #clear_errors, #errors, #valid?, #validate, #validates_presence_of
Constructor Details
- (Nic) initialize(caller, data)
Since there is currently no way to create a new nic, this is only used internally. Developers should NOT try to initialize their own nic objects.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/virtualbox/nic.rb', line 74 def initialize(caller, data) super() @index = data["slot"].to_i + 1 # Set the parent write_attribute(:parent, caller) # Convert each attribute value to a string attrs = {} data.attributes.each do |key, value| attrs[key] = value.to_s end populate_attributes(attrs) # The `nic` attribute is a bit more complicated, but not by # much if data["enabled"] == "true" write_attribute(:nic, data.children[1].name.downcase) else write_attribute(:nic, "none") end # Clear dirtiness clear_dirty! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class VirtualBox::AbstractModel::Dirty
Class Method Details
+ (Array<Nic>) populate_relationship(caller, doc)
Populates the nic relationship for anything which is related to it.
This method typically won't be used except internally.
49 50 51 52 53 54 55 56 57 |
# File 'lib/virtualbox/nic.rb', line 49 def populate_relationship(caller, doc) relation = Proxies::Collection.new(caller) doc.css("Hardware Network Adapter").each do |adapter| relation << new(caller, adapter) end relation end |
+ (Object) save_relationship(caller, data)
Saves the relationship. This simply calls #save on every member of the relationship.
This method typically won't be used except internally.
63 64 65 66 67 68 |
# File 'lib/virtualbox/nic.rb', line 63 def save_relationship(caller, data) # Just call save on each nic with the VM data.each do |nic| nic.save(caller.name) end end |
Instance Method Details
- (Object) save_attribute(key, value, vmname)
Saves a single attribute of the nic. This method is automatically called on #save.
This method typically won't be used except internally.
106 107 108 109 |
# File 'lib/virtualbox/nic.rb', line 106 def save_attribute(key, value, vmname) Command.vboxmanage("modifyvm", vmname, "--#{key}#{@index}", value) super end |