diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-01-11 23:35:10 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-01-11 23:35:10 +0000 |
| commit | 02ea0f9f9e5c7f022b465a96ba3a4f089c633bee (patch) | |
| tree | 01f50722fd79e297b4e0f05dfa8f6341b472c700 /nova | |
| parent | cd2008c8f7476ba28e826ad40d4db8e94045723c (diff) | |
| parent | 9d3f524c6926edfbff5f62308c8d582edcc7067f (diff) | |
Merge "Correct the calculating of disk size when using lvm disk backend."
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/virt/libvirt/driver.py | 18 | ||||
| -rw-r--r-- | nova/virt/libvirt/utils.py | 30 |
2 files changed, 44 insertions, 4 deletions
diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 1e087e61a..caf76908c 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -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. diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 73c3b552b..9c8d192c7 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -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. |
