Merge "Correct the calculating of disk size when using lvm disk backend."
This commit is contained in:
@@ -2034,8 +2034,13 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
"""
|
||||
|
||||
stats = libvirt_utils.get_fs_info(CONF.instances_path)
|
||||
return stats['total'] / (1024 ** 3)
|
||||
if CONF.libvirt_images_type == 'lvm':
|
||||
vg_total = libvirt_utils.volume_group_total_space(
|
||||
CONF.libvirt_images_volume_group)
|
||||
return vg_total / (1024 ** 3)
|
||||
else:
|
||||
stats = libvirt_utils.get_fs_info(CONF.instances_path)
|
||||
return stats['total'] / (1024 ** 3)
|
||||
|
||||
def get_vcpu_used(self):
|
||||
"""Get vcpu usage number of physical computer.
|
||||
@@ -2103,8 +2108,13 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
|
||||
"""
|
||||
|
||||
stats = libvirt_utils.get_fs_info(CONF.instances_path)
|
||||
return stats['used'] / (1024 ** 3)
|
||||
if CONF.libvirt_images_type == 'lvm':
|
||||
vg_used = libvirt_utils.volume_group_used_space(
|
||||
CONF.libvirt_images_volume_group)
|
||||
return vg_used / (1024 ** 3)
|
||||
else:
|
||||
stats = libvirt_utils.get_fs_info(CONF.instances_path)
|
||||
return stats['used'] / (1024 ** 3)
|
||||
|
||||
def get_hypervisor_type(self):
|
||||
"""Get hypervisor type.
|
||||
|
||||
@@ -144,6 +144,36 @@ def volume_group_free_space(vg):
|
||||
return int(out.strip())
|
||||
|
||||
|
||||
def volume_group_total_space(vg):
|
||||
"""Return total space on volume group in bytes.
|
||||
|
||||
:param vg: volume group name
|
||||
"""
|
||||
|
||||
out, err = execute('vgs', '--noheadings', '--nosuffix',
|
||||
'--units', 'b', '-o', 'vg_size', vg,
|
||||
run_as_root=True)
|
||||
return int(out.strip())
|
||||
|
||||
|
||||
def volume_group_used_space(vg):
|
||||
"""Return available space on volume group in bytes.
|
||||
|
||||
:param vg: volume group name
|
||||
"""
|
||||
|
||||
out, err = execute('vgs', '--noheadings', '--nosuffix',
|
||||
'--separator', '|',
|
||||
'--units', 'b', '-o', 'vg_size,vg_free', vg,
|
||||
run_as_root=True)
|
||||
|
||||
info = out.split('|')
|
||||
if len(info) != 2:
|
||||
raise RuntimeError(_("vg %s must be LVM volume group") % vg)
|
||||
|
||||
return int(info[0]) - int(info[1])
|
||||
|
||||
|
||||
def list_logical_volumes(vg):
|
||||
"""List logical volumes paths for given volume group.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user