Class: VirtualBox::DVD
- Inherits:
-
Image
- Object
- AbstractModel
- Image
- VirtualBox::DVD
- Defined in:
- lib/virtualbox/dvd.rb
Overview
Represents a DVD image stored by VirtualBox. These DVD images can be mounted onto virtual machines.
Finding all DVDs
The only method at the moment of finding DVDs is to use DVD.all, which returns an array of DVDs.
DVD.all
Empty Drives
Sometimes it is useful to have an empty drive. This is the case where you may have a DVD drive but it has no disk in it. To create an AttachedDevice, an image must be specified, and an empty drive is a simple option. Creating an empty drive is simple:
DVD.empty_drive
Class Method Summary
- + (Object) all Returns an array of all available DVDs as DVD objects.
- + (Object) all_from_command Returns an array of all available DVDs by parsing the VBoxManage output.
- + (DVD) empty_drive Returns an empty drive.
- + (Object) populate_relationship(caller, doc)
Instance Method Summary
- - (Boolean) destroy(raise_errors = false) Deletes the DVD from VBox managed list and also from disk.
- - (Boolean) empty_drive? Override of Image#empty_drive?.
- - (Object) image_type Override of Image#image_type.
- - (DVD) initialize(*args) constructor A new instance of DVD.
- - (Object) load_attribute(name) Lazy load the lazy attributes for this model.
Methods inherited from Image
#filename, parse_block, parse_blocks, parse_raw, set_relationship
Methods included from SubclassListing
Methods inherited from AbstractModel
#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
- (DVD) initialize(*args)
A new instance of DVD
65 66 67 68 69 70 71 |
# File 'lib/virtualbox/dvd.rb', line 65 def initialize(*args) if args.length == 1 && args[0] == :empty_drive @empty_drive = true else super end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class VirtualBox::AbstractModel::Dirty
Class Method Details
+ (Object) all
Returns an array of all available DVDs as DVD objects
24 25 26 |
# File 'lib/virtualbox/dvd.rb', line 24 def all Global.global.media.dvds end |
+ (Object) all_from_command
Returns an array of all available DVDs by parsing the VBoxManage output
30 31 32 33 |
# File 'lib/virtualbox/dvd.rb', line 30 def all_from_command raw = Command.vboxmanage("list", "dvds") parse_raw(raw) end |
+ (DVD) empty_drive
Returns an empty drive. This is useful for creating new or modifyingn existing AttachedDevice objects and attaching an empty drive to them.
40 41 42 |
# File 'lib/virtualbox/dvd.rb', line 40 def empty_drive new(:empty_drive) end |
+ (Object) populate_relationship(caller, doc)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/virtualbox/dvd.rb', line 44 def populate_relationship(caller, doc) result = Proxies::Collection.new(caller) # TODO: Location in this case is relative the vboxconfig path. # We need to expand it. Also, size/accessible is not available. doc.css("MediaRegistry DVDImages Image").each do |hd_node| data = {} hd_node.attributes.each do |key, value| data[key.downcase.to_sym] = value.to_s end # Massage UUID to proper format data[:uuid] = data[:uuid][1..-2] result << new(data) end result end |
Instance Method Details
- (Boolean) destroy(raise_errors = false)
Deletes the DVD from VBox managed list and also from disk. This method will fail if the disk is currently mounted to any virtual machine. This method also does nothing for empty drives (see DVD.empty_drive) and will return false automatically in that case.
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/virtualbox/dvd.rb', line 95 def destroy(raise_errors=false) return false if empty_drive? Command.vboxmanage("closemedium", "dvd", uuid, "--delete") Global.reload! true rescue Exceptions::CommandFailedException raise if raise_errors false end |
- (Boolean) empty_drive?
Override of Image#empty_drive?. This will only be true if the DVD was created with DVD.empty_drive.
77 78 79 |
# File 'lib/virtualbox/dvd.rb', line 77 def empty_drive? @empty_drive || false end |
- (Object) image_type
Override of Image#image_type.
82 83 84 |
# File 'lib/virtualbox/dvd.rb', line 82 def image_type "dvddrive" end |
- (Object) load_attribute(name)
Lazy load the lazy attributes for this model.
107 108 109 110 111 112 |
# File 'lib/virtualbox/dvd.rb', line 107 def load_attribute(name) # Since the lazy attributes are related, we just load them all at once loaded_image = self.class.all_from_command.detect { |o| o.uuid == self.uuid } write_attribute(:accessible, loaded_image.accessible) end |