[virt-tools-list] [virt-manager][Patch v2]Add virtio-scsi disk bus option
Chen HanXiao
chenhanxiao at cn.fujitsu.com
Wed Nov 21 07:06:51 UTC 2012
Ping...
> -----Original Message-----
> From: Chen Hanxiao [mailto:chenhanxiao at cn.fujitsu.com]
> Sent: Friday, November 16, 2012 5:35 PM
> To: virt-tools-list at redhat.com
> Cc: chenhanxiao at cn.fujitsu.com
> Subject: [virt-tools-list][virt-manager][Patch v2]Add virtio-scsi disk bus
option
>
> From: ChenHanxiao <chenhanxiao at cn.fujitsu.com>
>
> This patch will add virtio-scsi bus option on "Add New Virtual Hardware"
GUI
> page. It will support users to add a virtual disk using SCSI bus with a
controller
> model virtio-scsi.
> If there is no SCSI controller existed, a new SCSI controller by model
'virtio-scsi'
> will be added automatically.
>
> Signed-off-by: ChenHanxiao <chenhanxiao at cn.fujitsu.com>
> ---
> src/virtManager/addhardware.py | 38
> ++++++++++++++++++++++++++++++++++++++
> src/virtManager/details.py | 6 +++++-
> 2 files changed, 43 insertions(+), 1 deletions(-)
>
> diff --git a/src/virtManager/addhardware.py
> b/src/virtManager/addhardware.py index 4d894eb..76797c9 100644
> --- a/src/virtManager/addhardware.py
> +++ b/src/virtManager/addhardware.py
> @@ -34,6 +34,7 @@ import virtManager.uihelpers as uihelpers from
> virtManager.asyncjob import vmmAsyncJob from virtManager.storagebrowse
> import vmmStorageBrowser from virtManager.baseclass import
> vmmGObjectUI
> +from virtinst.VirtualController import VirtualControllerSCSI
>
> PAGE_ERROR = 0
> PAGE_DISK = 1
> @@ -539,6 +540,8 @@ class vmmAddHardware(vmmGObjectUI):
> if self.vm.get_hv_type() == "kvm":
> add_dev("sata", virtinst.VirtualDisk.DEVICE_DISK, "SATA
disk")
> add_dev("virtio", virtinst.VirtualDisk.DEVICE_DISK, "Virtio
disk")
> + add_dev("virtio-scsi", virtinst.VirtualDisk.DEVICE_DISK,
> + "Virtio-SCSI disk")
> if self.conn.is_xen():
> add_dev("xen", virtinst.VirtualDisk.DEVICE_DISK, "Virtual
disk")
>
> @@ -1151,10 +1154,16 @@ class vmmAddHardware(vmmGObjectUI):
>
> self._dev.get_xml_config()
> logging.debug("Adding device:\n" + self._dev.get_xml_config())
> + if self.has_controller():
> + if self._controller is not None:
> + logging.debug("Adding controller:\n"
> + + self._controller.get_xml_config())
>
> # Hotplug device
> attach_err = False
> try:
> + if self.has_controller() and self._controller is not None:
> + self.vm.attach_device(self._controller)
> self.vm.attach_device(self._dev)
> except Exception, e:
> logging.debug("Device could not be hotplugged: %s", str(e))
> @@ -1176,6 +1185,13 @@ class vmmAddHardware(vmmGObjectUI):
> return (False, None)
>
> # Alter persistent config
> + if self.has_controller() and self._controller is not None:
> + try:
> + self.vm.add_device(self._controller)
> + except Excpetion, e:
> + self.err.show_err(_("Error adding device: %s" % str(e)))
> + return (True, None)
> +
> try:
> self.vm.add_device(self._dev)
> except Exception, e:
> @@ -1184,6 +1200,14 @@ class vmmAddHardware(vmmGObjectUI):
>
> return (False, None)
>
> + #check whether device has attribute '_controller'
> + def has_controller(self):
> + try:
> + self._controller
> + except AttributeError:
> + return False
> + else:
> + return True
>
> ###########################
> # Page validation methods #
> @@ -1222,6 +1246,10 @@ class vmmAddHardware(vmmGObjectUI):
> bus, device = self.get_config_disk_target()
> cache = self.get_config_disk_cache()
> fmt = self.get_config_disk_format()
> + model = None
> + if bus == "virtio-scsi":
> + bus = "scsi"
> + model = "virtio-scsi"
>
> # Make sure default pool is running
> if self.is_default_storage():
> @@ -1271,6 +1299,7 @@ class vmmAddHardware(vmmGObjectUI):
> device=device,
> bus=bus,
> driverCache=cache,
> + model=model,
> format=fmt)
>
> if not fmt:
> @@ -1316,6 +1345,15 @@ class vmmAddHardware(vmmGObjectUI):
> uihelpers.check_path_search_for_qemu(self.topwin,
> self.conn, disk.path)
>
> + if disk.model == "virtio-scsi":
> + controllers = self.vm.get_controller_devices()
> + controller = VirtualControllerSCSI(conn = self.conn.vmm)
> + controller.set_model(disk.model)
> + self._controller = controller
> + for d in controllers:
> + if disk.model == d.model:
> + self._controller = None
> +
> self._dev = disk
> return True
>
> diff --git a/src/virtManager/details.py b/src/virtManager/details.py index
> d20e748..0e86648 100644
> --- a/src/virtManager/details.py
> +++ b/src/virtManager/details.py
> @@ -2219,7 +2219,11 @@ class vmmDetails(vmmGObjectUI):
> if bus == "spapr-vscsi":
> bus = "scsi"
> addr = "spapr-vio"
> - add_define(self.vm.define_disk_bus, dev_id_info, bus, addr)
> + if bus == "virtio-scsi":
> + bus = "scsi"
> + model = "virtio-scsi"
> + add_define(self.vm.define_disk_bus, dev_id_info, bus,
> + addr, model)
>
> return self._change_config_helper(df, da, hf, ha)
>
> --
> 1.7.1
More information about the virt-tools-list
mailing list