diff --git a/lib/backend.py b/lib/backend.py index ab013366d7e01f0ec752aaea2fa205d5874283d7..ac5f93b4a0699af111843ac826f34daea0f50538 100644 --- a/lib/backend.py +++ b/lib/backend.py @@ -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 - @return: - 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: - try: - 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) - else: - 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)) diff --git a/lib/bdev.py b/lib/bdev.py index 3352885840e518d9b1c282e2c63fb4231775438c..1378a2ff744fd3dcdcf97b8101380d2bc3ad1f48 100644 --- a/lib/bdev.py +++ b/lib/bdev.py @@ -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 + MiB """ try: - info = cls._GetVolumeInfo("vgs", ["vg_name", "vg_free", "vg_attr"]) + info = cls._GetVolumeInfo("vgs", ["vg_name", "vg_free", "vg_attr", + "vg_size"]) 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": continue # (possibly) skip over vgs which are not in the right volume group(s) if vg_names and vg_name not in vg_names: continue - 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)