lib/virtualbox/hard_drive.rb in virtualbox-0.4.3 vs lib/virtualbox/hard_drive.rb in virtualbox-0.5.0

- old
+ new

@@ -76,25 +76,19 @@ # attribute :format, :default => "VDI" # attribute :size # class HardDrive < Image attribute :format, :default => "VDI" - attribute :size + attribute :size, :lazy => true class <<self # Returns an array of all available hard drives as HardDrive # objects. # - # @param [Boolean] raise_errors If true, {Exceptions::CommandFailedException} - # will be raised if the command failed. # @return [Array<HardDrive>] - def all(raise_errors=false) - raw = Command.vboxmanage("list", "hdds") - parse_blocks(raw).collect { |v| find(v[:uuid], raise_errors) } - rescue Exceptions::CommandFailedException - raise if raise_errors - false + def all + Global.global.media.hard_drives end # Finds one specific hard drive by UUID or file name. If the # hard drive can not be found, will return `nil`. # @@ -115,10 +109,31 @@ new(data) rescue Exceptions::CommandFailedException raise if raise_errors nil end + + def populate_relationship(caller, doc) + result = Proxies::Collection.new(caller) + + doc.css("MediaRegistry HardDisks HardDisk").each do |hd_node| + data = {} + hd_node.attributes.each do |key, value| + data[key.downcase.to_sym] = value.to_s + end + + # Strip the brackets off of UUID + data[:uuid] = data[:uuid][1..-2] + + # Expand location relative to config location + data[:location] = Global.expand_path(data[:location]) if data[:location] + + result << new(data) + end + + result + end end # Clone hard drive, possibly also converting formats. All formats # supported by your local VirtualBox installation are supported # here. If no format is specified, the format of the source drive @@ -212,8 +227,17 @@ Command.vboxmanage("closemedium", "disk", uuid, "--delete") true rescue Exceptions::CommandFailedException raise if raise_errors false + end + + # Lazy load the lazy attributes for this model. + def load_attribute(name) + # Since the lazy attributes are related, we just load them all at once + loaded_hd = self.class.find(uuid, true) + + write_attribute(:size, loaded_hd.size) + write_attribute(:accessible, loaded_hd.accessible) end end end \ No newline at end of file