Comment 1 for bug 676128

Revision history for this message
Itai Frenkel (itaifrenkel) wrote :

Here's the code in Java (sorry don't have it in python)

// The tricky part in destroying a VM, is to find the disks before terminating
// the machine, and delete the disks after terminating the machine.
// find vm's virtuaL disks
List<VDI> virtualDiskImagesToDelete = new ArrayList<VDI>();
for (VBD vbd : VBD.getAll(connection)) {
  if (vbd.getVM(connection).equals(vm) {
    VDI vdi = vbd.getVDI(connection);
    if (!vdi.getReadOnly(connection)) {
      virtualDiskImagesToDelete.add(vdi);
    }
  }
}

// destroy vm and disks
vm.destroy(connection);
for (VDI vdi : virtualDiskImagesToDelete) {
  vdi.destroy(connection);
}