Class: VirtualBox::StorageController

Inherits:
AbstractModel show all
Defined in:
lib/virtualbox/storage_controller.rb

Overview

Represents a single storage controller which can be attached to a virtual machine.

Currently, storage controllers can not be created from scratch. Therefore, the only way to use this model is through a relationship of a VM object.

Attributes and Relationships

Properties of the storage controller 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.

Relationships are also accessed like attributes but can't be set. Instead, they are typically references to other objects such as an AttachedDevice which in turn have their own attributes which can be modified.

Attributes

This is copied directly from the class header, but lists all available attributes. If you don't understand what this means, read Attributable.

attribute :parent, :readonly => true
attribute :name
attribute :type
attribute :max_ports, :populate_key => :maxportcount
attribute :ports, :populate_key => :portcount

Relationships

In addition to the basic attributes, a virtual machine is related to other things. The relationships are listed below. If you don't understand this, read Relatable.

relationship :devices, AttachedDevice, :dependent => :destroy

Class Method Summary

Instance Method Summary

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, #save_attribute, #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

- (StorageController) initialize(index, caller, data)

Since storage controllers still can't be created from scratch, this method shouldn't be called. Instead, storage controllers can be retrieved through relationships of other models such as VM.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/virtualbox/storage_controller.rb', line 89

def initialize(index, caller, data)
  super()

  @index = index

  # Setup the index specific attributes
  populate_data = {}
  data.attributes.each do |key,value|
    populate_data[key.downcase.to_sym] = value.to_s
  end

  populate_attributes(populate_data.merge({:parent => caller}), :ignore_relationships => true)
  populate_relationship(:devices, data)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class VirtualBox::AbstractModel::Dirty

Class Method Details

+ (Object) destroy_relationship(caller, data, *args)

Destroys a relationship with another model.

This method typically won't be used except internally.



70
71
72
# File 'lib/virtualbox/storage_controller.rb', line 70

def destroy_relationship(caller, data, *args)
  data.each { |v| v.destroy(*args) }
end

+ (Array<StorageController>) populate_relationship(caller, doc)

Populates a relationship with another model.

This method typically won't be used except internally.

Returns:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/virtualbox/storage_controller.rb', line 55

def populate_relationship(caller, doc)
  relation = Proxies::Collection.new(caller)

  counter = 0
  doc.css("StorageControllers StorageController").each do |sc|
    relation << new(counter, caller, sc)
    counter += 1
  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.



78
79
80
81
82
# File 'lib/virtualbox/storage_controller.rb', line 78

def save_relationship(caller, data)
  data.each do |sc|
    sc.save
  end
end