Blob Blame History Raw
From b6060b42f9fd5fa318ce07feeabec5f0c15517ae Mon Sep 17 00:00:00 2001
From: Martin Kletzander <mkletzan@redhat.com>
Date: Tue, 20 Aug 2013 09:15:47 +0200
Subject: [RHEL-7.0 virt-manager PATCH] Handle storage formats properly

This simple patch fixes three issues:

 1) We used only one list of storage formats.  However, we are able to
    use some formats which we cannot create.  This patch adds a list
    called 'no_create_formats' and moves such formats (currently only
    one) into it and uses new parameter 'create' which describes
    whether such formats should be removed or not.

 2) When creating new storage with the above fixed, we need to set the
    combobox's text to "" in order not to change it to "raw".  This
    was already done in reset_state(), but we need it also when
    toggle_storage_select() happens and it doesn't hurt in
    set_initial_state(), so I abstracted the implementation into
    populate_disk_format_combo().

 3) It's a bit unrelated, but when bus of a domain disk gets changed
    (in details.py), the address was not cleaned up properly ('target'
    attribute was still kept), so I fixed up the VirtualDeviceAddress
    as well.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=907289
(cherry picked from commit 3b9c397d11b68e1eb9603738c661ef946af0757e)

Conflicts:
	virtManager/uihelpers.py -- whitespace
	virtinst/device.py -- 952708f5 and other refactors
---
 virtManager/addhardware.py | 14 +++++++++-----
 virtManager/details.py     |  2 +-
 virtManager/domain.py      |  2 +-
 virtManager/uihelpers.py   | 13 ++++++++++---
 virtinst/VirtualDevice.py  | 12 ++++++++++--
 5 files changed, 31 insertions(+), 12 deletions(-)

diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 62d69e7..f9c85c1 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -251,8 +251,7 @@ class vmmAddHardware(vmmGObjectUI):
         uihelpers.build_cache_combo(self.vm, cache_list)

         # Disk format mode
-        format_list = self.widget("config-storage-format")
-        uihelpers.build_storage_format_combo(self.vm, format_list)
+        self.populate_disk_format_combo(True)

         # Sparse tooltip
         sparse_info = self.widget("config-storage-nosparse-info")
@@ -427,9 +426,7 @@ class vmmAddHardware(vmmGObjectUI):
         self.widget("config-storage-size").set_value(8)
         self.widget("config-storage-entry").set_text("")
         self.widget("config-storage-nosparse").set_active(True)
-        # Don't specify by default, so we don't overwrite possibly working
-        # libvirt detection
-        self.widget("config-storage-format").get_child().set_text("")
+        self.populate_disk_format_combo(True)
         target_list = self.widget("config-storage-devtype")
         self.populate_target_device_model(target_list.get_model())
         if len(target_list.get_model()) > 0:
@@ -583,6 +580,12 @@ class vmmAddHardware(vmmGObjectUI):
             model.append([_("No Devices Available"), None])
         util.set_list_selection(devlist, 0)

+    def populate_disk_format_combo(self, create):
+        format_list = self.widget("config-storage-format")
+        uihelpers.update_storage_format_combo(self.vm, format_list, create)
+        if not create:
+            format_list.get_child().set_text("")
+
     ########################
     # get_config_* methods #
     ########################
@@ -924,6 +927,7 @@ class vmmAddHardware(vmmGObjectUI):
     def toggle_storage_select(self, src):
         act = src.get_active()
         self.widget("config-storage-browse-box").set_sensitive(act)
+        self.populate_disk_format_combo(not act)

     def set_disk_storage_path(self, ignore, path):
         self.widget("config-storage-entry").set_text(path)
diff --git a/virtManager/details.py b/virtManager/details.py
index ad950a5..8012914 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -949,7 +949,7 @@ class vmmDetails(vmmGObjectUI):

         # Disk format combo
         format_list = self.widget("disk-format")
-        uihelpers.build_storage_format_combo(self.vm, format_list)
+        uihelpers.update_storage_format_combo(self.vm, format_list, False)

         # Disk bus combo
         disk_bus = self.widget("disk-bus-combo")
diff --git a/virtManager/domain.py b/virtManager/domain.py
index f4a0f4d..e6e642b 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2006 Red Hat, Inc.
+# Copyright (C) 2006, 2013 Red Hat, Inc.
 # Copyright (C) 2006 Daniel P. Berrange <berrange@redhat.com>
 #
 # This program is free software; you can redistribute it and/or modify
diff --git a/virtManager/uihelpers.py b/virtManager/uihelpers.py
index ba69ee9..415c67d 100644
--- a/virtManager/uihelpers.py
+++ b/virtManager/uihelpers.py
@@ -420,20 +420,27 @@ def build_vnc_keymap_combo(vm, combo, no_default=False):
 #####################################


-def build_storage_format_combo(vm, combo):
+def update_storage_format_combo(vm, combo, create):
     dev_model = Gtk.ListStore(str)
     combo.set_model(dev_model)
     combo.set_entry_text_column(0)

     formats = ["raw", "qcow2", "qed"]
+    no_create_formats = []
     if vm.rhel6_defaults():
         formats.append("vmdk")
-        formats.append("vdi")
+        no_create_formats.append("vdi")

     for m in formats:
         dev_model.append([m])
+    if not create:
+        for m in no_create_formats:
+            dev_model.append([m])
+
+    if create:
+        # TODO: make the default storage format configurable
+        combo.set_active(0)

-    combo.set_active(0)

 #######################################################################
 # Widgets for listing network device options (in create, addhardware) #
diff --git a/virtinst/VirtualDevice.py b/virtinst/VirtualDevice.py
index bbc32a6..cc06eda 100644
--- a/virtinst/VirtualDevice.py
+++ b/virtinst/VirtualDevice.py
@@ -168,8 +168,9 @@ class VirtualDeviceAddress(XMLBuilderDomain):
         self._function = None

         # Drive address:
-        # <address type='drive' controller='0' bus='0' unit='0'/>
+        # <address type='drive' controller='0' bus='0' target='0' unit='0'/>
         self._controller = None
+        self._target = None
         self._unit = None

         # VirtioSerial address:
@@ -207,6 +208,7 @@ class VirtualDeviceAddress(XMLBuilderDomain):
         self._slot = None
         self._function = None
         self._controller = None
+        self._target = None
         self._unit = None
         self._port = None

@@ -251,6 +253,12 @@ class VirtualDeviceAddress(XMLBuilderDomain):
     controller = _xml_property(_get_controller, _set_controller,
                                xpath="./address/@controller")

+    def _get_target(self):
+        return self._target
+    def _set_target(self, val):
+        self._target = val
+    target = _xml_property(_get_target, _set_target, xpath="./address/@target")
+
     def _get_unit(self):
         return self._unit
     def _set_unit(self, val):
@@ -274,7 +282,7 @@ class VirtualDeviceAddress(XMLBuilderDomain):
         if self.type == self.ADDRESS_TYPE_PCI:
             xml += format_props("domain", "bus", "slot", "function")
         elif self.type == self.ADDRESS_TYPE_DRIVE:
-            xml += format_props("controller", "bus", "unit")
+            xml += format_props("controller", "bus", "target", "unit")
         elif self.type == self.ADDRESS_TYPE_VIRTIO_SERIAL:
             xml += format_props("controller", "bus", "port")
         elif self.type == self.ADDRESS_TYPE_CCID:
-- 
1.8.3.2