Revision 69266fae lib/backend.py
b/lib/backend.py | ||
---|---|---|
647 | 647 |
return result |
648 | 648 |
|
649 | 649 |
|
650 |
def GetBlockDevSizes(devices): |
|
651 |
"""Return the size of the given block devices |
|
652 |
|
|
653 |
@type devices: list |
|
654 |
@param devices: list of block device nodes to query |
|
655 |
@rtype: dict |
|
656 |
@return: |
|
657 |
dictionary of all block devices under /dev (key). The value is their |
|
658 |
size in MiB. |
|
659 |
|
|
660 |
{'/dev/disk/by-uuid/123456-12321231-312312-312': 124} |
|
661 |
|
|
662 |
""" |
|
663 |
DEV_PREFIX = "/dev/" |
|
664 |
blockdevs = {} |
|
665 |
|
|
666 |
for devpath in devices: |
|
667 |
if os.path.commonprefix([DEV_PREFIX, devpath]) != DEV_PREFIX: |
|
668 |
continue |
|
669 |
|
|
670 |
try: |
|
671 |
st = os.stat(devpath) |
|
672 |
except EnvironmentError, err: |
|
673 |
logging.warning("Error stat()'ing device %s: %s", devpath, str(err)) |
|
674 |
continue |
|
675 |
|
|
676 |
if stat.S_ISBLK(st.st_mode): |
|
677 |
result = utils.RunCmd(["blockdev", "--getsize64", devpath]) |
|
678 |
if result.failed: |
|
679 |
# We don't want to fail, just do not list this device as available |
|
680 |
logging.warning("Cannot get size for block device %s", devpath) |
|
681 |
continue |
|
682 |
|
|
683 |
size = int(result.stdout) / (1024 * 1024) |
|
684 |
blockdevs[devpath] = size |
|
685 |
return blockdevs |
|
686 |
|
|
687 |
|
|
650 | 688 |
def GetVolumeList(vg_names): |
651 | 689 |
"""Compute list of logical volumes and their size. |
652 | 690 |
|
Also available in: Unified diff