[PATCH] Provide a common block device size utility for Solaris & Linux

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

 



# HG changeset patch
# User john.levon@xxxxxxx
# Date 1228271102 28800
# Node ID 7069ca5b2ced261f19438d3091af89aea2441b88
# Parent  ca3207be8b5da3d6f4f9f5432dfa819cfab173c8
Provide a common block device size utility for Solaris & Linux

Signed-off-by: John Danielson <john.danielson@xxxxxxx>

diff --git a/virtinst/CloneManager.py b/virtinst/CloneManager.py
--- a/virtinst/CloneManager.py
+++ b/virtinst/CloneManager.py
@@ -24,7 +24,6 @@ import logging
 import logging
 import urlgrabber.progress as progress
 import util
-import commands
 import libvirt
 import Guest
 from VirtualDisk import VirtualDisk
@@ -397,13 +396,7 @@ class CloneDesign(object):
         for i in lst:
             mode = os.stat(i)[stat.ST_MODE]
             if stat.S_ISBLK(mode):
-                dummy, msg = commands.getstatusoutput('fdisk -s %s' % i)
-                # check
-                if msg.isdigit() == False:
-                    lines = msg.splitlines()
-                    # retry eg. for the GPT disk
-                    msg = lines[len(lines)-1]
-                size.append(int(msg) * 1024)
+                size.append(util.blkdev_size(i))
                 typ.append(False)
             elif stat.S_ISREG(mode):
                 size.append(os.path.getsize(i))
@@ -457,13 +450,7 @@ class CloneDesign(object):
                 continue
             mode = os.stat(i)[stat.ST_MODE]
             if stat.S_ISBLK(mode):
-                dummy, msg = commands.getstatusoutput('fdisk -s %s' % i)
-                # check
-                if msg.isdigit() == False:
-                    lines = msg.splitlines()
-                    # retry eg. for the GPT disk
-                    msg = lines[len(lines)-1]
-                size.append(int(msg) * 1024)
+                size.append(util.blkdev_size(i))
                 typ.append(False)
             elif stat.S_ISREG(mode):
                 size.append(os.path.getsize(i))
diff --git a/virtinst/util.py b/virtinst/util.py
--- a/virtinst/util.py
+++ b/virtinst/util.py
@@ -25,6 +25,8 @@ import re
 import re
 import libxml2
 import logging
+import commands
+import stat
 from sys import stderr
 
 import libvirt
@@ -257,6 +259,18 @@ def xml_escape(str):
     str = str.replace("<", "&lt;")
     str = str.replace(">", "&gt;")
     return str
+ 
+def blkdev_size(path):
+    if platform.system() == 'SunOS':
+        return os.stat(path)[stat.ST_SIZE]
+    else:
+        dummy, msg = commands.getstatusoutput('fdisk -s %s' % path)
+        # check
+        if msg.isdigit() == False:
+            lines = msg.splitlines()
+            # retry eg. for the GPT disk
+            msg = lines[len(lines)-1]
+        return (int(msg) * 1024)
 
 def compareMAC(p, q):
     """Compare two MAC addresses"""

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux