FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora/Linux Management Tools

 
 
LinkBack Thread Tools
 
Old 12-03-2008, 01:25 AM
 
Default Provide a common block device size utility for Solaris & Linux

# HG changeset patch
# User john.levon@sun.com
# 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@sun.com>

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@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-05-2008, 12:37 PM
 
Default Provide a common block device size utility for Solaris & Linux

# HG changeset patch
# User john.levon@sun.com
# Date 1228484251 28800
# Node ID 89668fd908b8ee8dc8fd54d89888037d8845e8d2
# Parent 862a53870d43aaa9b65d7afadaed999ca4349fea
Provide a common block device size utility for Solaris & Linux.

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

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
@@ -257,6 +257,15 @@ def xml_escape(str):
str = str.replace("<", "&lt;")
str = str.replace(">", "&gt;")
return str
+
+def blkdev_size(path):
+ """Return the size of the block device. We can't use os.stat() as
+ that returns zero on many platforms."""
+ fd = os.open(path, os.O_RDONLY)
+ # os.SEEK_END is not present on all systems
+ size = os.lseek(fd, 0, 2)
+ os.close(fd)
+ return size

def compareMAC(p, q):
"""Compare two MAC addresses"""

_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@redhat.com
https://www.redhat.com/mailman/listinfo/et-mgmt-tools
 
Old 12-07-2008, 03:22 AM
Cole Robinson
 
Default Provide a common block device size utility for Solaris & Linux

john.levon@sun.com wrote:
> # HG changeset patch
> # User john.levon@sun.com
> # Date 1228484251 28800
> # Node ID 89668fd908b8ee8dc8fd54d89888037d8845e8d2
> # Parent 862a53870d43aaa9b65d7afadaed999ca4349fea
> Provide a common block device size utility for Solaris & Linux.
>
> Signed-off-by: John Danielson <john.danielson@sun.com>
>
>

Thanks, applied:

http://hg.et.redhat.com/virt/applications/virtinst--devel?cs=13390c95ae0a

- Cole

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

Thread Tools




All times are GMT. The time now is 09:36 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org