[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [virt-tools-list] [PATCH] Show disk allocation & size on Details tab in VMM



Hi Haydn,
you were right. It was not working right in some circumstances - the values of allocation & size were not reset when type was not 'file' and this is the corrected version of this patch. Thanks once again Haydn...

Thanks,
Michal

----- Original Message -----
From: "Haydn Solomon" <haydn solomon gmail com>
To: "Michal Novotny" <minovotn redhat com>
Cc: virt-tools-list redhat com
Sent: Tuesday, August 4, 2009 6:29:41 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna
Subject: Re: [virt-tools-list] [PATCH] Show disk allocation & size on Details  tab in VMM

Michael, 

Thanks for your patch. I have one comment based on my observation. I noticed that if the cdrom is not connected, it shows the capacity of the primary disk. The cdrom source type shows as block when disconnected but file when connected. 




On Tue, Aug 4, 2009 at 12:02 PM, Michal Novotny < minovotn redhat com > wrote: 


Hi, 
sorry, I made a mistake here preventing it to show size and even work correctly in some circumstances, this is updated version of this patch. 

Thanks, 
Michal 




----- Original Message ----- 
From: "Michal Novotny" < minovotn redhat com > 
To: virt-tools-list redhat com 
Sent: Tuesday, August 4, 2009 5:39:23 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna 
Subject: [virt-tools-list] [PATCH] Show disk allocation & size on Details tab in VMM 

Hi, 
this is a patch for virt-manager (VMM for short) that allows user see the current allocation and disk size. It's working fine for both managed and unmanaged storages, however getting allocation information is possible only for managed ones so that there is just "N/A" string shown in disk allocation field if looking on unmanaged storage details. It's also showing disk size of CD-ROM devices assigned for this VM... 

Please review, thanks, 
Michal 
_______________________________________________ 
virt-tools-list mailing list 
virt-tools-list redhat com 
https://www.redhat.com/mailman/listinfo/virt-tools-list 
_______________________________________________ 
virt-tools-list mailing list 
virt-tools-list redhat com 
https://www.redhat.com/mailman/listinfo/virt-tools-list 

# HG changeset patch
# User Michal Novotny <minovotn redhat com>
# Date 1249466832 -7200
# Node ID ec2ddfac511f7d78cf715e7375c54aa22ac4b01c
# Parent  18e673ca4e148a3e023f56353412d259aea487c2
Show disk size and allocation bits in Details tab

When user selected a disk, it was never showing disk allocation and
size. The allocation itself is (according to my testing) available
only for managed storages so user can check the allocation of
managed storages and real capacity (disk image size) bit for both
of types of storages.

diff -r 18e673ca4e14 -r ec2ddfac511f src/virtManager/details.py
--- a/src/virtManager/details.py	Tue Jul 28 22:25:13 2009 -0400
+++ b/src/virtManager/details.py	Tue Aug 04 17:34:37 2009 +0200
@@ -1050,6 +1050,14 @@
         self.window.get_widget("disk-source-path").set_text(diskinfo[3])
         self.window.get_widget("disk-target-type").set_text(diskinfo[4])
         self.window.get_widget("disk-target-device").set_text(diskinfo[2])
+
+        if diskinfo[9] is None:
+            diskinfo[9] = "N/A"
+        if diskinfo[10] is None:
+            diskinfo[10] = "N/A"
+
+        self.window.get_widget("disk-size-capacity").set_text(diskinfo[9])
+        self.window.get_widget("disk-size-allocation").set_text(diskinfo[10])
         if diskinfo[6] == True:
             perms = "Readonly"
         else:
diff -r 18e673ca4e14 -r ec2ddfac511f src/virtManager/domain.py
--- a/src/virtManager/domain.py	Tue Jul 28 22:25:13 2009 -0400
+++ b/src/virtManager/domain.py	Tue Aug 04 17:34:37 2009 +0200
@@ -25,7 +25,7 @@
 import time
 import difflib
 
-from virtManager import util
+from virtManager import util, storagevol
 import virtinst.util as vutil
 import virtinst
 
@@ -796,6 +796,17 @@
 
 
     # ----------------
+    # prettyify_disk_size formats the size in pretty string
+    # val have to be passed in GB (as it's a result of VirtualDisk' size)
+    # ----------------
+
+    def prettyify_disk_size(self, val):
+        if val > 1:
+            return "%2.2f GB" % val
+        else:
+            return "%2.2f MB" % (val * 1024)
+
+    # ----------------
     # get_X_devices functions: return a list of lists. Each sublist represents
     # a device, of the format:
     # [ device_type, unique_attribute(s), hw column label, attr1, attr2, ... ]
@@ -840,11 +851,30 @@
                 if devdst == None:
                     raise RuntimeError("missing destination device")
 
+                capacity = None
+                allocation = None
+                selinux_label = None
+                if typ == 'file':
+                    if virtinst._util.is_storage_capable( self.connection.vmm ):
+                        try:
+                            vol = self.connection.vmm.storageVolLookupByPath( srcpath )
+                            volobj = storagevol.vmmStorageVolume( self.config, self.connection.vmm, vol, vol )
+                            capacity = volobj.get_pretty_capacity()
+                            allocation = volobj.get_pretty_allocation()
+                        except libvirt.libvirtError:
+                            pass
+
+                    vd = virtinst.VirtualDisk( path = srcpath )
+                    if capacity is None:
+                        capacity = self.prettyify_disk_size( vd.size )
+
+                    #selinux_label = vd.selinux_label or "None"
+                    
                 # [ devicetype, unique, device target, source path,
                 #   disk device type, disk type, readonly?, sharable?,
-                #   bus type ]
+                #   bus type, capacity, allocation ]
                 disks.append(["disk", devdst, devdst, srcpath, devtype, typ,
-                              readonly, sharable, bus])
+                              readonly, sharable, bus, capacity, allocation])
 
             return disks
 
diff -r 18e673ca4e14 -r ec2ddfac511f src/vmm-details.glade
--- a/src/vmm-details.glade	Tue Jul 28 22:25:13 2009 -0400
+++ b/src/vmm-details.glade	Tue Aug 04 17:34:37 2009 +0200
@@ -2410,6 +2410,67 @@
                                             <property name="y_options"></property>
                                           </packing>
                                         </child>
+
+                                        <child>
+                                          <widget class="GtkLabel" id="disk-capacity-label">
+                                            <property name="visible">True</property>
+                                            <property name="xalign">1</property>
+                                            <property name="label" translatable="yes">Disk capacity:</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="top_attach">6</property>
+                                            <property name="bottom_attach">7</property>
+                                            <property name="x_options">GTK_FILL</property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkLabel" id="disk-size-capacity">
+                                            <property name="visible">True</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label">label423</property>
+                                            <property name="selectable">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">6</property>
+                                            <property name="bottom_attach">7</property>
+                                            <property name="x_options">GTK_FILL</property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+
+                                        <child>
+                                          <widget class="GtkLabel" id="disk-allocation-label">
+                                            <property name="visible">True</property>
+                                            <property name="xalign">1</property>
+                                            <property name="label" translatable="yes">Disk allocation:</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="top_attach">7</property>
+                                            <property name="bottom_attach">8</property>
+                                            <property name="x_options">GTK_FILL</property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <widget class="GtkLabel" id="disk-size-allocation">
+                                            <property name="visible">True</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label">label423</property>
+                                            <property name="selectable">True</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">7</property>
+                                            <property name="bottom_attach">8</property>
+                                            <property name="x_options">GTK_FILL</property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+
                                         <child>
                                           <widget class="GtkLabel" id="label507">
                                             <property name="visible">True</property>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]