[virt-tools-list] [virt-manager PATCH 2/2] add support for modifying scsi controller model

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Mon Jan 20 09:44:30 UTC 2014


From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>

We could modify scsi controller model
between 'default' and 'virtio-scsi'.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 virtManager/domain.py | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)

diff --git a/virtManager/domain.py b/virtManager/domain.py
index ada404b..604b511 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -822,27 +822,53 @@ class vmmDomain(vmmLibvirtObject):
 
     # Controller define methods
     def define_controller_model(self, devobj, newmodel):
+        #model list from libvirt with extra "default" member
+        usb_controller_model = ["default", "piix3-uhci", "piix4-uhci",
+                "ehci", "ich9-ehci1", "ich9-uhci1", "ich9-uhci2",
+                "ich9-uhci3", "vt82c686b-uhci", "pci-ohci", "nec-xhci"]
+        scsi_controller_model = ["default_virtio_scsi", "auto", "buslogic",
+                "lsilogic", "lsisas1068", "vmpvscsi", "ibmvscsi", "virtio-scsi",
+                "lsisas1078"]
+
         def change(editdev):
             ignore = editdev
 
             guest = self._get_xmlobj_to_define()
             ctrls = guest.get_devices("controller")
-            ctrls = [x for x in ctrls if (x.type ==
-                     VirtualController.TYPE_USB)]
-            for dev in ctrls:
-                guest.remove_device(dev)
-
+            ctrls_usb = [x for x in ctrls if
+                    (x.type == VirtualController.TYPE_USB)]
+            ctrls_scsi = [x for x in ctrls if
+                    (x.type == VirtualController.TYPE_SCSI)]
+
+            for dev in ctrls_usb:
+                if newmodel in usb_controller_model:
+                    guest.remove_device(dev)
             if newmodel == "ich9-ehci1":
                 for dev in VirtualController.get_usb2_controllers(
                         guest.conn):
                     guest.add_device(dev)
-            else:
+            elif newmodel in usb_controller_model:
                 dev = VirtualController(guest.conn)
                 dev.type = "usb"
                 if newmodel != "default":
                     dev.model = newmodel
                 guest.add_device(dev)
 
+            index_new = max([x.index for x in ctrls_scsi]) + 1
+
+            for dev in ctrls_scsi:
+                if newmodel in scsi_controller_model:
+                    guest.remove_device(dev)
+            for dev in ctrls_scsi:
+                if newmodel == "virtio-scsi":
+                    dev = VirtualController(guest.conn)
+                    dev.type = "scsi"
+                    dev.index = index_new
+                    if newmodel != "default":
+                        dev.model = newmodel
+                    guest.add_device(dev)
+                    break
+
         return self._redefine_device(change, devobj)
 
 
-- 
1.8.2.1




More information about the virt-tools-list mailing list