From dc439b2c1c0805d42f21b9ddd9fe543f581bd4d2 Mon Sep 17 00:00:00 2001 From: Chen Hanxiao Date: Tue, 21 Jan 2014 16:24:09 +0800 Subject: [PATCH] addhw: set virtio-scsi controller index via max index in scsi controller list We set virtio-scsi controller index according to the number of scsi controller in VM. This patch will set virtio-scsi controller index via max index in scsi controller list. How to reproduce: a) If we got an VM with two scsi controller: #reason for index='2': someone delete a scsi controller with index=1 by virsh b) add a virtio-scsi disk by virt-manager c) error threw by virt-manager: libvirtError: XML error: Multiple 'scsi' controllers with index '2' Signed-off-by: Chen Hanxiao --- virtManager/addhardware.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py index 05a23aad0..3e0cfad13 100644 --- a/virtManager/addhardware.py +++ b/virtManager/addhardware.py @@ -1546,13 +1546,19 @@ class vmmAddHardware(vmmGObjectUI): disk.vmm_controller = None if (controller_model == "virtio-scsi") and (bus == "scsi"): controllers = self.vm.get_controller_devices() + ctrls_scsi = [x for x in controllers if + (x.type == VirtualController.TYPE_SCSI)] + if len(ctrls_scsi) > 0: + index_new = max([x.index for x in ctrls_scsi]) + 1 + else: + index_new = 0 controller = VirtualController(conn) controller.type = "scsi" controller.model = controller_model disk.vmm_controller = controller for d in controllers: if controller.type == d.type: - controller.index += 1 + controller.index = index_new if controller_model == d.model: disk.vmm_controller = None controller = d