mitchellh / virtualbox

[ABANDONED] Create and modify virtual machines in VirtualBox using pure ruby.
http://mitchellh.github.com/virtualbox/
MIT License
245 stars 45 forks source link

Access VM's on a Hard Drive #21

Closed KieranP closed 14 years ago

KieranP commented 14 years ago

I have the following code:

@vms_on_this_hd = VirtualBox::VM.all.select do |vm|
    vm.storage_controllers.any? do |sc|
      sc.medium_attachments.any? { |ma| ma.type == :hard_disk && ma.medium.uuid == @hd.uuid }
    end
  end

Basically, it takes all vms, checks each storage containers medium attachments to see if the hard drive is related.

Ideally, something like this could be available:

@vms_on_this_hd = @hd.virtual_machines
KieranP commented 14 years ago

After digging into something else, came across this:

@vms_on_this_hd = @hd.interface.machine_ids.collect { |vm_uuid| VirtualBox::VM.find(vm_uuid) }

Which returns the same result, and much cleaner. Still would be nice to have this through something like:

@hd.machines