Commit 673cd9c4 authored by René Nussbaumer's avatar René Nussbaumer

Migrate call from backend._GetVGInfo to bdev.LogicalVolume.GetVGInfo

This patch removes duplicate code found in backend which also needs to
get VG infos. To make it simpler we moved to bdev.LogicalVolume.GetVGInfo.
Signed-off-by: default avatarRené Nussbaumer <>
Reviewed-by: default avatarMichael Hanselmann <>
parent b80cc518
......@@ -439,9 +439,15 @@ def GetNodeInfo(vgname, hypervisor_type):
outputarray = {}
vginfo = _GetVGInfo(vgname)
outputarray['vg_size'] = vginfo['vg_size']
outputarray['vg_free'] = vginfo['vg_free']
vginfo = bdev.LogicalVolume.GetVGInfo([vgname])
vg_free = vg_size = None
if vginfo:
vg_free = int(round(vginfo[0][0], 0))
vg_size = int(round(vginfo[0][1], 0))
outputarray['vg_size'] = vg_size
outputarray['vg_free'] = vg_free
hyper = hypervisor.GetHypervisor(hypervisor_type)
hyp_info = hyper.GetNodeInfo()
......@@ -930,46 +936,6 @@ def RunRenameInstance(instance, old_name, debug):
" log file:\n%s", result.fail_reason, "\n".join(lines), log=False)
def _GetVGInfo(vg_name):
"""Get information about the volume group.
@type vg_name: str
@param vg_name: the volume group which we query
@rtype: dict
A dictionary with the following keys:
- C{vg_size} is the total size of the volume group in MiB
- C{vg_free} is the free size of the volume group in MiB
- C{pv_count} are the number of physical disks in that VG
If an error occurs during gathering of data, we return the same dict
with keys all set to None.
retdic = dict.fromkeys(["vg_size", "vg_free", "pv_count"])
retval = utils.RunCmd(["vgs", "-ovg_size,vg_free,pv_count", "--noheadings",
"--nosuffix", "--units=m", "--separator=:", vg_name])
if retval.failed:
logging.error("volume group %s not present", vg_name)
return retdic
valarr = retval.stdout.strip().rstrip(':').split(':')
if len(valarr) == 3:
retdic = {
"vg_size": int(round(float(valarr[0]), 0)),
"vg_free": int(round(float(valarr[1]), 0)),
"pv_count": int(valarr[2]),
except (TypeError, ValueError), err:
logging.exception("Fail to parse vgs output: %s", err)
logging.error("vgs output has the wrong number of fields (expected"
" three): %s", str(valarr))
return retdic
def _GetBlockDevSymlinkPath(instance_name, idx):
return utils.PathJoin(constants.DISK_LINKS_DIR,
"%s:%d" % (instance_name, idx))
......@@ -488,24 +488,26 @@ class LogicalVolume(BlockDev):
@param filter_readonly: whether to skip over readonly VGs
@rtype: list
@return: list of tuples (free_space, name) with free_space in mebibytes
@return: list of tuples (free_space, total_size, name) with free_space in
info = cls._GetVolumeInfo("vgs", ["vg_name", "vg_free", "vg_attr"])
info = cls._GetVolumeInfo("vgs", ["vg_name", "vg_free", "vg_attr",
except errors.GenericError, err:
logging.error("Can't get VG information: %s", err)
return None
data = []
for vg_name, vg_free, vg_attr in info:
for vg_name, vg_free, vg_attr, vg_size in info:
# (possibly) skip over vgs which are not writable
if filter_readonly and vg_attr[0] == "r":
# (possibly) skip over vgs which are not in the right volume group(s)
if vg_names and vg_name not in vg_names:
data.append((float(vg_free), vg_name))
data.append((float(vg_free), float(vg_size), vg_name))
return data
......@@ -702,7 +704,7 @@ class LogicalVolume(BlockDev):
vg_info = self.GetVGInfo([self._vg_name])
if not vg_info:
_ThrowError("Can't compute VG info for vg %s", self._vg_name)
free_size, _ = vg_info[0]
free_size, _, _ = vg_info[0]
if free_size < size:
_ThrowError("Not enough free space: required %s,"
" available %s", size, free_size)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment