[virt-tools-list] [virt-manager PATCH] Handle storage formats properly

Martin Kletzander mkletzan at redhat.com
Wed Aug 21 09:18:51 UTC 2013


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
Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---

Notes:
    Sorry for not splitting these up in a separate patches, I hope this is
    not needed in virt-manager for such simple case.  But feel free to
    disagree, I'll just have to create one more bug to track the second
    issue downstream.

 virtManager/addhardware.py | 14 +++++++++-----
 virtManager/details.py     |  2 +-
 virtManager/domain.py      |  2 +-
 virtManager/uihelpers.py   | 12 +++++++++---
 virtinst/device.py         |  4 +++-
 5 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 1b388fb..0d11924 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -252,8 +252,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")
@@ -429,9 +428,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:
@@ -593,6 +590,12 @@ class vmmAddHardware(vmmGObjectUI):
             model.append([_("No Devices Available"), None])
         uihelpers.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 #
     ########################
@@ -942,6 +945,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 085973f..a10eef8 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -960,7 +960,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 3407231..a2ae5c5 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 at 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 f1685e6..9380d23 100644
--- a/virtManager/uihelpers.py
+++ b/virtManager/uihelpers.py
@@ -419,20 +419,26 @@ def build_vnc_keymap_combo(vm, combo, no_default=False):
 # Storage format list/combo helpers #
 #####################################

-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])

-    combo.set_active(0)
+    if create:
+        # TODO: make the default storage format configurable
+        combo.set_active(0)


 #######################################################################
diff --git a/virtinst/device.py b/virtinst/device.py
index af78bf0..0cce561 100644
--- a/virtinst/device.py
+++ b/virtinst/device.py
@@ -135,7 +135,8 @@ class VirtualDeviceAddress(XMLBuilder):
              ADDRESS_TYPE_SPAPR_VIO]

     _XML_ROOT_XPATH = "/domain/devices/device/address"
-    _XML_PROP_ORDER = ["type", "domain", "bus", "slot", "function"]
+    _XML_PROP_ORDER = ["type", "domain", "controller", "bus", "slot",
+                       "function", "target", "unit"]

     def set_addrstr(self, addrstr):
         if addrstr is None:
@@ -163,3 +164,4 @@ class VirtualDeviceAddress(XMLBuilder):
     controller = XMLProperty(xpath="./address/@controller", is_int=True)
     unit = XMLProperty(xpath="./address/@unit", is_int=True)
     port = XMLProperty(xpath="./address/@port", is_int=True)
+    target = XMLProperty(xpath="./address/@target", is_int=True)
-- 
1.8.3.2




More information about the virt-tools-list mailing list