summaryrefslogtreecommitdiff
path: root/virtManager/addhardware.py
diff options
context:
space:
mode:
authorMartin Kletzander <mkletzan@redhat.com>2014-02-12 15:58:40 +0100
committerMartin Kletzander <mkletzan@redhat.com>2014-02-12 21:55:32 +0100
commit078e1a4d0503d98884b5b61df83021941bf32e8d (patch)
treeb7054d478ecfbd6396b4fc8441ad1e7255da3f5b /virtManager/addhardware.py
parent6c4302b0a7a919afd15aeb87e9625da9c5079db8 (diff)
downloadvirt-manager-078e1a4d0503d98884b5b61df83021941bf32e8d.tar.gz
Rework disk target assignment
Using previous patches, this one makes the disk target generation a bit more intelligent, so adding multiple disks with various controllers is not a problem anymore. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1036716 Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Diffstat (limited to 'virtManager/addhardware.py')
-rw-r--r--virtManager/addhardware.py48
1 files changed, 30 insertions, 18 deletions
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 121c75b8..ecb5fc83 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -1,5 +1,5 @@
#
-# Copyright (C) 2006-2007, 2013, 2014 Red Hat, Inc.
+# Copyright (C) 2006-2007, 2012-2014 Red Hat, Inc.
# Copyright (C) 2006 Hugh O. Brock <hbrock@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
@@ -20,6 +20,7 @@
import logging
import traceback
+import collections
# pylint: disable=E0611
from gi.repository import Gtk
@@ -1412,34 +1413,45 @@ class vmmAddHardware(vmmGObjectUI):
self._dev.validate()
return ret
- def _set_disk_controller(self, disk, controller_model):
+ def _set_disk_controller(self, disk, controller_model, used_disks):
# Add a SCSI controller with model virtio-scsi if needed
disk.vmm_controller = None
if controller_model != "virtio-scsi":
- return
+ return None
+ # Get SCSI controllers
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
+ # Create possible new controller
controller = VirtualController(self.conn.get_backend())
controller.type = "scsi"
controller.model = controller_model
- disk.vmm_controller = controller
- for d in controllers:
- if controller.type == d.type:
- controller.index = index_new
- if controller_model == d.model:
- disk.vmm_controller = None
- controller = d
+
+ # And set its index
+ controller.index = 0
+ if ctrls_scsi:
+ controller.index = max([x.index for x in ctrls_scsi]) + 1
+
+ # Take only virtio-scsi ones
+ ctrls_scsi = [x for x in ctrls_scsi
+ if x.model == controller_model]
+
+ # Save occupied places per controller
+ occupied = collections.defaultdict(int)
+ for d in used_disks:
+ if d.bus == disk.bus:
+ num = virtinst.VirtualDisk.target_to_num(d.target)
+ occupied[num / 7] += 1
+ for c in ctrls_scsi:
+ if occupied[c.index] < 7:
+ controller = c
break
+ else:
+ disk.vmm_controller = controller
- disk.address.type = disk.address.ADDRESS_TYPE_DRIVE
- disk.address.controller = controller.index
+ return controller.index
def validate_page_storage(self):
bus = self.get_config_disk_bus()
@@ -1471,9 +1483,9 @@ class vmmAddHardware(vmmGObjectUI):
for d in disks:
used.append(d.target)
- disk.generate_target(used)
+ prefer_ctrl = self._set_disk_controller(disk, controller_model, disks)
+ disk.generate_target(used, prefer_ctrl)
- self._set_disk_controller(disk, controller_model)
except Exception, e:
return self.err.val_err(_("Storage parameter error."), e)